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

how to run main loop parallel with nrf_ble_scan event

Hi Nordic Team,

I have one doubt which I can not able to understand.

Actually in my code I'm scanning some ble devices also in main infinite loop I'm reading some sensor data, my problem is when nrf device scan the other devices it goes to main loop after so long, I also run app_timer_start before main loop as I also counting the ticks, so in my code when there is no device to scan it goes to loop immediately and get the sensor data, but when I switch on the other devices and my devices scans these devices then it goes to main loop randomly like some time systick count is 30 sometimes it is beyond 200 so why it is happening like that. Is there any way so that it scan the devices as well as it also goes to the main loop.

Thanks in advance.

Any help will be highly appreciated.

Parents Reply Children
  • Hi Kenneth, 

    Thanks for the reply, now as you have told about handling BLE_GAP_EVT_ADV_REPORT event, so there only I'm scanning 4 devices I've also mentioned there addresses so I don't think It's not handling properly.

    Now for SCAN_INTERVAL and SCAN_WINDOW I think you are talking about NRF_BLE_SCAN_SCAN_INTERVAL and NRF_BLE_SCAN_SCAN_WINDOW so these values were defined 160 and 80 respectively so as per your suggestion now I changed it to 0x05 but still it's not going to my main loop to read sensor data. As soon as I just switch off the others ble devices which my current device is scanning it immediately goes to my main loop, so definitely something is stopping or delaying it to going to my main loop.

    So I'm still not getting where I'm doing wrong.

    Thanks.

  • The only explanation I have is that the handling of BLE_GAP_EVT_ADV_REPORT takes long time? Maybe try to add some gpio toggling to try to find what may be taking time?

    But how long is a systick here? Is it ~30us? 

    Kenneth

  • I'm running app_timer_start with Notification interval of 1000(1 sec), so my systick increments every 1 seconds, by observing the systic only I see that at what seconds it is going to main loop. There are already gpio are working like when it scan those device then leds glow like that.

    Thanks

  • I think you will just have to debug this further. I don't have any explanation to why you have a 30-200second delay sometimes no, it just doesn't make sense, sorry. 

    Maybe take a new look at the central examples.

    Kenneth

  • I've debug it several times and it's not delay it's timer interrupt through which I'm getting systick. 

    Here I'm uploading my main.c file for your refernece please let me know where I'm doing wrong. as I told I'm reading rtc data from main loop, when there is no other ble device ON it goes to loop and gives the RTC data but when any nrf52840 device is on then serving loop is happening randomly or even after so long it only goes to scan the device.1738.main.c

Related