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.

Parents Reply
  • Hi Jared

    I solved the problem.

    After the flag was set due to an interrupt, it was fine to stop the interrupt and clear the pending interrupt.

    I realized it with the following delay timer code

    It was very nice to solve

    void delay_timer (uint32_t time)
    {
        uint32_t err_code;
        delay_flag = true;
        err_code = app_timer_start(m_single_shot_timer_id, APP_TIMER_TICKS(time), NULL);
        APP_ERROR_CHECK(err_code);
        while (delay_flag)
        {
            sd_nvic_DisableIRQ(RADIO_IRQn);
            sd_nvic_ClearPendingIRQ(RADIO_IRQn);
            APP_ERROR_CHECK(err_code);
        }
    }

Children
Related