Assistance Needed with BLE Application Development on nRF5340 Development Board

Hello Nordic Team,

I am writing because I encountered an issue while developing a BLE application on the nRF5340 development board. Currently, I have set up this callback to receive commands from the nRF Connect app:

static ssize_t setPlayTrack(struct bt_conn *conn,
                            const struct bt_gatt_attr *attr,
                            const void *buf,
                            uint16_t len,
                            uint16_t offset,
                            uint8_t flags)
{
    uint16_t track_number = *((uint16_t *)buf);

    if (track_number < 1 || track_number > 2999) 
    {
        return BT_GATT_ERR(BT_ATT_ERR_VALUE_NOT_ALLOWED);
    }

    DFPlayer_Errors_t err = DFPlayer_setPlay(&dfPlayerDriverOne, track_number);
    err = DFPlayer_setPlay(&dfPlayerDriverTwo, track_number);
    err = DFPlayer_setPlay(&dfPlayerDriverThree, track_number);
    err = DFPlayer_setPlay(&dfPlayerDriverFour, track_number);

    if (err != DF_PLAYER_ERROR_NONE) 
    {
        return BT_GATT_ERR(BT_ATT_ERR_UNLIKELY);
    }

    return len;
}

I send 16-bit data from the mobile app and receive it on the microcontroller. However, during debugging, I noticed an issue with the received data. When I send the number 1 from the app, I receive the number 3 on the microcontroller. Here are some of the results:

  • Sending (uint16) 1 from the app, I receive 3 (uint16) on the microcontroller.
  • Sending (uint16) 2 from the app, I receive 2 (uint16) on the microcontroller.
  • Sending (uint16) 3 from the app, I receive 3 (uint16) on the microcontroller.
  • Sending (uint16) 4 from the app, I receive 4 (uint16) on the microcontroller.
  • Sending (uint16) 5 from the app, I receive 7 (uint16) on the microcontroller.
  • Sending (uint16) 6 from the app, I receive 6 (uint16) on the microcontroller.
  • Sending (uint16) 7 from the app, I receive 7 (uint16) on the microcontroller.
  • Sending (uint16) 8 from the app, I receive 8 (uint16) on the microcontroller.
  • Sending (uint16) 9 from the app, I receive 11 (uint16) on the microcontroller.
  • Sending (uint16) 10 from the app, I receive 10 (uint16) on the microcontroller.

It seems that, for some commands, the second bit of the LSB in the 16-bit series is being set to 1. I couldn't identify the problem during debugging. Could you help me? I've attached a screenshot of the debug session where I send the uint16 value 1.

Thank you.

Cristian

Parents
  • Hi Cristian,

    Data corruption all the way to the application layer is not something that should happen at all.

    Have you checked if the len and offset parameters are all 0?

    Also, are you able to verify that the correct data is sent from the app?

    Are you able to reproduce the issue consistently?

    Hieu

  • Hi Hieu,

    I am currently absolutely sure that the data from the nrF APP is being sent correctly, and the error is reproducible consistently. However, I need to notify you that the len and offset are not always zero. Specifically, the length is 3 and the offset is zero, but sometimes the offset changes and becomes different from zero.

    Cristian

  • Hi Cristian,

    You will need to take offset into account when reading the data. Could you please update the callback handler to only copy len, offset, and ~10 bytes from buf to a different location and set a flag; and then in another thread or the main loop, act upon that flag and print out the value?

    I would like to look at what the data is like. Printing can take time, and the handler should be quick, thus I suggest copying the value out and print in a different context.

    Hieu

Reply
  • Hi Cristian,

    You will need to take offset into account when reading the data. Could you please update the callback handler to only copy len, offset, and ~10 bytes from buf to a different location and set a flag; and then in another thread or the main loop, act upon that flag and print out the value?

    I would like to look at what the data is like. Printing can take time, and the handler should be quick, thus I suggest copying the value out and print in a different context.

    Hieu

Children
No Data
Related