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

custom_ble_service_example - Values written to NRF52DK odd behavior

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)
    {
        nrf_gpio_pin_toggle(LED_4);
        
        if(*p_evt_write->data == 0x01)
        {
            nrf_gpio_pin_clear(20); 
        }
        else if(*p_evt_write->data == 0x02)
        {
            nrf_gpio_pin_set(20); 
        }
        else
        {
          //Do nothing
        }
        
    }

Parents Reply Children
No Data
Related