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

There is no good example for UART handler.

I can see that there is one example for UART and it uses application uart module (APP_UART_FIFO_INIT ...). I used this module for printing strings on terminal window, but now i need to communicate with sensor over UART and it just does not work for me. I tried blocking and non blocking mode (by passing handler function).

Here is my code:

void uart_error_handle(app_uart_evt_t * p_event)
{
	switch (p_event->evt_type)
	{
		case APP_UART_DATA_READY:
			APP_ERROR_CHECK(nrf_drv_uart_rx((uint8_t *)rx_data, LENGHT_RX));
		break;
		
		case APP_UART_TX_EMPTY:
		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;
	}
}

void uart_config(void)
{   
	const app_uart_comm_params_t comm_params =
  {
      UART_RX,
      UART_TX,
      RTS_PIN_NUMBER,
      CTS_PIN_NUMBER,
      APP_UART_FLOW_CONTROL_DISABLED,
      false,
      UART_BAUDRATE_BAUDRATE_Baud921600
    };

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

  APP_ERROR_CHECK(err_code);
    
  enable_uart_peripheral();
}

//I am calling tx function in my sensor read function in non blocking mode:
APP_ERROR_CHECK(nrf_drv_uart_tx(tx_data, LENGHT_TX));

Configuration with UART driver (NRF_DRV_UART_INIT ...) works, but it is much harder to write handler function over UART driver, and there is no good example.

Here is my code:

void uart_config(void)
{       
    nrf_drv_uart_config_t config;
    config.pselrxd = UART_RX;
    config.pseltxd = UART_TX;
    config.pselrts = RTS_PIN_NUMBER;
    config.pselcts = CTS_PIN_NUMBER;
    config.baudrate = NRF_UART_BAUDRATE_921600;
    config.hwfc = NRF_UART_HWFC_DISABLED;
    config.parity = NRF_UART_PARITY_EXCLUDED;
    config.interrupt_priority = APP_IRQ_PRIORITY_LOWEST;
    config.p_context = NULL;
    
    APP_ERROR_CHECK(nrf_drv_uart_init(&config, NULL));
}

//I am calling tx and rx functions in my sensor read function in blocking mode:
APP_ERROR_CHECK(nrf_drv_uart_tx(tx_data, LENGHT_TX));
APP_ERROR_CHECK(nrf_drv_uart_rx((uint8_t *)rx_data, LENGHT_RX));

I would like if sobebody can point me in the good direction. Example code would help.

Sorry for my bad english.

Parents Reply Children
No Data
Related