If I have set up a pin as a peripheral pin (timer, uart, whatever) can I still setup GPIO edge-triggered interrupt on that pin? Thanks.
It is definitely possible to configure an alternate function for a GPIO pin (like USART TXD) and also generate pin change interrupts from the same pin.
We are doing this on the P1.27 TXD pin on an LPC11E14 device. We output USART serial data on the TXD pin but also generate interrupts on each edge of the TXD signal. In our application we don't even use the TXD signal directly at all.
Yes, you must have power enabled to the GPIO system and configure the alternate function for the pin as usual.
Here's our initialization for the pin change interrupts:
void init_txd_edge_int(void)
{
NVIC_DisableIRQ( FLEX_INT0_IRQn );
<span style="font-size: 10px;"> // Select P1.27 for pin interrupt selection 0</span>
LPC_SYSCON->PINTSEL[0] = INTPIN_P1_27;
<span style="font-size: 10px;"> // Enable interrupts for both edges of P1.27</span>
LPC_GPIO_PIN_INT->ISEL = 0; // Sets pin interrupt mode to edge sensitive
LPC_GPIO_PIN_INT->IENR = 1; // Enable rising edge interrupt
LPC_GPIO_PIN_INT->SIENR = 1; // Write to enable rising edge interrupt
LPC_GPIO_PIN_INT->IENF = 1; // Enable falling edge interrupt
LPC_GPIO_PIN_INT->SIENF = 1; // Write to enable falling edge interrupt
<span style="font-size: 10px;"> // Set P1.27 pin-change interrupt priority to 0 (highest) </span>
// This is configured in decoder.h
NVIC_SetPriority( FLEX_INT0_IRQn, TXD_PIN_CHANGE_NVIC_INT_PRIORITY );
<span style="font-size: 10px;"> // Enable the pin change interrupt</span>
NVIC_EnableIRQ( FLEX_INT0_IRQn );
}
I'm not so sure this is true, looking at the user manual. You can read the DATA register and it will return the current logic state of the pins whether they are set to GPIO input, output, or some other function. I don't see anything specifically about the interrupt in cases where the pin is set to some other function, but it would make sense that it triggers off the DATA register and operates the same way. An easy way to check would be to set up and enable the GPIO interrupt on a UART pin and see if it calls the interrupt handler. The GPIO domain would obviously have to be powered up.
When you assigned a pin to a specific fucntion other than GPIO, then the GPIO capabilities is considered disabled. That's to say writing to the GPIO registers would have no affect on the pin after the function assignment. Since the edge detection is part of the GPIO domain, this would also be disabled.
You can do a simple experiment to convince yourself on this:
Set up the UART on the TX/RX pin. Now power down the GPIO domain. With the GPIO domain powered down, the UART will still work.