2014-07-10 12:25 PM
2014-07-10 12:55 PM
SysTick is an Interrupt (System Handler), you define the periodicity that this is called.
You configure it with ticks of the system clock, it figures out which source (SYSCLK, vs HCLK/8) depending on the number of ticks, and the fact the counter has only 24-bit. Only supports a single periodicity, ie 1 ms, if you want 1s and 1ms you'd count off 1000 milliseconds, then do the 1Hz task. It is NOT a delay function. Review an example: STM32F4xx_DSP_StdPeriph_Lib_V1.3.0\Project\STM32F4xx_StdPeriph_Examples\SysTick\SysTick_Example\main.c/* Setup SysTick Timer for 1 msec interrupts.
------------------------------------------
1. The SysTick_Config() function is a CMSIS function which configure:
- The SysTick Reload register with value passed as function parameter.
- Configure the SysTick IRQ priority to the lowest value (0x0F).
- Reset the SysTick Counter register.
- Configure the SysTick Counter clock source to be Core Clock Source (HCLK).
- Enable the SysTick Interrupt.
- Start the SysTick Counter.
2. You can change the SysTick Clock source to be HCLK_Div8 by calling the
SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK_Div8) just after the
SysTick_Config() function call. The SysTick_CLKSourceConfig() is defined
inside the misc.c file.
3. You can change the SysTick IRQ priority by calling the
NVIC_SetPriority(SysTick_IRQn,...) just after the SysTick_Config() function
call. The NVIC_SetPriority() is defined inside the core_cm3.h file.
4. To adjust the SysTick time base, use the following formula:
Reload Value = SysTick Counter Clock (Hz) x Desired Time base (s)
- Reload Value is the parameter to be passed for SysTick_Config() function
- Reload Value should not exceed 0xFFFFFF
*/
if (SysTick_Config(SystemCoreClock / 1000))
{
/* Capture error */
while (1);
}
/**
* @brief This function handles SysTick Handler.
* @param None
* @retval None
*/
void SysTick_Handler(void)
{
TimingDelay_Decrement();
}
2014-07-10 02:38 PM
Hi Clive,
Many thanks for responding. Based on the explanation you posted, Reload Value = the number of systick timer cycles the timer will start counting from, subtracting one with each cycle until it gets to 0. Based on my setup is it correct to assume that 21M will equal one second? (since the timer runs on a 21MHz clock (i think :S)) What would you suggest i use if not the systick timer in order to implement a wait function? The reason I'm trying to implement this : I'm trying to connect my stm32f4 discovery board to a dht11 temperature sensor. That sensor uses a proprietary single wire bus/protocol to transmit/receive information (I already have it working with a stm8 and an arduino - i'm out of my league when it comes to stm32/arm though). My cunning plan was to create a 1us delay (by initializing the timer and then waiting for it to get to 0) and then use that to count the number of microseconds each time the wire transitions to high when pulled up by that sensor (i think a 0 is something like 20us and a 1 is 50us) in order to get the temperature value. I also wanted to use that delay function in order to wait for some time (e.g. 10 mins) before polling the sensor again etc. Best regards2014-07-10 08:10 PM
1 MHz is too high to interrupt, consider using DWT_CYCCNT
You can use SysTick and TIM for periodic interrupts, counting down other timeouts, etc. For long delays consider the RTC and low power options, rather than spinning in a tight loop.2014-07-11 02:23 PM
Hi,
Thanks for all your help :) Have a great weekend! Best regards