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,

    You can use the logger module with the RTT enabled as backend (see the ble_app_uart for reference). But the best approach would be to use the debugger and set a breakpoint in the event handler and see if the RX buffer is filled.

    regards

    Jared 

  • Hi,

         So this particular line ".p_data = p_evt->data.rxtx.p_data," has the received data right? 

    I also tried to debug the firmware. I am receiving the data from the other controller but after receiving the data I am getting this error in the logs:-

    <error> app: LIBUARTE ERROR
    <error> app: LIBUARTE ERROR
    <error> hardfault: HARD FAULT at 0x000287A8
    <error> hardfault: R0: 0x00000000 R1: 0x20006880 R2: 0x0A0D6466 R3: 0x20006878
    <error> hardfault: R12: 0x200067A4 LR: 0x00029C2D PSR: 0x61000038
    <error> hardfault: Cause: Data bus error (return address in the stack frame is not related to the instruction that caused the error).

    What could have caused this issue?

    Regards,

    Snehal

  • Hi,

    Can you start the program with the debugger and see what instruction is at 0x000287A8 in the Dissembler view? 

  • I have solved that issue. Can you help me with one thing. I am receiving lot of data from the other MCU via libuarte. I want to print that data on the RTT terminal... How can I do that using NRF_LOG_INFO?? 

    My libuarte handler is as follows:-

    void libuart_event_handler(void *context, nrf_libuarte_async_evt_t *p_evt) {
    static uint8_t index;

    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: {
    NRF_LOG_ERROR("LIBUARTE ERROR");
    break;
    }
    case NRF_LIBUARTE_ASYNC_EVT_RX_DATA: {
    // Receive complete
    memset(buffer,'0',sizeof(buffer));
    memcpy(buffer, p_evt->data.rxtx.p_data, p_evt->data.rxtx.length);
    int data_length = p_evt->data.rxtx.length;

    nrf_libuarte_async_rx_free(p_libuarte, p_evt->data.rxtx.p_data, p_evt->data.rxtx.length);
    break;
    }
    case NRF_LIBUARTE_ASYNC_EVT_TX_DONE: {
    // Transmit complete

    break;
    }
    }
    }

    How can I print the buffer values on RTT?? Size of buffer is 256.

    Regards,

    Snehal

  • Hi ,

    You need to set the logger backend in the sdk_config.h file from UART to RTT.

    regards

    Jared

Reply Children
No Data
Related