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

What is a good practice to "block" for async event.

HI, I wan't to read sensor data from ADC. So i use nrf_drv_saadc_sample(). On Arduinos i usually call value = analogRead() and after that i process the data. But here the data comes asynchronously. So i can't make a simple clean function that would give me the data i need.

I had an idea of making a bool data_is_ready,set it to false, call nrf_drv_saadc_sample() and make while(!data_is_ready).

Now inside a callback function on the end of the function set the bool back to true. But as i understand this is not a way to do with nordic.

What is a good practice to make such event. Is there a sleep function which does not block the CPU? Maybe some combination using RTC?

My idea of a clean concept would be something like value = getMySensorData(), and to continue from there on.

Parents
  • I don't see why you cannot do that with nordic. But as you mention it might be better to just sleep while you wait for the end event and then continue processing the data. Did you see our github example?

  • Thank you for you anwser. It is realy better to use __WFE() and __SEV(). I was using delay and that was blocking the CPU. I also had problem with SAMPLES_IN_BUFFER because for more then one sample i was only calling one nrf_drv_saadc_sample().

Reply
  • Thank you for you anwser. It is realy better to use __WFE() and __SEV(). I was using delay and that was blocking the CPU. I also had problem with SAMPLES_IN_BUFFER because for more then one sample i was only calling one nrf_drv_saadc_sample().

Children
No Data