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

nRF51822 - UART Init error

Hi,

We try to communicate between nRF51822 SoC and a GPS module through UART on a custom board but failed initializing UART.

More details:

  • We use nRF51822 as a BLE peripheral using SoftDevice S110 v9.0
  • BLE tasks work fine (initializing, communication with other devices...)
  • On our design, we do not have flow control for UART communication
  • In order to initialize UART communication we define the following functions:

Function 1 - event handler -> called in case of a UART event

void uart_event_handle(app_uart_evt_t * p_event) {
   static uint8_t data_array[128];
   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++;

           if ((data_array[index - 1] == '\n') || (index >= (8)))
           {
               if (err_code != NRF_ERROR_INVALID_STATE)
               {
                   APP_ERROR_CHECK(err_code);
               }
            
               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:
           break;
 }
}

Function 2 - UART initializer

static void uart_init(void) {
   uint32_t err_code;
   const app_uart_comm_params_t comm_params =
     {
         UART_RXD_PIN,
         UART_TXD_PIN,
         UART_RXD_PIN,
         UART_TXD_PIN,
         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_event_handle,
                    APP_IRQ_PRIORITY_LOW,
                    err_code);

   APP_ERROR_CHECK(err_code);
}

Baud rate is the same between both devices. No control flow is possible. UART_RX_BUF_SIZE & UART_TX_BUF_SIZE are set equal to 64. We do not have RTS & CTS pin but we assume as control flow is disabled, their values in app_uart_comm_params_t are not really important.

Debugging, uart_init does not raise any error (according to APP_ERROR_CHECK). A few milliseconds after UART initialisation, uart_event_handle is triggered with APP_UART_COMMUNICATION_ERROR. data_error_communication has 0x0000000C value and the system stops.

Does anyone know about this problem? Are we doing something with UART initialization?

Parents
  • The error code indicates that the FRAMING and BREAK bits in the UART error register are set. This suggests that maybe the UART RX pin is being held low. For normal UART operation it should always be held high by the transmitting device when it's idle, except for when the transmitting device pulls it low for short pulses to send data. So if your GPS module hasn't started driving the pin yet and it's floating then this error might occur. Try enabling the internal pull-up on the UART RX pin to see if that fixes the error.

  • Not yet. Before calling uart_init(), I added this line of code: nrf_gpio_cfg_input(UART_RX_PIN, NRF_GPIO_PIN_PULLUP);

    It seems that uart_init() does not crash the device anymore. Unfortunately, when I add this line, I can not enter debug mode anymore, device is not seen by JLink anymore.

    So, I am not able to confirm it solves the problem right now. uart_init() does not crash the device anymore as I successfully turned on a LED just after this step but I can not see if UART is operational.

Reply
  • Not yet. Before calling uart_init(), I added this line of code: nrf_gpio_cfg_input(UART_RX_PIN, NRF_GPIO_PIN_PULLUP);

    It seems that uart_init() does not crash the device anymore. Unfortunately, when I add this line, I can not enter debug mode anymore, device is not seen by JLink anymore.

    So, I am not able to confirm it solves the problem right now. uart_init() does not crash the device anymore as I successfully turned on a LED just after this step but I can not see if UART is operational.

Children
No Data
Related