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

UART example not working

Hi

I have development kit nrf51 PCA 10028 and try to run uart example example with loopback (RX connected to TX, RTS connected to CTS). Unfortunately, after sending, I don't get anything from uart. Has anyone any idea why? I use SDK 11.0.0

Here is the code (almost the same as in example):

 const app_uart_comm_params_t comm_params =
      {
          RX_PIN_NUMBER,
          TX_PIN_NUMBER,
          RTS_PIN_NUMBER,
          CTS_PIN_NUMBER,
          APP_UART_FLOW_CONTROL_DISABLED,
          false,
          UART_BAUDRATE_BAUDRATE_Baud115200
      };

    APP_UART_FIFO_INIT(&comm_params,
                         UART_RX_BUF_SIZE,
                         UART_TX_BUF_SIZE,
                         uart_error_handle,
                         APP_IRQ_PRIORITY_LOW,
                         err_code);

    APP_ERROR_CHECK(err_code);

    while (true)
    {
        uint8_t * tx_data = (uint8_t *)("\n\rLOOPBACK_TEST\n\r");
        uint8_t   rx_data;

        // Start sending one byte and see if you get the same
        for (uint32_t i = 0; i < MAX_TEST_DATA_BYTES; i++)
        {
            uint32_t err_code;
            while(app_uart_put(tx_data[i]) != NRF_SUCCESS);

            nrf_delay_ms(10);
            err_code = app_uart_get(&rx_data);

            if ((rx_data != tx_data[i]) || (err_code != NRF_SUCCESS))
            {
                show_error();
            }
       }
    }
Parents
  • Hi, UART is well established to work on nRF chips.

    /**@brief Function for getting a byte from the UART.
     *
     * @details This function will get the next byte from the RX buffer. If the RX buffer is empty
     *          an error code will be returned and the app_uart module will generate an event upon
     *          reception of the first byte which is added to the RX buffer.
     *
     * @param[out] p_byte    Pointer to an address where next byte received on the UART will be copied.
     *
     * @retval NRF_SUCCESS          If a byte has been received and pushed to the pointer provided.
     * @retval NRF_ERROR_NOT_FOUND  If no byte is available in the RX buffer of the app_uart module.
     */
    uint32_t app_uart_get(uint8_t * p_byte);
    

    I am guessing that you are not listening to APP_UART_DATA_READY in your uart_error_handler. I guess the naming in the example is not correct, because it is not just the error events that you get but also TX and RX events.

    just add one case to you uart_error_handler

    case APP_UART_DATA_READY: /* new data received */

  • Then i suggest you to see

    1. if the UART is initialized properly without errors?
    2. Check the lines with the oscilloscope (or a LOGIC analyzer) and see if the data is coming or not.
Reply Children
No Data
Related