I'm having an rather cryptic problem where around 0.01% bytes are simply not transmitted via UART for some reason.
This error happens independently from the chosen baudrate, parity bytes, or control lines setting.
I've verified it happens on the transmit side, by tapping into the Tx line with protocol analyzer. However, I was unable to catch the exact moment in the analog domain, it's insanely hard thing to do with such low probability of happening. I'm using nrf52dk development board.
The device's job is to listen for BLE packets, filter them, and transmit their content via UART (from the softdevice context). It simultaneously responds to some commands from the main context too. This might be the clue, but I cannot see how, as beside this problem, the transmission works reliably.
Uart initialization (the event handler is empty)
static void uart_init(void) { ret_code_t err_code; 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, .baud_rate = UART_BAUDRATE_BAUDRATE_Baud230400 }; 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); }
Data transmission method
bool uart_put_bytes(lbga_raw_packet_t *p_raw_packet){ APP_ERROR_CHECK(app_uart_put(LBGA_API_CHAR_PACKET_START)); for (uint16_t i=0;i<p_raw_packet->len;i++){ volatile char c = p_raw_packet->data[i]; if ((c == LBGA_API_CHAR_PACKET_START)|| c == (LBGA_API_CHAR_PACKET_END)|| c == (LBGA_API_CHAR_PACKET_CR)){ APP_ERROR_CHECK(1); } APP_ERROR_CHECK(app_uart_put(c)); } APP_ERROR_CHECK(app_uart_put(LBGA_API_CHAR_PACKET_END)); return true; }
Example of the broken data packet (capture from protocol analyzer) - notice the missing "h4E" in 3rd packet.
h30 h31 h20 h6F h08 h00 h00 h93 hEF h12 hB8 h77 hF8 h02 h01 h1E h1B hFF h75 h00 h42 h04 h01 h40 h4E hF8 h77 hB8 h12 hEF h93 hFA h77 hB8 h94 hEF h92 h01 h00 h00 h00 h00 h00 h00 h00 h1F h00 hB5 hBF h20 h30 h31 h20 h70 h08 h00 h00 h93 hEF h12 hB8 h77 hF8 h02 h01 h1E h1B hFF h75 h00 h42 h04 h01 h40 h4E hF8 h77 hB8 h12 hEF h93 hFA h77 hB8 h94 hEF h92 h01 h00 h00 h00 h00 h00 h00 h00 h1F h00 hB5 h59 hE3 h30 h31 h20 h71 h08 h00 h00 h93 hEF h12 hB8 h77 hF8 h02 h01 h1E h1B hFF h75 h00 h42 h04 h01 h40 hF8 h77 hB8 h12 hEF h93 hFA h77 hB8 h94 hEF h92 h01 h00 h00 h00 h00 h00 h00 h00 h1F h00 hB5 h1E h0F
Best regards,
Jakub