cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L0 - Microseconds delay function

pbdiazam
Associate II

Hi everyone!

I am using a STM32L0 board and I need to read data from a sensor. To be able to do this, I need a microsecond delay function, but I could not find any way to achieve this.

I need some help! Thank you!

3 REPLIES 3

Free run a TIM at 1 MHz (or higher) and delta the count measurement until it reaches the span of the delay required. Pretty basic stuff.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Dvorak.Peter
Senior II

True, unless you need low microseconds. Here I would use inline asm counter code or insert NOPs

If you need nano-second realm stuff clock the TIM faster. Heck even at 24 MHz you can get well sub-microsecond

On the non-CM0 parts consider the DWT_CYCCNT

Timer and counters aren't afflicted by interrupt loading compared to fixed iterations loops with NOP, etc.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..