stm32 SysTick system timer

Publisher:温暖的微风Latest update time:2019-01-04 Source: eefocusKeywords:stm32  SysTick Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

It is a 24-bit downward-counting timer. Each count takes 1/SYSTICK. SYSTICK is the system timer clock. It can be directly obtained from the system clock or obtained by dividing the system clock by 8. 

When the timer counts to 0, the initial value of the timer will be automatically reloaded from the LOAD register and count down again. 
If the SysTick interrupt is enabled, an interrupt signal will be generated when the timer counts to 0.


SysTick


void SysTick_Init(u8 SYSCLK)

{

    SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK_Div8); 

    fac_us=SYSCLK/8; //1us times             

    fac_ms=(u16)fac_us*1000; //1ms times                

}


void delay_us(u32 nus)

{       

    u32 temp;            

    SysTick->LOAD=nus*fac_us; //Time initial value           

    SysTick->VAL=0x00; //Clear the counter

    SysTick->CTRL|=SysTick_CTRL_ENABLE_Msk; //Turn on the timer   

    do

    {

        temp=SysTick->CTRL;

    }while((temp&0x01)&&!(temp&(1<<16))); //Wait for time to arrive   

    SysTick->CTRL&=~SysTick_CTRL_ENABLE_Msk; //Turn off the counter

    SysTick->VAL=0x00; //Clear the counter  

}


void delay_ms(u16 nms) //Maximum 1864ms

{                 

    u32 temp;          

    SysTick->LOAD=(u32)nms*fac_ms;

    SysTick->VAL=0x00;

    SysTick->CTRL|=SysTick_CTRL_ENABLE_Msk; 

    do

    {

        temp=SysTick->CTRL;

    }while((temp&0x01)&&!(temp&(1<<16)));

    SysTick->CTRL&=~SysTick_CTRL_ENABLE_Msk;

    SysTick->VAL=0x00;

}


Keywords:stm32  SysTick Reference address:stm32 SysTick system timer

Previous article:stm32 touch screen XPT2046
Next article:STM32 lights up LED

Recommended ReadingLatest update time:2024-11-16 15:35

STM32-General timer basic timing function
1. Introduction to STM32 Timer There are 11 timers in STM32, including 2 advanced control timers, 4 normal timers, 2 basic timers, 2 watchdog timers and 1 system tick timer. The system tick timer is SysTick described in the previous article, and the watchdog timer will be studied in detail later. Today we mainly study
[Microcontroller]
Standard function for sending data to the STM32 serial port
Example: 1 void UART_Send_Message(u8 *Data,u8 lenth) {   while(lenth--)   {       USART_SendData(USART2, *Data);       while(USART_GetFlagStatus(USART2, USART_FLAG_TXE) == RESET);       Data++;   } }   void main() {     u8 Sendbuf ;               Sendbuf =0xA0;     Sendbuf =0xA0;     Sendbuf =0xA0;            UART_S
[Microcontroller]
About STM32 memory image
1. Peripheral memory map Peripheral base address: corresponding peripheral memory start address + address offset (see the STM32 reference manual memory impact section and the corresponding peripheral memory) 2. SRAM      The STM32F10xxx has a built-in 20K bytes of static SRAM. It can be accessed as a byte, half word (
[Microcontroller]
Design of touch screen for battery management system based on STM32
0 Introduction Electric vehicles have always been a focus of attention for their cleanliness and environmental protection. With the intensification of the energy crisis and the continuous rise in oil prices, electric vehicles are becoming more and more popular among users. Electric vehicles are generally po
[Automotive Electronics]
Design of touch screen for battery management system based on STM32
STM32 ADC learning
Configuring ADC 1. System clock definition: RCC_Configuration(); Contains:  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMAx, ENABLE); // Enable DMA clock RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADCx , ENABLE); // Enable ADC1 and GPIOC clock 2. Interrupt source configuration: NVIC_Configuration(); Example: { NVIC_InitTypeDef NV
[Microcontroller]
Reasons and solutions for STM32_RTC crystal oscillator not oscillating
The RTC crystal oscillator of STM32 often fails to oscillate, which is already an "industry consensus". Many people ask for help on various electronic forums, such as "Ask an expert for advice! What should I do if the RTC crystal oscillator does not oscillate?" The answer can basically be summarized as "The expert can
[Microcontroller]
STM32 FLASH power-off data loss processing strategy and backup mechanism
1. Reasons Due to the characteristics of FLASH erasing and writing, if the power is lost during erasing or writing, failure may occur, and an error will occur when power is turned on and read next time. When power is turned off during erasing, it cannot be guaranteed that the data is completely erased, but the era
[Microcontroller]
STM32 FLASH power-off data loss processing strategy and backup mechanism
STM32 bit-band applications
With the support of bit operations in the Cortex-M3, ordinary load/store instructions can be used to read and write single bits.   Among the bit bands supported by CM3, there are two areas where bit bands are implemented.   One is the lowest 1MB range of the SRAM area, 0x20000000 ‐ 0x200FFFFF (the lowest 1MB in the S
[Microcontroller]
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号