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 

  • Hi Jared,

               Thanks for your reply. I followe dyour instructions and did the changes as follows:-

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

    In sdk_config.h
    ADDED LIBUARTE CONFIG
    
    
    
    // <q> NRF_LIBUARTE_ASYNC_WITH_APP_TIMER - nrf_libuarte_async - libUARTE_async library
    
    #ifndef NRF_LIBUARTE_ASYNC_WITH_APP_TIMER
    #define NRF_LIBUARTE_ASYNC_WITH_APP_TIMER 1
    #endif
    
    //==========================================================
    
    // <h> nrf_libuarte_drv - libUARTE library
    
    //==========================================================
    // <q> NRF_LIBUARTE_DRV_HWFC_ENABLED - Enable HWFC support in the driver
    
    #ifndef NRF_LIBUARTE_DRV_HWFC_ENABLED
    #define NRF_LIBUARTE_DRV_HWFC_ENABLED 0
    #endif
    
    // <q> NRF_LIBUARTE_DRV_UARTE0 - UARTE0 instance
    
    #ifndef NRF_LIBUARTE_DRV_UARTE0
    #define NRF_LIBUARTE_DRV_UARTE0 0
    #endif
    
    // <q> NRF_LIBUARTE_DRV_UARTE1 - UARTE1 instance
    
    #ifndef NRF_LIBUARTE_DRV_UARTE1
    #define NRF_LIBUARTE_DRV_UARTE1 1
    #endif
    
    // <e> NRF_CLI_LIBUARTE_CONFIG_LOG_ENABLED - Enables logging in the module.
    //==========================================================
    #ifndef NRF_CLI_LIBUARTE_CONFIG_LOG_ENABLED
    #define NRF_CLI_LIBUARTE_CONFIG_LOG_ENABLED 1
    #endif
    // <o> NRF_CLI_LIBUARTE_CONFIG_LOG_LEVEL - Default Severity level
    
    
    #ifndef NRF_CLI_LIBUARTE_CONFIG_LOG_LEVEL
    #define NRF_CLI_LIBUARTE_CONFIG_LOG_LEVEL 3
    #endif
    
    // <o> NRF_CLI_LIBUARTE_CONFIG_INFO_COLOR - ANSI escape code prefix.
    
    
    #ifndef NRF_CLI_LIBUARTE_CONFIG_INFO_COLOR
    #define NRF_CLI_LIBUARTE_CONFIG_INFO_COLOR 0
    #endif
    
    // <o> NRF_CLI_LIBUARTE_CONFIG_DEBUG_COLOR - ANSI escape code prefix.
    
    
    #ifndef NRF_CLI_LIBUARTE_CONFIG_DEBUG_COLOR
    #define NRF_CLI_LIBUARTE_CONFIG_DEBUG_COLOR 0
    #endif
    
    ============================================================================
    
    In uart.c added code for uarte
    
    NRF_LIBUARTE_ASYNC_DEFINE(libuarte, 1, 0, 0, NRF_LIBUARTE_PERIPHERAL_NOT_USED, 255, 3);
    
    typedef struct {
    uint8_t * p_data;
    uint32_t length;
    } buffer_t;
    
    NRF_QUEUE_DEF(buffer_t, m_buf_queue, 10, NRF_QUEUE_MODE_NO_OVERFLOW);
    
    static volatile bool m_loopback_phase;
    void sys_uart2_init(void);
    
    
    
    
    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;
    }
    }
    
    
    
    
    
    void sys_uart2_init(void)
    {
    ret_code_t err_code;
    
    nrf_libuarte_async_config_t nrf_libuarte_async_config = {
    .tx_pin = UART2_TX_PIN_NUMBER,
    .rx_pin = UART2_RX_PIN_NUMBER,
    .baudrate = NRF_UARTE_BAUDRATE_9600,
    .parity = NRF_UARTE_PARITY_EXCLUDED,
    .hwfc = NRF_UARTE_HWFC_DISABLED,
    .timeout_us = 100,
    .int_prio = APP_IRQ_PRIORITY_LOW
    };
    
    err_code = nrf_libuarte_async_init(&libuarte, &nrf_libuarte_async_config, libuarte_event_handle, (void *)&libuarte);
    
    APP_ERROR_CHECK(err_code);
    
    nrf_libuarte_async_enable(&libuarte);
    
    //err_code = nrf_libuarte_async_tx(&libuarte, text, text_size);
    //APP_ERROR_CHECK(err_code);
    }

    after adding the code i tried to compile and I am getting error: -

    How to solve this error? 

  • Seems like you already use UARTE1 in your project? Have you already initialized UARTE1 somewhere else in your code?

  • I disabled this in sdk_config.h. Had enabled it according to our previous discussion. Now again i have disabled it. I have attached my sdk_config file. 3566.sdk_config.h

    #ifndef UART1_ENABLED
    #define UART1_ENABLED 0
    #endif
    // <q> UART1_CONFIG_USE_EASY_DMA - Default setting for using EasyDMA

    #ifndef UART1_CONFIG_USE_EASY_DMA
    #define UART1_CONFIG_USE_EASY_DMA 0
    #endif

    #ifndef APP_UART_DRIVER_INSTANCE
    #define APP_UART_DRIVER_INSTANCE 1
    #endif

  • Hi,

    The SDK config should look somewhat similar to this. 

    5415.sdk_config.h

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

    Please help. 

Reply Children
Related