STM32 v3.5固件库systick ms延时
在标准外设库中移除了SysTick的驱动,因此用户必须调用CMSIS定义的函数。
CMSIS只提供了一个SysTick设置的函数,替代了STM32原有SysTick驱动的全部函数。
SysTick_Config(uint32_t ticks);
该函数设置了自动重载入计数器(LOAD)的值,SysTick IRQ的优先级,复位了计数器(VAL)的值,开始计数并打开SysTick IRQ中断。SysTick时钟默认使用系统时钟。
下面的例程为使用固件库V2.0.3进行SysTick设置:
/* Select the HCLK Clock as SysTick clock source (72MHz) */
SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK);
/* SysTick end of count event each 1ms with input clock equal to 72MHz (HCLK) */
SysTick_SetReload(72000);
/* Enable SysTick interrupt */
SysTick_ITConfig(ENABLE);
下面的例程为使用标准外设库V3.0.0进行SysTick设置:
/* Setup SysTick Timer for 1 msec interrupts */
if (SysTick_Config(SystemFrequency / 1000)) /* SystemFrequency is defined in “system_stm32f10x.h” and equal to HCLK frequency */
{
/* Capture error */
while (1);
}
2.0库函数延时代码
/*初始化时钟*/
void Init_SysTick(void)
{
/* Disable SysTick Counter */
SysTick_CounterCmd(SysTick_Counter_Disable);
/* Disable the SysTick Interrupt */
SysTick_ITConfig(DISABLE);
/* Configure HCLK clock as SysTick clock source */
SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK_Div8);
/* SysTick interrupt each 1000 Hz with HCLK equal to 72MHz */
SysTick_SetReload(9000);
/* Enable the SysTick Interrupt */
SysTick_ITConfig(ENABLE);
}
__IO uint32_t TimingDelay;
void delay_ms(__IO uint32_t nTime)
{
/* Enable the SysTick Counter */
SysTick_CounterCmd(SysTick_Counter_Enable);
TimingDelay = nTime;
while(TimingDelay != 0);
/* Disable SysTick Counter */
SysTick_CounterCmd(SysTick_Counter_Disable);
/* Clear SysTick Counter */
SysTick_CounterCmd(SysTick_Counter_Clear);
}
/*stm32f10x_it.c中的void SysTick_Handler(void)函数改为*/
extern __IO uint32_t TimingDelay;
void SysTick_Handler(void)
{
if (TimingDelay != 0x00)
{
TimingDelay--;
}
}
/*用法,延时1秒*/
delay_ms(1000);
3.5库函数延时代码
/*初始化时钟*/
void Init_SysTick(void)
{
if(SysTick_Config(SystemCoreClock / 1000)) //注意:3.5库中SystemFrequency 被SystemCoreClock 取代。
while(1);
}
/*延时1ms函数*/
__IO uint32_t TimingDelay;
void delay_ms(__IO uint32_t nTime)
{
TimingDelay = nTime;
while(TimingDelay != 0);
}
/*stm32f10x_it.c中的void SysTick_Handler(void)函数改为*/
extern __IO uint32_t TimingDelay;
void SysTick_Handler(void)
{
if (TimingDelay != 0x00)
{
TimingDelay--;
}
}
/*用法,延时1秒*/
delay_ms(1000);
STM32v3 5固件库systickms延 相关文章:
- STM32 V3.5固件库下SysTick的使用(11-27)
- stm32v3.5库的时钟配置(11-25)
- STM32的V3.5库Systick优先级设置的问题(11-20)
- 如何使用STM32_V3.5版本固件库建立工程模板(11-17)
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)