用GD32做项目,跟着官方文档一直做到后面,在做iic的时候一直被这个问题所困扰,好在最后解决
- 在systick.c文件中添加delay_us函数的定义和实现:
void delay_us(uint32_t count) { uint32_t startTick = SysTick->VAL; /* calculate the number of ticks for the given microseconds */ uint32_t ticks = count * (SystemCoreClock / 1000000U); /* wait until the required number of ticks has elapsed */ while((SysTick->VAL - startTick) < ticks) { } }
- 在systick.h文件中添加delay_us函数的声明:
void delay_us(uint32_t count);
- 在main.c中调用delay_us函数来实现以微秒为单位的延迟。
这样就可以在这段代码的基础上实现以微秒为单位的延迟函数