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?

Related