On a custom board with an nRF52832 communicating over UART with another microcontroller with no flow control capability.
SDK 13.0.0-1.alpha with an S132SD.
I have some weirdness where reading data from the UART is returning the previously received message. (i.e. - messages seem to be one message behind.)
Messages are encoded as raw bytes (nano-bp) and I have verified that the other micro is transmitting/receiving and encoding/decoding just fine.
I can TX messages from the nRF52 without issue.
init looks like this:
static void uart_init(void)
{
uint32_t err_code;
const app_uart_comm_params_t comm_params =
{
RX_PIN_NUMBER,
TX_PIN_NUMBER,
NULL,
NULL,
APP_UART_FLOW_CONTROL_DISABLED,
false,
UART_BAUDRATE_BAUDRATE_Baud19200
};
APP_UART_FIFO_INIT( &comm_params,
UART_RX_BUF_SIZE,
UART_TX_BUF_SIZE,
uart_event_handle,
APP_IRQ_PRIORITY_LOWEST,
err_code);
APP_ERROR_CHECK(err_code);
}
UART event handler:
void uart_event_handle(app_uart_evt_t * p_event)
{
switch (p_event->evt_type)
{
// case APP_UART_DATA_READY:
// UART_available = true; // globally defined bool
// 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;
}
}
Checking for APP_UART_DATA_READY events doesn't seem to solve the problem as the data is definitely there.
Messages are more or less read a byte at at time like so then decoded, which works just fine:
while(app_uart_get(&data) == NRF_SUCCESS)
{
if(index < sizeof(msg_buffer))
{
msg_buffer[index] = data;
}
index++;
}
msg_buffer is local and is reinitialized before every read.
I have tried app_uart_flush() in various locations to clear any extraneous data that might be in the buffer prior to the data arriving to no avail.
Oddly, the very first attempt to decode a message after boot always fails (but subsequent messages are successfully decoded, just with the previous message's data) leading me to believe there's initially garbage in the buffer which could account for the messages always being one behind.
I tried consuming the data and ignoring it on first read to discard any garbage to no avail:
static bool is_first_message = true;
if(is_first_message)
{
while(app_uart_get(&data) == NRF_SUCCESS)
{
if(index < sizeof(msg_buffer))
{
msg_buffer[index] = data;
}
index++;
}
is_first_message = false;
}
Happy to provide more details within reason.
Any suggestions or thoughts would be greatly appreciated!