Hi I am using the tutorial from https://github.com/bjornspockeli/custom_ble_service_example. I have uncommented some of the starter code from ble_cus.c. My understanding is that the code only turns on LED 4 (also assigned to gpio pin 20) on the NRF52480 DK (pca10056) board if the data written from a connected BLE client is equal to 2. So when I write over a byte or byte array with value 0x02 the LED 4 should turn on. If I write over a byte that is 0x01 the LED 4 will turn off. Other values should not change the current LED 4 state.
However, I notice when I write any value of data type byte, byte array, UINT8, or any number between 0 to 9 for data type Text, I can turn the LED 4 on and off by sending a new write value. The new write values can be same or different than the previous write value, but it seems like sending a new write value to the DK board turns the LED back on or back off. Why does this occur?
The uncommented code below:
static void on_write(ble_cus_t * p_cus, ble_evt_t const * p_ble_evt)
ble_gatts_evt_write_t const * p_evt_write = &p_ble_evt->evt.gatts_evt.params.write;
// Custom Value Characteristic Written to.
if (p_evt_write->handle == p_cus->custom_value_handles.value_handle)
if(*p_evt_write->data == 0x01)
else if(*p_evt_write->data == 0x02)
Its because of this line:
You toggle the line regardless of data sent and then depending on the value that you send to it you either set the pin low or high if you send 0x01 or 0x02.