I am using a ultra-miniature (BMD-350) series module from Rigdo which has the nRF52832 BLE SoC. The pins from the nrf52 SoC are all brought out on a female headers on a custom PCB.
Firmware/SDK configuration:
- nRF5_SDK_15.3.0_59ac345 SDK
- pca10040 and softdevice s132
- nrf52832_xxaa
Debugger
- J-Link EDU Mini debug module and using Segger Ozone software for debugging.
nrf Android Apps:
- nrFConnect, nrF Logger and nrfUART app
I have modified the ble_app_uart example and attached the zip file of modified code.
In the main.c file, I modified the function nus_data_handler to send dummy packets(appx. 24 bytes per packet) to the nrfUART app by calling the function ble_nus_data_send periodically 5 seconds over BLE NUS to nrfUART app inside a loop over 500 times. Below is the code snippet:
/**@snippet [Handling the data received over BLE] */ static void nus_data_handler(ble_nus_evt_t * p_evt) { // uint8_t rx_byte; NRF_LOG_INFO("[%d]nus_data_handler", order++); if (p_evt->type == BLE_NUS_EVT_RX_DATA) { NRF_LOG_INFO("[%d]nus_data_handler: evt=BLE_NUS_EVT_RX_DATA", order++); uint32_t err_code; NRF_LOG_DEBUG("Received data from BLE NUS. Writing data on UART."); NRF_LOG_HEXDUMP_DEBUG(p_evt->params.rx_data.p_data, p_evt->params.rx_data.length); for (uint32_t i = 0; i < p_evt->params.rx_data.length; i++) { do { err_code = app_uart_put(p_evt->params.rx_data.p_data[i]); if ((err_code != NRF_SUCCESS) && (err_code != NRF_ERROR_BUSY)) { NRF_LOG_ERROR("Failed receiving NUS message. Error 0x%x. ", err_code); APP_ERROR_CHECK(err_code); } } while (err_code == NRF_ERROR_BUSY); // nrf_delay_ms(10); // // err_code = app_uart_get(&rx_byte); // if( ( rx_byte != p_evt->params.rx_data.p_data[i] ) && err_code != NRF_SUCCESS ) // { // NRF_LOG_ERROR("Failed to Loopback character 0x%x. Error: 0x%x", // p_evt->params.rx_data.p_data[i], // err_code ); // } } if (p_evt->params.rx_data.p_data[p_evt->params.rx_data.length - 1] == '\r') { while (app_uart_put('\n') == NRF_ERROR_BUSY); // nrf_delay_ms(10); // // err_code = app_uart_get(&rx_byte); // // if( ( rx_byte != p_evt->params.rx_data.p_data[p_evt->params.rx_data.length - 1] ) && err_code != NRF_SUCCESS ) // { // NRF_LOG_ERROR("Failed to Loopback character 0x%x. Error: 0x%x", // p_evt->params.rx_data.p_data[p_evt->params.rx_data.length - 1], // err_code ); // } } } NRF_LOG_DEBUG("Received string %s", p_evt->params.rx_data.p_data); NRF_LOG_HEXDUMP_DEBUG(p_evt->params.rx_data.p_data, p_evt->params.rx_data.length); // If Data Received is "Requesting Data", then start sending data in a loop // char const * expected_str = "Requesting Data"; // if( 0 == strncmp( (char*)(p_evt->params.rx_data.p_data), expected_str, strlen(expected_str) ) ) { NRF_LOG_DEBUG("Ready to send sensor data over BLE NUS"); uint32_t err_code; //char * data = "24, 0.000, 0.000, 1, D1\n"; char data_buffer[BLE_NUS_MAX_DATA_LEN]; // srand (time(NULL)); // float x; for( int i = 0; i <500; i++) { // x = ((float)rand()/(float)(RAND_MAX)) * 0.9999; // sprintf(data_buffer, "24,%.2f,%d,D1\n",x, i+1); sprintf(data_buffer, "24,0.000,%d,D1\n", i+1); uint16_t length = strlen(data_buffer); NRF_LOG_DEBUG("Sending over BLE. Data length: %d, Data: %s", length, data_buffer); do { err_code = ble_nus_data_send(&m_nus, (uint8_t*)data_buffer, &length, m_conn_handle); if ((err_code != NRF_ERROR_INVALID_STATE) && (err_code != NRF_ERROR_RESOURCES) && (err_code != NRF_ERROR_NOT_FOUND)) { APP_ERROR_CHECK(err_code); } } while (err_code == NRF_ERROR_RESOURCES); nrf_delay_ms(5000); } } // else // { // NRF_LOG_DEBUG("Not received required string!"); // } } /**@snippet [Handling the data received over BLE] */
While I do receive first 12 packets on nRFUART app but thereafter I stop receiving anything even though I should continue to receive remaining 489 of 500 dummy packets. The Bluetooth connection also gets disconnected and I dont see the nrf52 advertising. Thereafter, I have to reset my nRF52 to make new Bluetooth connection and restart this process.
I have tried manipulating buffer sizes used by ble_nus_data_send as well as UARt bufffers, but nothing seems to work. Either I get run-time error or issue remains.
What is the proper way to send streaming data packets to the nrfUART from nrf52 continuously using the BLE UART service ?