LPC1768 / ARM Cortex-M3 microsecond delay

前端 未结 3 1909
闹比i
闹比i 2021-01-25 05:22

I\'m trying to implement a microsecond delay in a bare metal arm environment( LPC1768 ) / GCC. I\'ve seen the examples that use the SysTimer to generate an interrupt that then d

3条回答
  •  广开言路
    2021-01-25 05:32

    You can use SYSTICK inside ARM processor for that. Just program it to count each 1uS, or less if you have enough clock speed, and do-while a loop till your delay value expires. Like this:

    void WaitUs(int us) {
    
        unsigned int cnt; 
    
        while(us-- >0) {
           cnt = STK_VAL; // get systick counter, ticking each 500nS
           while( (STK_VAL-cnt) < 2); // repeat till 2 ticks
        }
    }
    

    Bear in mind that this is an example, you'll need to adjust it for counter roll-over among other things.

提交回复
热议问题