cancel
Showing results for 
Search instead for 
Did you mean: 

positively lost regarding systick

d_dhmas
Associate II
Posted on July 10, 2014 at 21:25

The original post was too long to process during our migration. Please click on the attachment to read the original post.
4 REPLIES 4
Posted on July 10, 2014 at 21:55

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();
}

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
d_dhmas
Associate II
Posted on July 10, 2014 at 23:38

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 regards
Posted on July 11, 2014 at 05:10

1 MHz is too high to interrupt, consider using DWT_CYCCNT

https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/compensating%20latencies%20on%20STM32F4%20interrupts&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B&cu...

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.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
d_dhmas
Associate II
Posted on July 11, 2014 at 23:23

Hi,

Thanks for all your help 🙂 Have a great weekend!

Best regards