SYD8801 systick tick timer 使用说明
SYD8801是一款低功耗高性能蓝牙低功耗SOC,集成了高性能2.4GHz射频收发机、32位ARM Cortex-M0处理器、128kB Flash存储器、以及丰富的数字接口。SYD8801片上集成了Balun无需阻抗匹配网络、高效率DCDC降压转换器,适合用于可穿戴、物联网设备等。具体可咨询:http://www.syd-tek.com/
SYD8801 systick tick timer 使用说明
和其他的以ARM MO为内核的MCU一样,SYD8801内部也有MO自带的systick tick timer,这里使用方法也十分简单。
注意:在M0中,systick tick timer是一个24bit的递减计数器:
注意:system_tick存在一个缺陷:如果想动态改变这个定时器的周期,必须要留足够的时间给硬件反应,否则直接改可能无效!
主函数如下:
//static void timer0_callback(void);
int main()
{
// uint8_t i=0;
led_config(LEDALL);
Systick_Init();
// if(LPOCaliWaitUS(1000)){
// for(i=0;i<6;i++){
// led_turn(LEDALL);
// delay_ms(300);
// }
// }else{
// for(i=0;i<20;i++){
// led_turn(LEDALL);
// delay_ms(300);
// }
// }
//
// timer_0_enable(0x1F40, timer0_callback); // 8000 /32.768 ms = 244.140625 ms
__enable_irq();
while(1)
{
}
}
void SysTick_Handler(void)
{
GPO_CTRL->GPO_7 = ~GPO_CTRL->GPO_7;
}
这里在主函数中初始化了systick tick timer,然后在其中断函数中翻转GPIO7这个管脚的状态
其中初始化函数如下:
void Systick_Init(void)
{
// if (SysTick_Config(SystemCoreClock / 1000))//1ºÁÃë
// {
// /* Capture error */
// while (1);
// }
//
if (SysTick_Config(SystemCoreClock))
{
/* Capture error */
while (1);
}
}
systick tick timer的时钟就是MCU运行的时钟,传入的SystemCoreClock变量是定时器的分频值,其中SysTick_Config函数是MO自带函数,如下:
/**
\brief System Tick Configuration
\details Initializes the System Timer and its interrupt, and starts the System Tick Timer.
Counter is in free running mode to generate periodic interrupts.
\param [in] ticks Number of ticks between two interrupts.
\return 0 Function succeeded.
\return 1 Function failed.
\note When the variable <b>__Vendor_SysTickConfig</b> is set to 1, then the
function <b>SysTick_Config</b> is not included. In this case, the file <b><i>device</i>.h</b>
must contain a vendor-specific implementation of this function.
*/
__STATIC_INLINE uint32_t SysTick_Config(uint32_t ticks)
{
if ((ticks - 1UL) > SysTick_LOAD_RELOAD_Msk)
{
return (1UL); /* Reload value impossible */
}
SysTick->LOAD = (uint32_t)(ticks - 1UL); /* set reload register */
NVIC_SetPriority (SysTick_IRQn, (1UL << __NVIC_PRIO_BITS) - 1UL); /* set Priority for Systick Interrupt */
SysTick->VAL = 0UL; /* Load the SysTick Counter Value */
SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk |
SysTick_CTRL_TICKINT_Msk |
SysTick_CTRL_ENABLE_Msk; /* Enable SysTick IRQ and SysTick Timer */
return (0UL); /* Function successful */
}
最后这里上传本博客使用到的源代码:http://download.csdn.net/detail/chengdong1314/9890438