UART interrupt IRQ rx not working

I was using sdk 1.9.1 into my project and every things waking prefect which use openthread. I took the same project and build it in latest version ( sdk v2.1.1 ). when I flash it the uart did not work. after some investigation I found that the IRQ callback did not work in this version. I search if someone have same my problem and found this  https://devzone.nordicsemi.com/f/nordic-q-a/92008/uart_1-callback-not-being-set/390257 , but the answer did not fix the problem. 

what confused me is that the same code work in v1.9.1 sdk but not the latest one. is there something missing or must include in  v2.1.1 sdk to enable irq? 

prj.conf of uart:

#UART
CONFIG_SERIAL=y
CONFIG_UART_INTERRUPT_DRIVEN=y
CONFIG_UART_1_INTERRUPT_DRIVEN=y
main initialization of uart and irq of rx:
...

const struct device *uart_dev;

...

static void UART_RxCallback(const struct device *x, void *user_data) {

	int res;
	uart_irq_update(x);

	if (uart_irq_rx_ready(x)) 
	{
		res = uart_poll_in(x, &rx_buffer.new);
		if (res != 0) {
			return;
		}
	}
}

...

void main(){
...
uart_dev = device_get_binding("UART_1"); 
if (!device_is_ready(uart_dev)) {
    printf("UART device not found!");
    return;
    }
uart_irq_callback_set(uart_dev,UART_RxCallback);
uart_irq_rx_enable(uart_dev);
...
}
any one can help me please?
Parents Reply Children
  • Hi,

    Thank you for your answer.

    everything works with logic analyzer. the TX data show and RX data also. but the RX callback did not work.

    after some investigation when I enter infinity loop (pressing button until I release it) the callback function works fine and able to save into buffer.

    why this happen in 2.x.x versions ? is the irq change in this sdk? 

    I add these config but did not work for me.

    Best regards,
    Kalbani,

  • Hi,

    The interrupt priorioties can be controlled in the .dts file, if not set explicit, then I believe they are default in the .dtsi file for the chip in question.

    Typically something like:
            uart0: uart@40002000 {

                /* uart can be either UART or UARTE, for the user to pick */
                /* compatible = "nordic,nrf-uarte" or "nordic,nrf-uart"; */
                compatible = "nordic,nrf-uarte";
                reg = <0x40002000 0x1000>;
                interrupts = <2 NRF_DEFAULT_IRQ_PRIORITY>;
                status = "disabled";
            };

    Based on this you should be able to do something like this in the .dts file:

    arduino_serial: &uart0 {
        status = "okay";
        compatible = "nordic,nrf-uarte";
        current-speed = <115200>;
        pinctrl-0 = <&uart0_default>;
        pinctrl-1 = <&uart0_sleep>;
        pinctrl-names = "default", "sleep";
        interrupts = <2 PRIORITY>;
    };

    For test (to see if it's related to interrupt priority) you can try to set PRIORITY to 0 (though not recommended for final application).
     
    Kenneth

Related