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
  • I don't see any reason why this should occur. Looks like you need to look into how you handle the BLE_GAP_EVT_ADV_REPORT events.

    You can try to reduce SCAN_INTERVAL and SCAN_WINDOW both to 0x5 to see if that have any impact on the issue you experience.

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

  • 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

  • I can find you have several while() and do-while() loops that may be problematic. Have you done any debugging into which may be delaying return to main()-loop?

    I can't really find that where in you application you are reading or output system_ticks? I can find the function get_System_ticks(), but it's not used anywhere?

    Kenneth

  • Hi Kenneth,

    I've resolved the issue now it is going to main loop as well, actually I was using buzzer as well and in nrf_ble_scan.c file in BLE_GAP_EVT_ADV_REPORT case I have used for loop also to run buzzer for long time now I've reduced the for loop value and now it is going to main loop as well. 

    And get_System_ticks() I'm calling in BLE_GAP_EVT_ADV_REPORT, I'm not calling it in main file

    Now my code is working but still I've one doubt that why it was not going to main loop when there is for loop used in BLE_GAP_EVT_ADV_REPORT with more value as I've used for buzzer here, and when I reduced to less value, now it is going in main loop.

    Thanks.

Reply
  • Hi Kenneth,

    I've resolved the issue now it is going to main loop as well, actually I was using buzzer as well and in nrf_ble_scan.c file in BLE_GAP_EVT_ADV_REPORT case I have used for loop also to run buzzer for long time now I've reduced the for loop value and now it is going to main loop as well. 

    And get_System_ticks() I'm calling in BLE_GAP_EVT_ADV_REPORT, I'm not calling it in main file

    Now my code is working but still I've one doubt that why it was not going to main loop when there is for loop used in BLE_GAP_EVT_ADV_REPORT with more value as I've used for buzzer here, and when I reduced to less value, now it is going in main loop.

    Thanks.

Children
Related