Hi,
I have been using the NUS service via the ble_app_uart example on SDK 16 in conjunction with the nRF Connect iOS app and all works fine.
I connect via the iOS app and when I select the notify button on the iOS app corresponding to the UART TX Characteristic, I get the BLE_NUS_EVT_COMM_STARTED notification.
At this point, I can send and receive data and when I send data, I get the BLE_NUS_EVT_TX_RDY notification to indicate the send completed.
However, when I port the example code into my own nRF52 app, I do not get the BLE_NUS_EVT_COMM_STARTED notification. I can receive data from the iOS app but when I try to send I get NRF_ERROR_INVALID_STATE from sd_ble_gatts_hvx() in ble_nus_data_send() which I guess is consistent with the NUS service not being ready.
The code appears identical but clearly I missing something - if anyone can suggest what I might have missed for the BLE_NUS_EVT_COMM_STARTED not to be sent, I would be very grateful...
static void nus_data_handler(ble_nus_evt_t * p_evt) { char rxData[20] = {0}; bleNUS_TX_RDY = false; //NRF_LOG_INFO("Received event from NUS %d\n",p_evt->type); switch(p_evt->type) { case BLE_NUS_EVT_COMM_STARTED: NRF_LOG_INFO("BLE_NUS_EVT_COMM_STARTED.\n"); break; case BLE_NUS_EVT_COMM_STOPPED: NRF_LOG_INFO("BLE_NUS_EVT_COMM_STOPPED.\n"); break; case BLE_NUS_EVT_TX_RDY: NRF_LOG_INFO("BLE_NUS_EVT_TX_RDY.\n"); bleNUS_TX_RDY = true; break; case BLE_NUS_EVT_RX_DATA: NRF_LOG_INFO("BLE_NUS_EVT_RX_DATA.\n"); NRF_LOG_HEXDUMP_DEBUG(p_evt->params.rx_data.p_data, p_evt->params.rx_data.length); memcpy(rxData,p_evt->params.rx_data.p_data,p_evt->params.rx_data.length); NRF_LOG_INFO("rxData >%s<\n",rxData); printf("rxData >%s<\n",rxData); break; default: NRF_LOG_INFO("RX default %d\n",p_evt->type); break; } }
Log from working example code:
app: Debug logging for UART over RTT started. app: Connected app: Data len is set to 0xB6(182) app: ATT MTU exchange completed. central 0xF7 peripheral 0xF7 app: PHY update request. app: ATT MTU exchange completed. central 0xF7 peripheral 0xF7 app: BLE_NUS_EVT_COMM_STARTED.
Log from same function ported to my app:
app: Connection 0x1 established app: Data len is set to 0xB6(182) app: ATT MTU exchange completed. Central 0xF7 Peripheral 0xF7 app: PHY update request. app: ATT MTU exchange completed. Central 0xF7 Peripheral 0xF7