Closed
Description
Issuer reported here by ut2uz:
http://stm32duino.com/viewtopic.php?f=48&t=2960
delayMicrosecond sometimes makes much shorter delay than requested. Say, 1 us instead of 4500.
Original implementation from wiring_time.h:
static inline void delayMicroseconds(uint32_t usec){
uint32_t start = GetCurrentMicro();
while((start+usec) > GetCurrentMicro());
}
Proposed solution by ut2uz:
static inline void delayMicroseconds(uint32_t usec){
uint32_t end = GetCurrentMicro() + usec;
while(((int32_t)(GetCurrentMicro()-end))<0);
}
Note that delays greater than 2147483647 (2147 sec = 35 min ) are handled incorrectly. I'm not familiar with compiler warnings in this IDE, so left the solution as is.