Multiple UART on NRF52833

Hello Everyone,

                   I am using NRF52833 in my project and I have my NRF module connected to 2 other microcontrollers on UART peripherals. The details are mentioned as below:-

1) NRF52833 connected to MCU A

   RX pin of nrf- P0.29

   TX pin of nrf- P0.28

2) NRF52833 connected to MCU B

   RX pin of nrf- P0.30

   TX pin of nrf- P0.31.

I have successfully configured connection to MCU and I am able to transmit data from NRF to MCU A and receive data on NRF from MCU A.

Now I have to add another UART in the code so as to communicate with MCU B. What will be the steps to add one more UART configuration?? What is the procedure to do so.

Thanks & Regards,

Snehal.

Parents
  • Hi,

    The nRF52833 has only 1 UART, but 2 UARTE. So you would have to add a UARTE peripheral to your project. To add the peripheral you need to:

    1. Enable the Instance in your sdk config file and add necessary files to your project. 
    2. Initialize the peripheral and instance
    3. Use the peripheral Slight smile

    You can follow the procedure as in the UART example. If you're already using the UART example, then you're actually using the UARTE peripheral. If so, then you need to make sure that you add instance 1 instead of 0, because the example already use instance 0. 

    regards

    Jared 

  • Hi Jared,

                 Thanks for your reply. You mean to say I will have to edit in sdk_config.h from 

    #ifndef APP_UART_DRIVER_INSTANCE
    #define APP_UART_DRIVER_INSTANCE 0
    #endif

    to 

    #ifndef APP_UART_DRIVER_INSTANCE
    #define APP_UART_DRIVER_INSTANCE 1
    #endif

    ??

    Will this enable 2 uarts? As well as for uart1 i am using function below:-

    void sys_uart_init(void)
    {
    uint32_t err_code;
    const app_uart_comm_params_t comm_params =
    {
    UART_RX_PIN_NUMBER,
    UART_TX_PIN_NUMBER,
    UART_RTS_PIN_NUMBER,
    UART_CTS_PIN_NUMBER,
    APP_UART_FLOW_CONTROL_DISABLED,
    false,
    UART_BAUDRATE_BAUDRATE_Baud9600
    };

    APP_UART_FIFO_INIT(&comm_params,
    UART_RX_BUF_SIZE,
    UART_TX_BUF_SIZE,
    uart_event_handle,
    APP_IRQ_PRIORITY_LOWEST,
    err_code);


    APP_ERROR_CHECK(err_code);
    }

    will i have to creae another function for adding 2nd uart using the same method???

    Thanks & Regards,

    Snehal 

  • I tried to edit the sdk_config according to the file you have provided. Now I am getting new errors. 

    Please help. 

  • I solved the issue. I had to put some defines like APP_TIMER_V2 & APP_TIMER_V2_RTC1_ENABLED in the preprocessor definitions. 

    I am also using "app_timer_freertos.c" in my project as I have to run some timers through schedulers. So the problem is I am getting multiple definition error after including the app_timer2.c.

    Any way to solve this issue?

    I actually removed 2 files app_timer2.c and drv_rtc.c and the errors are gone now. But still libuarte gives error while running the code on the device.

    Thank you.

  • Hi,

    Are you actually  using freeRTOS? 

    sne_333 said:
    my project as I have to run some timers through schedulers.

    Please elaborate on this.

    regards

    Jared

  • I am using RTOS in my project. So i have defined some timers which are created in different tasks in RTOS.

  • Hi,

    If you're using RTOS then only app_timer_freertos.c should be included. 

    sne_333 said:
    I actually removed 2 files app_timer2.c and drv_rtc.c and the errors are gone now. But still libuarte gives error while running the code on the device.

    What kind of error?

    I think you should first try to simplify this process into two steps:

    1. Merge the libuarte example with the UART peripheral hardware example and verify that it works. 
    2. Add FreeRTOS to your project.

    Trying to do both at the same time will unnecessarily complicate things.

    regards

    Jared 

Reply
  • Hi,

    If you're using RTOS then only app_timer_freertos.c should be included. 

    sne_333 said:
    I actually removed 2 files app_timer2.c and drv_rtc.c and the errors are gone now. But still libuarte gives error while running the code on the device.

    What kind of error?

    I think you should first try to simplify this process into two steps:

    1. Merge the libuarte example with the UART peripheral hardware example and verify that it works. 
    2. Add FreeRTOS to your project.

    Trying to do both at the same time will unnecessarily complicate things.

    regards

    Jared 

Children
  • Hi Jared,

                  I have solved all the errors of libuarte and the code is running properly without any errors. But when I try to transmit hex data from libuarte, i am not able to transmit or receive any data. I am trying to transmit hex data (0x73,0x01,0x0a,0x0d) 

    What might be the issue?I am not seeing any errors but the other mcu is not receiving any data.

    Regards,
    Snehal

  • Hi,

    Do you see any activity on the TX line when you try to send data? Can you use a logical analyzer or a scope and verify?

    regards

    Jared

  • Hi Jared,

      Unfortunately I am not having scope or analyzer to check the lines. 

    Regards,

    Snehal.

  • Can you use the debugger and see what the transmits functions returns and how the TX buffer that is passed to the function look like? 

  • yes I can check that. Meanwhile If I want to check the received data from other MCU on nrf52833,how can I check if hex data is being received. The libuarte handler is as follow:-

    void libuarte_event_handle(void * context, nrf_libuarte_async_evt_t * p_evt)
    {
        nrf_libuarte_async_t * p_libuarte = (nrf_libuarte_async_t *)context;
        ret_code_t ret;
    
        switch (p_evt->type)
        {
            case NRF_LIBUARTE_ASYNC_EVT_ERROR:
                //bsp_board_led_invert(0);
                break;
            case NRF_LIBUARTE_ASYNC_EVT_RX_DATA:
                ret = nrf_libuarte_async_tx(p_libuarte,p_evt->data.rxtx.p_data, p_evt->data.rxtx.length);
                if (ret == NRF_ERROR_BUSY)
                {
                    buffer_t buf = {
                        .p_data = p_evt->data.rxtx.p_data,
                        .length = p_evt->data.rxtx.length,
                    };
    
                    ret = nrf_queue_push(&m_buf_queue, &buf);
                    APP_ERROR_CHECK(ret);
                }
                else
                {
                    APP_ERROR_CHECK(ret);
                }
                //bsp_board_led_invert(1);
                m_loopback_phase = true;
                break;
            case NRF_LIBUARTE_ASYNC_EVT_TX_DONE:
                if (m_loopback_phase)
                {
                    nrf_libuarte_async_rx_free(p_libuarte, p_evt->data.rxtx.p_data, p_evt->data.rxtx.length);
                    if (!nrf_queue_is_empty(&m_buf_queue))
                    {
                        buffer_t buf;
                        ret = nrf_queue_pop(&m_buf_queue, &buf);
                        APP_ERROR_CHECK(ret);
                        UNUSED_RETURN_VALUE(nrf_libuarte_async_tx(p_libuarte, buf.p_data, buf.length));
                    }
                }
               // bsp_board_led_invert(2);
                break;
            default:
                break;
        }
    }
    

    Like if I want to print the received data on the RTT terminal, how can I do that?

    Regards,

    Snehal.

Related