This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

GPIOTE pin change IRQ handler fired when UART data RX occurs

Hello, in my project i simultaneously use MPR121 touch sensor controller and GPS module connected to UART0 of nRF52840 (custom board). To handle touch events, i use MPR121 IRQ line which is hooked up to GPIOTE pin IRQ:

void touch_IRQ_init(void)
{
 ret_code_t err_code;

 err_code = nrf_drv_gpiote_init();
 APP_ERROR_CHECK(err_code);

 nrf_drv_gpiote_in_config_t in_config = GPIOTE_CONFIG_IN_SENSE_HITOLO(true);

 in_config.pull = NRF_GPIO_PIN_NOPULL;

 err_code = nrf_drv_gpiote_in_init(TOUCH_IRQ_PIN, &in_config, MPR121_check_pad_status);
 APP_ERROR_CHECK(err_code);

 nrf_drv_gpiote_in_event_enable(TOUCH_IRQ_PIN, true);

 SEGGER_RTT_printf(0, "Touch IRQ init complete.\n");
}

Then, UART0 along with UART IRQ handler is initialized (code is borrowed from Nordic UART example):

void UART_config( uint8_t rts_pin_number,
uint8_t txd_pin_number,
uint8_t cts_pin_number,
uint8_t rxd_pin_number,
uint32_t speed,
bool hwfc)
{
nrf_gpio_cfg_output(txd_pin_number);
nrf_gpio_cfg_input(rxd_pin_number, NRF_GPIO_PIN_PULLUP);

NRF_UART0->PSELTXD = txd_pin_number;
NRF_UART0->PSELRXD = rxd_pin_number;

if (hwfc)
{
nrf_gpio_cfg_output(rts_pin_number);
nrf_gpio_cfg_input(cts_pin_number, NRF_GPIO_PIN_NOPULL);
NRF_UART0->PSELCTS = cts_pin_number;
NRF_UART0->PSELRTS = rts_pin_number;
NRF_UART0->CONFIG = (UART_CONFIG_HWFC_Enabled << UART_CONFIG_HWFC_Pos);
}

NRF_UART0->BAUDRATE = (speed << UART_BAUDRATE_BAUDRATE_Pos);
NRF_UART0->CONFIG = (UART_CONFIG_PARITY_Excluded << UART_CONFIG_PARITY_Pos);
NRF_UART0->ENABLE = (UART_ENABLE_ENABLE_Enabled << UART_ENABLE_ENABLE_Pos);
NRF_UART0->TASKS_STARTTX = 1;
NRF_UART0->TASKS_STARTRX = 1;
NRF_UART0->EVENTS_RXDRDY = 0;

m_current_state = UART_READY;

NRF_UART0->INTENCLR = 0xffffffffUL;
NRF_UART0->INTENSET = (UART_INTENSET_RXDRDY_Set << UART_INTENSET_RXDRDY_Pos) |
(UART_INTENSET_TXDRDY_Set << UART_INTENSET_TXDRDY_Pos) |
(UART_INTENSET_ERROR_Set << UART_INTENSET_ERROR_Pos);

NVIC_ClearPendingIRQ(UART0_IRQn);
NVIC_SetPriority(UART0_IRQn, 1);
NVIC_EnableIRQ(UART0_IRQn);

}

Touch IRQ handler works well (reacts on pin changes where MPR121 IRQ pin is connected, correct IRQ handler is fired up), until i enable GPS module, which starts to send NMEA strings to UART. Then, only handler that is fired up on incoming UART data, is MPR121_check_pad_status() which was set explicity to fire only on specific pin change, not UART events. UART0_IRQHandler(), which is also defined, is never fired at all.

Same UART code alone seems to work ok in a separate program dedicated to testing GPS interaction. Touch events code alone also works well, when UART code is not compiled in. 

Parents
  • I have found one error in my code: RX and TX pins for UART were swapped in my main program. After correcting that, i see that UART handler is triggered as expected. I still have a problem with touch IRQ handler being triggered along with UART handler though. If there are no known bugs that can cause similar behavior, then i suspect that maybe there is some error on my custom board - maybe some short or crosstalk between these two pins - i will check this and i'll get back with the results.

  • Hello Wojtek,

    woytekm said:
    i'm not using internal pull up, as there is external pull up resistor present on this line.

    Thank you for clarifying, and for the detailed descriptions and code - this is very helpful!

    woytekm said:
    I have found one error in my code: RX and TX pins for UART were swapped in my main program. After correcting that, i see that UART handler is triggered as expected. I still have a problem with touch IRQ handler being triggered along with UART handler though.

    I am happy to hear that you were able to identify and resolve this particular issue! It still seems very strange to me that you are getting the UART RX event when the GPIOTE pin is triggered. 

    woytekm said:
    If there are no known bugs that can cause similar behavior, then i suspect that maybe there is some error on my custom board - maybe some short or crosstalk between these two pins - i will check this and i'll get back with the results.

    There is no known issue of this, no. I have never heard of any similar behavior either. Could you possibly try to change the pin you are using for your GPIOTE event, to see if the same happens then? if the same does not happen with another pin it is very likely that it is a hardware issue.

    Best regards,
    Karl

Reply
  • Hello Wojtek,

    woytekm said:
    i'm not using internal pull up, as there is external pull up resistor present on this line.

    Thank you for clarifying, and for the detailed descriptions and code - this is very helpful!

    woytekm said:
    I have found one error in my code: RX and TX pins for UART were swapped in my main program. After correcting that, i see that UART handler is triggered as expected. I still have a problem with touch IRQ handler being triggered along with UART handler though.

    I am happy to hear that you were able to identify and resolve this particular issue! It still seems very strange to me that you are getting the UART RX event when the GPIOTE pin is triggered. 

    woytekm said:
    If there are no known bugs that can cause similar behavior, then i suspect that maybe there is some error on my custom board - maybe some short or crosstalk between these two pins - i will check this and i'll get back with the results.

    There is no known issue of this, no. I have never heard of any similar behavior either. Could you possibly try to change the pin you are using for your GPIOTE event, to see if the same happens then? if the same does not happen with another pin it is very likely that it is a hardware issue.

    Best regards,
    Karl

Children
No Data
Related