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