I have the CLI module over UART enabled, with one command that continuously prints out the readings from a sensor. What I'm trying to do is stopping this continuous printout if the user types CTRL+C. The sample code is below:
static void sensor_printout_cmd(nrf_cli_t const* p_cli, size_t argc, char** argv)
{
while(rx != ASCII_FOR_CTRL_C) /* rx is from UART, check here if byte read is CTRL+C */
{
uint8_t buf[3];
read_from_sensor(buf);
nrf_cli_fprintf(...); /* print sensor readings */
nrf_drv_uart_rx(&cli_uart_transport_uart, &rx, 1U); /* read character from UART */
}
}
The problem is that while I'm able to read properly from the UART with the nrf_drv_uart_rx() function, CLI over UART is unable to retrieve any more characters and locks the CLI. After stepping through the code, it seems like the CLI queue for UART gets messed up somehow because of the call to the nrf_drv_uart_rx() function.
So the question is: When using CLI with UART, is there a way to reliably read UART inputs while inside CLI commands?