STM32微秒级(us)延时
实现代码:
void Delay_us(uint16_t time)
{
HAL_SYSTICK_Config(72);
HAL_Delay(time);
HAL_SYSTICK_Config(72000);
}
由于使用的是F103配置的工作主频是72MHz,所以为72;
实现原理:修改HAL_Delay的延时,将延时从1ms减少一千倍,再修改回1ms;
可以通过下面的代码获取HAL的工作频率
RCC_ClocksTypeDef get_rcc_clock;
RCC_GetClocksFreq(&get_rcc_clock);
printf("SYSCLK_Frequency:%d\r\n",get_rcc_clock.SYSCLK_Frequency);
printf("HCLK_Frequency:%d\r\n",get_rcc_clock.HCLK_Frequency);
printf("PCLK1_Frequency:%d\r\n",get_rcc_clock.PCLK1_Frequency);
printf("PCLK2_Frequency:%d\r\n",get_rcc_clock.PCLK2_Frequency);
printf("ADCCLK_Frequency:%d\r\n",get_rcc_clock.ADCCLK_Frequency);
|