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

problem of LED blinky by advertising

I want to turn on /off LED by advertising TX of BLE

peripheral : nrf52810
central : nrf52840
Specifically, peripheral performs advertising TX,
The central processes LED blinkly when the filter of ADDR is matched by scan_evnt_handler.
Sending of advertising of peripheral is sent only when I want to turn on/off the LED.

In the code of Example 1, the operation worked as code and worked well.

static void scan_evt_handler(scan_evt_t const * p_scan_evt)
{
    ret_code_t err_code;
    switch(p_scan_evt->scan_evt_id)
    {
       case NRF_BLE_SCAN_EVT_FILTER_MATCH:
       {
           nrf_gpio_pin_set(LED1_PIN);
           nrf_delay_ms(2000);
           nrf_gpio_pin_clear(LED1_PIN);
        }break;
    default:
    break;
    }
}

In the code of Example 2, sending advertising only turned on first,and then sending advertising could not turn it off.
Where is the problem?

static void scan_evt_handler(scan_evt_t const * p_scan_evt)
{
    ret_code_t err_code;
    switch(p_scan_evt->scan_evt_id)
    {
       case NRF_BLE_SCAN_EVT_FILTER_MATCH:
        {
           if(nrf_gpio_pin_out_read(LED1_PIN)){
            nrf_gpio_pin_set(LED1_PIN);
            }
            else{
             nrf_gpio_pin_clear(LED1_PIN);
             }
         }break; 
     default:
          break;
    }
}    

Expected behavior of the code in Example 2.

Advertising transmission →Turn on the LED and hold its state.
Advertising transmission →Turn off the LED and hold its state.

Please let me know solution method.

Related