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

Catch advertising timeout in main

Hi,

I would like to catch in main.c the nobody connect after advertising event via ADV_SET_TERMINATED. 

I can see with breakpoint program jump into  ble_advertising_on_ble_evt inble_advertising.c but once traeted, it doesn't call the same function in main.c.


I have added the case case BLE_GAP_EVT_ADV_SET_TERMINATED in ble_evt_handler in mains.c. But this timeout event doesn' reach the ble_evt_handler function of may main.c.

I saw another topics where Joakim Jakobsen proposed a good solution, that should solve the problem, but it dosn't work for me. My code is based on ble_app_buttonless_dfu_pca10100.

devzone.nordicsemi.com/.../142407

static void ble_evt_handler(ble_evt_t const * p_ble_evt, void * p_context)
{
    uint32_t err_code = NRF_SUCCESS;

    switch (p_ble_evt->header.evt_id)
    {
    
            case BLE_GAP_EVT_ADV_SET_TERMINATED:
               // AdvertisingTimeout, nobody connect after 1 minutes
               etat = EVENT_TIMEOUT;
            break;

Thanks a lot !

Parents Reply Children
  • Great that's works i can reach the event in main.c now. I had also this feeling before to read your answer that program was stopped lol.

    Now i have a second issue: after advertising timeout, i set ma state machine to enter low power with the call 2time to function idle_state_handle();:

     case LOW_POWER:
    
                        NRF_LOG_INFO("State Machine : LOW POWER");
                
                        bma400_goto_mode_power(MODE_LOW_POWER);    // attention si echec recommencer 
    
                        idle_state_handle();
                        idle_state_handle();    //why two times ? but it works...
    

    From a power on sequence this go into low power mode works. But after timeout advertising, it jump over the two function wihtout going into low power mode.

    Is there a link with the fact that we were in timeout advertising event previously may be ?

    Thank you Vidar !

  • I'm using a gpio to enter low power mode:

    I tried to call again thi init sequence but it doesn't allow to enter a second time in low power:

                    nrf_drv_gpiote_in_config_t in_config = GPIOTE_CONFIG_IN_SENSE_LOTOHI(true);
                    in_config.pull = NRF_GPIO_PIN_NOPULL;
    
                    err_code = nrf_drv_gpiote_in_init(30, &in_config, in_pin_handler);
                    APP_ERROR_CHECK(err_code);
                    nrf_drv_gpiote_in_event_enable(30, true);

  • After wake up , i did the test to come back again in low power and i can still wakeup with my accelerometre, so what is sure, is that advertising timeout event change the condition to go into low power again.

  • Hi,

    What kind of sleep are you trying to enter, System OFF or System ON. If it's system ON I would just recommend calling idle_state_handle() from the main loop like we do in our SDK examples. 

    Also noticed that you were using GPIOTE IN events. This increases the idle current in SYSTEM ON. You may consider using GPIOTE port events instead:

    nrf_drv_gpiote_in_config_t in_config = GPIOTE_CONFIG_IN_SENSE_LOTOHI(true); // <-- Set to false to use low power PORT events. GPIOTE IN vs PORT event: Sleep

  • Hi Vidar,

    I'm in system On to keep ram retention and clock because i should wake up every day. My system start, do all peripherals init, go in low power with idle_state_handle(); called two time because first time it jump over i don't know why.

    Then I wake up with GPIOTE ( accelerometer connected to one input pin). It toggle from low to high. Once wake up, nrf52833 start advertising. If nobody connect, it raise timeout event, and i call idle_state_handle() to enter in low power, but it doesn't work this time. It jump over the the function without going into low power mode.

    How to know why it is impossible to enter into sleep mode ?

    Thanks for the tips to use port event

Related