APP_UART_COMMUNICATION_ERROR in uart_event_handler after calling function APP_UART_INIT(&comm_params, uart_event_handle, APP_IRQ_PRIORITY_LOWEST, err_code);

Hi,

    Im working on n2f52805 where i need to include uart in my application.But when i call APP_UART_INIT function it is giving an event in uart_event_handle and giving the error APP_UART_COMMUNICATION_ERROR .In this project custom ble is working.I don't want to use uart fifo so i removed app_uart_fifo.c and added app_uart.c .

void uart_event_handle(app_uart_evt_t * p_event)
{
static uint8_t data_array[MAX_DATA_LEN];
static uint8_t index = 0;
uint32_t err_code;
NRF_LOG_INFO("uart_event_handle.");
switch (p_event->evt_type)
{
case APP_UART_DATA_READY:
NRF_LOG_INFO("APP_UART_DATA_READY.");
UNUSED_VARIABLE(app_uart_get(&data_array[index]));
break;

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

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

default:
break;
}
}
/**@brief Function for initializing the UART module.
*/
/**@snippet [UART Initialization] */
static void uart_init(void)
{
uint32_t err_code = NRF_SUCCESS;
app_uart_comm_params_t const comm_params =
{
.rx_pin_no = RX_PIN_NUMBER,
.tx_pin_no = TX_PIN_NUMBER,
.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_INIT(&comm_params, uart_event_handle, APP_IRQ_PRIORITY_LOWEST, err_code);
NRF_LOG_INFO("UART INIT %d.",err_code);
APP_ERROR_CHECK(err_code);
}
/**@brief Application main function.
*/
int main(void)
{
bool erase_bonds;

// Initialize.
log_init();
uart_init();
/* timers_init();
buttons_leds_init(&erase_bonds);
power_management_init();
ble_stack_init();
gap_params_init();
gatt_init();
services_init();
advertising_init();
conn_params_init();
//peer_manager_init();

// Start execution.
NRF_LOG_INFO("Template example started.");
application_timers_start();

advertising_start(erase_bonds);


// Enter main loop.
for (;;)
{
idle_state_handle();
}*/


while(1){
app_uart_put('A');
app_uart_put('K');
app_uart_put('S');
app_uart_put('H');
app_uart_put('A');
app_uart_put('Y');
app_uart_put('\n');
}
}

Parents
  • Hi there,

    Can you read out the ERRORSRC register when you get this error?

    regards

    Jared

  • Yes the rx pin state is low . Also im using p0.5 as rx,and p0.4 as tx.

    Could you tell me how to use this function NRF_GPIO->PIN_CNF[RX_PIN_NUMBER] to pull up.In my project i dont have libraries for gpio peripheral.

  • I use this function  nrf_gpio_cfg_input(RX_PIN_NUMBER, NRF_GPIO_PIN_PULLUP); before uart_init(); .Now the rx pin is set but after this function nrf_drv_uart_init(&app_uart_inst, &config, uart_event_handler); the rx pin state becomes low and giving the same error

  • What if you move it to after nrf_drv_uart_init()?

    regards

    Jared

  • I added external pull up for both rx and tx pins . Now the tx and rx started working but in uart handle im not able to send a complete string . When i try to send it on the uart handle then it is only send the first byte.I'm able the send strings in while loop.Rx data reception is working perferctly.

    This is the function im using:-

    static void Uart_Send(char * data, uint32_t length)
    {
    uint8_t i;
    for (i = 0; i < length; i++) {
    while(app_uart_put(data[i]) != NRF_SUCCESS);
    //app_uart_put(data[i]);
    }
    app_uart_put('\r'); app_uart_put('\n');
    }

    //uart handle

    void uart_event_handle(app_uart_evt_t * p_event)
    {
    static uint8_t data_array[MAX_DATA_LEN] = {0x00};
    static uint8_t index = 0;
    uint32_t err_code;
    NRF_LOG_INFO("uart_event_handle.");
    switch (p_event->evt_type)
    {
    case APP_UART_DATA:
    NRF_LOG_INFO("APP_UART_DATA_READY.");
    UNUSED_VARIABLE(app_uart_get(&data_array[index]));
    index++;

    if ((data_array[index - 1] == '\n') ||
    (data_array[index - 1] == '\r'))
    {
    if (index > 1)
    {
    NRF_LOG_INFO("UART DATA LOG\n");
    NRF_LOG_INFO("UART RX DATA %s",data_array);
    //for(int i=0;data_array[i]!='\r';i++){
    // nrf_delay_ms(1);
    // app_uart_put(data_array[i]);
    //}
    Uart_Send(data_array,index);
    memset(data_array,0,MAX_DATA_LEN);
    }

    index = 0;
    }
    break;

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

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

    default:
    break;
    }

    //uart init

    static void uart_init(void)
    {
    uint32_t err_code = NRF_SUCCESS;
    app_uart_comm_params_t const comm_params =
    {
    .rx_pin_no = RX_PIN_NUMBER,
    .tx_pin_no = TX_PIN_NUMBER,
    .rts_pin_no = RTS_PIN_NUMBER,
    .cts_pin_no = CTS_PIN_NUMBER,
    .flow_control = APP_UART_FLOW_CONTROL_DISABLED,
    .use_parity = NRF_UART_PARITY_EXCLUDED,
    #if defined (UART_PRESENT)
    .baud_rate = NRF_UART_BAUDRATE_115200
    #else
    .baud_rate = NRF_UARTE_BAUDRATE_115200
    #endif
    };


    APP_UART_INIT(&comm_params, uart_event_handle, APP_IRQ_PRIORITY_LOWEST, err_code);
    NRF_LOG_INFO("UART INIT %d.",err_code);
    APP_ERROR_CHECK(err_code);
    }


    }

    //pin cofig:

    nrf_gpio_cfg_input(RX_PIN_NUMBER, NRF_GPIO_PIN_NOPULL);
    // Configure the UART TX pin as output
    nrf_gpio_cfg_output(TX_PIN_NUMBER);
    uart_init();

  • Hi,

    In general it's advised to spend as short time as possible in callback handlers, I can't see that you check the return value of app_uart_put(), can you check what it returns?

    regards

    Jared 

Reply Children
No Data
Related