2017-09-11 08:17 AM
Hi,
I am still working my way through the STM32 , and decided to move away from CubeMX, to use the registers. I have started by writing the following just to get the systick to work. Im not really interested on the time span, just want to see the interupt working. I have done the following, and wondering if anyone can tell me whats happening? I simply setup ticker interupt, and setup a delay. The delay should exit when count down to 0, but for some reason the Delay function never exits. I am using Keil and step through the Delay function and see it count down..
I am initialising the systick, and initialising the Load register.
I then simply create a Delay(x) routine to continue to check the variable to see if reached 0.
Many Thanks
Scott
#include 'stm32l073xx.h'
#include 'header.h'uint32_t TimeDelay=0;
int main(void)
{ SysTick_Initialize(100); // << init Load and set interupt Delay(5); //<<do a simple countdown. In here is the issue return 0; }void SysTick_Initialize(uint32_t ticks)
{ SysTick->CTRL=0; SysTick->LOAD=ticks-1; NVIC_SetPriority(SysTick_IRQn,(1UL<<__NVIC_PRIO_BITS)-1UL); SysTick->VAL=0; SysTick->CTRL |= SysTick_CTRL_CLKSOURCE_Msk; SysTick->CTRL |= SysTick_CTRL_TICKINT_Msk; SysTick->CTRL |= SysTick_CTRL_ENABLE_Msk; }void SysTick_Handler(void)
{ if(TimeDelay>0) //simply count down TimeDelay--; //just to test I have setup the interupt okay}void Delay(uint32_t nTime)
{ TimeDelay=nTime; while(TimeDelay !=0) //<<< this loop never breaks out.. The variable does count down to 0. ; }2017-09-11 08:29 AM
I think you missed applying 'volatile' qualifier to
TimeDelay.
2017-09-11 08:49 AM
Hi
You did't enable the NVIC systick IRQ
NVIC_EnableIRQ(SysTick_IRQn);
rgrds
vf
2017-09-11 09:04 AM
Hi
Thanks for your replies.
When I changed the line SysTick_Initialize(10) from 10 to 100, it works everytime. I can only assume the interupts were firing too often. Is this possible? I thought the debugger would catch this.
Regards
Scott
2017-09-11 11:01 AM
Hi vf
I assumed the line SysTick->CTRL |= SysTick_CTRL_TICKINT_Msk; enabled the interupt as the interupt routine gets called.
Regards
Scott
2017-09-11 11:02 AM
Hi David,
Sorry I had a typo , I left out the volatile when I posted the code. See below how I think I gt it to work.
Regards
Scott
2017-09-11 11:12 AM
Hi!
Yes you are right. Was a mistake.
Rgrds
vf
2017-09-11 11:26 AM
That may well be possible.
The SysTick is firing every 10 cycles but its handler takes at least 15 cycles just to get served.