UART0 RX interrupt stuck in while loop doesn't allow lwm2m function to run?

Hello,

We want to read external sensor data using uart in lwm2m_client project.

I tried below following code :

static char RX_Data;
static char uart_buf[20];
static char *command1 = "This Is A Test of UART0\r\n";
void uart_cb(struct device *x)
{
uart_irq_update(x);
int data_length = 0;

if (uart_irq_rx_ready(x)) {
data_length = uart_fifo_read(x, uart_buf, sizeof(uart_buf));
uart_buf[data_length] = 0;
printk("%s\r\n", uart_buf);
RX_Data= uart_buf[0];
printk("Recived Data %c\r\n", RX_Data);
}


}

==================================================

struct device *uart = device_get_binding("UART_0");
uart_irq_callback_set(uart, uart_cb);
uart_irq_rx_enable(uart);
printk(" UART0 start!\n");

while (true)
{ //uart_send_str(uart1, command1);
lwm2m_rd_client_start(&client, endpoint_name, flags, rd_client_event);

k_sem_take(&lwm2m_restart, K_FOREVER);

LOG_INF("LwM2M restart requested. The sample will try to"
" re-establish network connection.");

/* Stop the LwM2M engine. */
lwm2m_rd_client_stop(&client, rd_client_event);

/* Try to reconnect to the network. */
ret = lte_lc_offline();
if (ret < 0) {
LOG_ERR("Failed to put LTE link in offline state (%d)", ret);
}

modem_connect();

}

==========================================

In terminal it's waiting for next RX value. which doesn't allow to run other function. how we can run both together?

How we can switch UART0 to UART1? i tried to modified above code but it doesn't work.

Best Regards

Deepak  

Parents
  • Hello!

    In terminal it's waiting for next RX value. which doesn't allow to run other function.

    I think it's a bad idea to place your uart read code in an ISR, for exactly the reason you mention that other functions get starved while the high priority ISR is waiting for the uart device.

    Instead I would make a lower priority thread that takes care of your uart reading, that you can signal to with a semaphore from your ISR.

    How we can switch UART0 to UART1? 

    When you call device_get_binding("UART_0"), you are using Zephyr's Devicetree API to access your device.

    You can find the devicetree file in your application folder as build/zephyr/zephyr.dts

    If you look up the uart nodes in this file you'll find that uart_1 is disabled by default in the lwm2m_client project (status = "disabled").

    One way to change this is by adding a devicetree overlay file to your project. Please refer to Zephyr's introduction to devicetree to learn how to do this.

    Best regards,

    Einar

  • I didn't understand shared documents. but i found uart1 can't use for _ns board project :

    so i am trying to configure uart2:

    In prj.conf
    CONFIG_UART_2_NRF_UARTE=y
    but it shows this :: CONFIG_UART_2_NRF_UARTE cannot be set (has no prompt) and getting error in compilation.

    Compiled Deice tree output showing this:

    art2: uart@a000 {

                                    compatible = "nordic,nrf-uarte";
                                    reg = <0xa000 0x1000>;
                                    interrupts = <10 NRF_DEFAULT_IRQ_PRIORITY>;
                                    status = "disabled";
                                    label = "UART_2";
                                    tx-pin = <24>;
                                    rx-pin = <23>;
    ==========================================================================
    can we enable in device tree: manually?
    uart2: uart@a000 {
        compatible = "nordic,nrf-uarte";
        reg = <0xa000 0x1000>;
        interrupts = <10 NRF_DEFAULT_IRQ_PRIORITY>;
        status = "disabled";
        label = "UART_2";
    };
    and
     &uart2 {
        status = "okay";
        current-speed = <115200>;
        tx-pin = <24>;
        rx-pin = <23>;
        rx-pull-up;
       
    };
    Best Regards
    Deepak
  • build tree::
    uart0: uart@8000 {
        compatible = "nordic,nrf-uarte";
        reg = <0x8000 0x1000>;
        interrupts = <8 NRF_DEFAULT_IRQ_PRIORITY>;
        status = "disabled";
        label = "UART_0";
    };

    uart1: uart@9000 {
        compatible = "nordic,nrf-uarte";
        reg = <0x9000 0x1000>;
        interrupts = <9 NRF_DEFAULT_IRQ_PRIORITY>;
        status = "disabled";
        label = "UART_1";
    };

    uart2: uart@a000 {
        compatible = "nordic,nrf-uarte";
        reg = <0xa000 0x1000>;
        interrupts = <10 NRF_DEFAULT_IRQ_PRIORITY>;
        status = "disabled";
        label = "UART_2";
    };
  • So from your error log it's clear you're not using CONFIG_UART_2_NRF_UARTE correctly.

    Have you looked up what this option does before including it in your project?

    You can see a list of all config options here.

    You can also use the nRF Kconfig browser in NCS for VS Code to browse available config options and their dependencies.

    Just from a quick look at the full list, I believe CONFIG_HAS_HW_NRF_UARTE2 or CONFIG_NRFX_UARTE2 could be more relevant.

    -Einar

  • if we use this CONFIG_NRFX_UARTE2...  cmake and build compilation not generating error. but still UART2 not working...  

  • ok

    As I asked earlier, do you see the "Found devicetree overlay" message when building?

    And if you do, could you put this in your code:

    #define UART2_NODE DT_NODELABEL(uart2)

    and then tell me what this function returns:

    DT_NODE_HAS_STATUS(UART2_NODE, okay)

    -Einar

  • Q1- As I asked earlier, do you see the "Found devicetree overlay" message when building?

    Ans- NO

    Q2- tell me what this function returns:

    DT_NODE_HAS_STATUS(UART2_NODE, okay)

    Ans-  Zero

Reply Children
Related