This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

When ble_nus_data_send does not work???

As below, BLE Data RX works fine, but TX doesn't.
When does this happen?

Currently BLE connect/disconnect and RX is working fine.
The power does not turn off due to this phenomenon.

Not all products exhibit the above symptoms. This was the first time this happened (1 sample).

After receiving, the green LED turns on/off and it is judged that the received data has been received well.

Also, when Rx Data is received, Rx Data is immediately returned (APP) to Tx.

Thank you.

* SDK15.2.0 , nRF52840

static void nus_data_handler (ble_nus_evt_t * p_evt)
{
    uint32_t err_code;
    if (p_evt-> type == BLE_NUS_EVT_RX_DATA)
    {
        if (p_evt-> params.rx_data.p_data [2] == BLE_FACTORY_START) / * * /
        {
            ble_test_mode = true;
            send_data_battery [2] = p_evt-> params.rx_data.p_data [2];
            err_code = ble_nus_data_send (& m_nus, send_data_battery, &length, m_conn_handle);
         }

       ....

}

* Abnormal sample and normal working sample

  • I think that it's must be some bug in your case with non-ascii code(utf.c problems). If your application code in your mobile side(android or ios) is not fixed. You may change the format to ascii code. It's more safe way for your solution. By the way,...It's the nRF Toolbox (android & ios) available. You may use this tool for debug( especial the NUS service, define hot key or so on).

    Finally, if you don't want to change your code to string format, you have to make sure ble_nus_data_send ()

    length

    uint16_t length = (uint16_t)index;
    err_code = ble_nus_data_send(&m_nus, data_array, &length, m_conn_handle);

Related