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
  • Hi,

    The buttonless dfu example attempts to enter System OFF (deep sleep) on adv. timeout if you've kept the default implementation. In that case, see if it works if you comment the call to sleep_mode_enter(); being made from on_adv_evt()::BLE_ADV_EVT_IDLE.

  • 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 !

  • No worries. For wakeup I would suggest you set up a repeated app timer instance like most of our BLE examples do.

  • Yes tha's exactly what i did and it works fine. After handler function is finished, does the systeme goes automatically to sleep ? I also have a proble with my jlink connexion now , i don't know why, I have tried several boards always the same issue. I can connect with jlink commander but impossible with nordic tool like nrf Connect or SES. What is strange is taht i didn't get error in the past.

    C:\Users\flo>nrfjprog --version
    nrfjprog version: 10.8.0
    JLinkARM.dll version: 6.82c

    J-Link>connect
    Please specify device / core. <Default>: CORTEX-M4
    Type '?' for selection dialog
    Device>?
    Please specify target interface:
      J) JTAG (Default)
      S) SWD
      T) cJTAG
    TIF>S
    Specify target interface speed [kHz]. <Default>: 4000 kHz
    Speed>
    Device "NRF52833_XXAA" selected.
    
    
    Connecting to target via SWD
    InitTarget() start
    InitTarget() end
    Found SW-DP with ID 0x2BA01477
    SWD speed too high. Reduced from 4000 kHz to 853 kHz for stability
    Failed to power up DAP
    InitTarget() start
    InitTarget() end
    InitTarget() start
    InitTarget() end
    InitTarget() start
    InitTarget() end
    Cannot connect to target.
    J-Link>

  • Olfox said:
    does the systeme goes automatically to sleep ?

     You still have to call idle_state_handle() again after when the program execution returns back to your main loop.

    Olfox said:
    . I can connect with jlink commander

    Jlink commander is too failing to connect to the target based on the log you posted. Can you describe the programming setup you use (connections, voltage, etc)?

  • I'm using a jlink programmer like this : 

    it is connected to my nrf52833 via a custom production board. But recently i mak etwo times a short to gnd by accident because of a gnd debug wire that touch some voltage on the board so i wonder about something broken. This short has shutdown my laptop because of impact on USB i guess... 

    I already ordered a new segeer programmer . For the moment i will come back on the developpement board i think ... Disappointed

    But i'm surprised because i was able to debug two or three times this morning but then, impossible.

    The led of the jlink programme blink one time each second , with green color. Its seems to indicate according to documentation

    GREEN, switched off for 10ms once per second J-Link heart beat. Will be activated after the emulator has been in idle mode for at least 7 seconds.

  • Ok after replacing a mux that was ded on my custom production board, i can flash with nrfConnect programmer the four files with succes and the program run fine. I still have issue in debug mode with SES.

    I can connect to jlink, but i click on run degug, i get an error :

Reply Children
  • Hi Vidar, 

    It's ok i can work again. i had to check an option and remove the ldo on vdd pin into my jlink programmer.

    Now i'm using my Power Profile Kit to supply and analyse my power consumption.

    I had some trouble at the begining with the fact that i was enter into sleep mode (32uA) , timer wake up and execute the callback ( communication with the sensors , setitng some io...) , but after this callback execution, impossible to enter into sleep mode and program doesn't return to main. I don't know what uC was executing, but consumption was 7mA but i can't reach breakpoint into the main loop.

    After debugging, I found that issue comes from the fact that one IO was set to 1 , and avoid to enter system in low power... Strange because wake up is only allowed when pin30 rise from  to 1 ...

    I also wanted to send 16bit buffer into my characteristic , but i had to manage by spliting into two byte because it was crashig when i tried to upload my uint16 table directly.

    I have also reach the limit of the number of data into the service (256?) in three characeteristics.

    Now my systeme has all the feature i will work on imporving power consumption, but i create a new topics i think :) .

  • Hi,

    Thanks for the update, glad to hear the programming part working again. For other questions I'd prefer you post it in a new thread as we have already moved away from the original topic.

Related