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

Bug in nrf_delay_us()

This comment for this line of code in twi_sw_master.c is misleading:

#define TWI_DELAY() nrf_delay_us(4) /*!< Time to wait when pin states are changed. For fast-mode the delay can be zero and for standard-mode 4 us delay is sufficient. */

If you call nrf_delay_us() with a parameter of zero, then the first thing it will do is subtract 1, then continue counting backwards from 0xFFFFFFFF:

static __ASM void __INLINE nrf_delay_us(uint32_t volatile number_of_us)
{
loop
    SUBS    R0, R0, #1
    ...

I think the correct behavior should be to terminate immediately if the number_of_us parameter is zero (as in "delay for 0 microseconds").

Related