Become a leader in the IoT community!
New DevHeads get a 320-point leaderboard boost when joining the DevHeads IoT Integration Community. In addition to learning and advising, active community leaders are rewarded with community recognition and free tech stuff. Start your Legendary Collaboration now!
I know double buffering is a common technique for handling non atomic operations. You can create two 32-bit variables `buffer_a` and `buffer_b` and use them as a double buffer. ISR would update one buffer say `buffer_a` with the new microsecond count. The read function would access the other buffer `buffer_b` . You can then toggle between which buffer the ISR writes to and which the read function accesses so that a complete value is always read, even if ISR updates the other buffer during the read operation
Hmm, okay okay… Makes sense, Thanks for this @marveeamasi 🙏
Yh you welcome @ifreakio you know you can temporarily disable interrupts around the update operation in the ISR and the read operation in your main code
To give me exclusive access to the variable during these critical sections
Yeah, you are right @marveeamasi 👍… @ifreakio try to disable interrupts during the read operation to prevent the ISR from updating the variable while you’re reading it.This will enable you to read either the old or new value in its entirety.
Okay yh
re enable interrupts after the operation is complete !! But pls use this approach with caution cus disabling interrupts for too long can make your system unresponsiveness
CONTRIBUTE TO THIS THREAD