This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

nRF52840 UART queries

Hello,

 

I am using nRF52840, SDK_16.0.0, S140 SoftDevice and Segger 4.16 for flashing the image. I am using ‘ble_app_blinky’.

 

1) In Product specification, it says 2 UARTE supported. Whereas in section 6.33.10 I am seeing only one instance of UART0, but in section 6.34.9 there are two instance of UARTE0 and UARTE1.

a) Without EasyDMA, is it only one UART supported ?

 

2) I need uart in my ble_app_blinky application. I have gone through ble_app_uart. For this I enabled NRF_LOG_BACKEND_RTT_ENABLED and disabled NRF_LOG_BACKEND_UART_ENABLED. Is this fine ?

 

3) For UART rx, ble_app_uart has uart_event_handle() to receive data. For UART Tx whether can I use app_uart_put() ?

     a) To cross check I want to type on Terminal. Once received on uart, I want to transmit the same data back to terminal. But when I call app_uart_put(), I am not seeing any print on Terminal.

     b) Even I am getting event APP_UART_TX_EMPTY (3) in default case, indicating "UART has completed transmission of all available data in the TX FIFO". But not output on Terminal. (I configured Terminal properly).

      

/**@snippet [Handling the data received over UART] */
void uart_event_handle(app_uart_evt_t * p_event)
{
    static uint8_t data_array[UART_MAX_DATA_LEN];
    static uint8_t index = 0;
    uint32_t       err_code;

    switch (p_event->evt_type)
    {
        case APP_UART_DATA_READY:
        {
            UNUSED_VARIABLE(app_uart_get(&data_array[index]));
            index++;
            
            NRF_LOG_DEBUG("D ");
            //NRF_LOG_HEXDUMP_DEBUG(data_array, index);
            
            app_uart_put(data_array[index]);
            
            if ((data_array[index - 1] == '\n') ||
                (data_array[index - 1] == '\r') ||
                (index >= m_ble_nus_max_data_len))
            {

                index = 0;
            }
        }
        break;

        case APP_UART_COMMUNICATION_ERROR:
            APP_ERROR_HANDLER(p_event->data.error_communication);
            break;

        case APP_UART_FIFO_ERROR:
            APP_ERROR_HANDLER(p_event->data.error_code);
            break;

        default:
            NRF_LOG_DEBUG("DF %d", p_event->evt_type);
            break;
    }
}
/**@snippet [Handling the data received over UART] */


/**@brief  Function for initializing the UART module.
 */
/**@snippet [UART Initialization] */
void uart_init(void)
{
    uint32_t                     err_code;
    app_uart_comm_params_t const comm_params =
    {
        #if CT40_ACTUAL_BOARD
        .rx_pin_no    = RX_PIN_NUMBER_CT40,
        .tx_pin_no    = TX_PIN_NUMBER_CT40,
        #else
        .rx_pin_no    = RX_PIN_NUMBER,
        .tx_pin_no    = TX_PIN_NUMBER,
        #endif

        .rts_pin_no   = RTS_PIN_NUMBER,
        .cts_pin_no   = CTS_PIN_NUMBER,
        .flow_control = APP_UART_FLOW_CONTROL_DISABLED,
        .use_parity   = false,
#if defined (UART_PRESENT)
        .baud_rate    = NRF_UART_BAUDRATE_115200
#else
        .baud_rate    = NRF_UARTE_BAUDRATE_115200
#endif
    };

    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);
}
/**@snippet [UART Initialization] */

4) I am bit confused, whether can I use app_uart.c / app_uart_fifo.c or “Serial Port Library”. My requirements are:

a) I need both UART Tx & Rx

b) BLE should work simultaneously.

c) Device should go into low power mode.

 

 Thanks & Regards

Vishnu Beema

Parents
  • Hi, 
    I will try to answer your questions.

    1) Yes, you understand correctly. UART0 and UARTE0 share the same memory space and HW and can be used with or without EasyDMA. UARTE1 can only be used with EasyDMA.

    2) I don't understand, you say you need UART, but you have enabled RTT? Do you mean that you need our logger, and want to use RTT as the log backend, or do you need the UART to be available as part of the application, while RTT is only for logging? In both cases, it should be OK.

    3) app_uart_put() is to be the correct way to transmit data in this context.
    If you have a look in the nus_data_handler(ble_nus_evt_t * p_evt) you can see how app_uart_put() is used.
    It seems that you are not waiting the tx to finish, other example typically use app_uart_put() inside a while loop. You can se how this is done in e.g. the peripheral example of uart on (line 173).
    while (app_uart_put(cr) != NRF_SUCCESS);

    4) I understand the confusion, and share this confusion with you. However, the serial port library is only a wrapper around the same functionality as using the uart more directly as is done in the app_uart example. I don't think it matters which method you choose to use, however I find the syntax in the serial port libary to be a bit easier.

    a) All the mentioned examples, etc. are able to handle both rx and tx
    b) Many of our BLE examples use UART and BLE simultaneously, the app_ble_uart does this as well. 
    c) I will recommend to disable the UART peripheral whenever possible, and e.g. use a BLE message or a pin input to trigger that the device should start listening on rx.

Reply
  • Hi, 
    I will try to answer your questions.

    1) Yes, you understand correctly. UART0 and UARTE0 share the same memory space and HW and can be used with or without EasyDMA. UARTE1 can only be used with EasyDMA.

    2) I don't understand, you say you need UART, but you have enabled RTT? Do you mean that you need our logger, and want to use RTT as the log backend, or do you need the UART to be available as part of the application, while RTT is only for logging? In both cases, it should be OK.

    3) app_uart_put() is to be the correct way to transmit data in this context.
    If you have a look in the nus_data_handler(ble_nus_evt_t * p_evt) you can see how app_uart_put() is used.
    It seems that you are not waiting the tx to finish, other example typically use app_uart_put() inside a while loop. You can se how this is done in e.g. the peripheral example of uart on (line 173).
    while (app_uart_put(cr) != NRF_SUCCESS);

    4) I understand the confusion, and share this confusion with you. However, the serial port library is only a wrapper around the same functionality as using the uart more directly as is done in the app_uart example. I don't think it matters which method you choose to use, however I find the syntax in the serial port libary to be a bit easier.

    a) All the mentioned examples, etc. are able to handle both rx and tx
    b) Many of our BLE examples use UART and BLE simultaneously, the app_ble_uart does this as well. 
    c) I will recommend to disable the UART peripheral whenever possible, and e.g. use a BLE message or a pin input to trigger that the device should start listening on rx.

Children
No Data
Related