代碼
void bsp_us_delay(uint32_t us) {
uint32_t start, now, delta, reload, us_tick;
start = SysTick->VAL;
reload = SysTick->LOAD;
us_tick = SystemCoreClock / 1000000UL;
do {
now = SysTick->VAL;
delta = start > now ? start - now : reload + start - now;
} while (delta < us_tick * us);
}
測試(主要邏輯)
stm32_pin_mode(GPIOB,GPIO_PIN_6,pin_mode_output);
while (1){
pin_high(GPIOB,GPIO_PIN_6);
bsp_us_delay(20);
pin_low(GPIOB,GPIO_PIN_6);
bsp_us_delay(20);
}
邏輯分析儀查看結(jié)果
大概1us左右的誤差
文章來源地址http://www.zghlxwxcb.cn/news/detail-502354.html
文章來源:http://www.zghlxwxcb.cn/news/detail-502354.html
到了這里,關(guān)于STM32之HAL庫微妙延遲(借助Systick)的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!