我看官方例程并没有systick的例程,所以我模仿了582F自己写了一个,但是延迟不太对,1000个中断本来对应的是1s,结果只有0.9s
void Interrupt_VTF_Init(void)
{
NVIC_EnableIRQ(SysTicK_IRQn);
SetVTFIRQ((u32)SysTick_Handler,SysTicK_IRQn,0,ENABLE);
}
uint32_t SysTick_Config(uint64_t ticks)
{
if((ticks - 1) > SysTick_LOAD_RELOAD_Msk)
return (1); /* Reload value impossible */
SysTick->CMP = ticks - 1; /* set reload register */
SysTick->CTLR = SysTick_CTLR_INIT |
SysTick_CTLR_STRE |
SysTick_CTLR_STCLK |
SysTick_CTLR_STIE |
SysTick_CTLR_STE; /* Enable SysTick IRQ and SysTick Timer */
return (0); /* Function successful */
}
main()
{
WCHBLE_Init();
HAL_Init();
RF_RoleInit();
RF_Init();
IMU_Init();
SysTick_Config(130000);
Interrupt_VTF_Init();
pretime = systick;
PRINT("Enter Main Loop\r\n");
Main_Circulation();
}
}
void SysTick_Handler(void)
{
systick++;
if(systick > 1000)
{
systick = 0;
if(ledstate111 == 0)
{
ledstate111 = 1;
GPIO_ResetBits(GPIOC, GPIO_Pin_7);
}
else
{
GPIO_SetBits(GPIOC, GPIO_Pin_7);
ledstate111 = 0;
}
}
SysTick->SR = 0; //清除中断标志
}