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