I am using nRF52832 with SDK 15.2.0 for my application. The application is created taking ble_app_uart example as the base. I have modified the example to suit my requirements. The application uses only one characteristics for sending and receiving data. Characteristics supports NOTIFY. The application also supports BLE NUS client role so it can do service discovery and also enable NOTIFICATION on the peer and get data from peer via NOTIFICATION. Connection interval minimum & maximum is set at 20 ms and 40 ms respectively.
My application receives large data around 30KB from peer (which is another BLE module in central mode) over BLE. The data is received via NOTIFICATIONS, 20 bytes at a time. The data received is then sent to a custom board which is connected using UART. Baud rate for UART is set at 9600 bps. The data transfer over UART starts soon after the application receives the notification value i.e as soon at it receives the first 20 bytes. It is observed that few bytes of data are lost while transmitting over UART. The loss of data is not consistent and I do receive the entire data sometimes.
For testing purpose I have connected a generic BLE module in a central mode and my device (which is the peripheral) to a PC using USB-Serial adapter. The central device connects to the peripheral, and using RealTerm I transmit 30KB of data from central to peripheral. The data received by the peripheral is transmitted back to the PC and captured using RealTerm.
I am using app_uart_put() to transmit data over UART
// Data transmit over UART for (uint32_t i = 0; i < data_len; i++) { do { ret_val = app_uart_put(p_data[i]); if ((ret_val != NRF_SUCCESS) && (ret_val != NRF_ERROR_BUSY)) { NRF_LOG_ERROR("app_uart_put failed for index 0x%04x.", i); APP_ERROR_CHECK(ret_val); } } while (ret_val == NRF_ERROR_BUSY); }
Any suggestions to further understand or debug the issues would be helpful.
On a side note, I noticed following comment in app_uart_put(). Is this causing the data loss, since BLE data is also being received continuously which has a higher priority and the function app_uart_put() is called in a do-while loop which will wait till the data is transmitted. Does this also explain why there is no data loss if the baud rate is higher. Is there a way to check if this is the reason for the data loss.
// This operation should be almost always successful, since we've // just added a byte to FIFO, but if some bigger delay occurred // (some heavy interrupt handler routine has been executed) since // that time, FIFO might be empty already. if (app_fifo_get(&m_tx_fifo, tx_buffer) == NRF_SUCCESS) { err_code = nrf_drv_uart_tx(&app_uart_inst, tx_buffer, 1); }