STM32 Learning 007_Use of Systick (Part 2)

Publisher:真诚的友谊Latest update time:2017-10-26 Source: eefocusKeywords:STM32 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

In "Embedded Learning 006_Use of Systick (I)", the use of registers in Systick is introduced in detail, and many functions are used. In fact, in the 3.5 version of the standard firmware library, the relevant driver functions are removed, and users must call the functions defined in CMSIS.h. CMSIS only provides a Systick setting function, which replaces all the original driver functions of STM32. The purpose of doing this may be to simplify the Systick setting, but it reduces the user's controllability of SysTick.

The function provided in CMSIS is SysTick_Config(uint32_t ticks); This function sets the value of the automatic reload counter (LOAD), the priority of the SysTick IRQ, resets the value of the counter (VAL), starts counting and turns on the SysTick IRQ interrupt. The SysTick clock uses the system clock by default.

This function is defined in Core_cm3.h, and the source code is as follows:

   static __INLINE uint32_t SysTick_Config(uint32_t ticks)

  if (ticks > SysTick_LOAD_RELOAD_Msk) return (1);                                                                                               
  SysTick->LOAD = (ticks & SysTick_LOAD_RELOAD_Msk) - 1;              
  NVIC_SetPriority (SysTick_IRQn, (1<<__NVIC_PRIO_BITS) - 1 );        
  SysTick-> VAL = 0;                                                                                        
  SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk | 
                   SysTick_CTRL_TICKINT_Msk | 
                   SysTick_CTRL_ENABLE_Msk;                                                
  return (0); }

As can be seen from the above function, this function completes the initial value of Systick, interrupt priority, enabling interrupts, and starting the timer, which greatly simplifies the program.

The ticks represent the initial value. For example, if the system clock is 72Mhz, then to generate a 1ms time base, we can write it like this.

SysTick_Config(SystemCoreClock/1000); Of course, it can also be written as: SysTick_Config(72000);

Knowing this, we can use it to make a simple delay function delay_ms(u16 time);

        code show as below:

            void delay_ms(u16 time)

             {

                             nTime=time; /nTime is a global variable and can be set as extern u16 nTime;/

                          while(nTime);

             }

       Directly add nTime-- in the interrupt function;

      Add SysTick_Config(72000) during the main function initialization process;


Keywords:STM32 Reference address:STM32 Learning 007_Use of Systick (Part 2)

Previous article:STM32 Learning 006_Systick Usage (I)
Next article:STM32 Learning 008_Analysis of ARM Products

Recommended ReadingLatest update time:2024-11-16 12:48

List of DMA1 channels of stm32, related operations of stm32 using DMA
DMA (Direct Memory Access) is often translated as "direct memory access". DMA applications have been available as early as Intel's 8086 platform. A complete microcontroller usually consists of components such as CPU, memory and peripherals. These components are generally independent in structure and function, and th
[Microcontroller]
List of DMA1 channels of stm32, related operations of stm32 using DMA
The principle and function of crystal oscillator in STM32
A crystal oscillator can be electrically equivalent to a two-terminal network consisting of a capacitor and a resistor in parallel and a capacitor in series. In electrical engineering, this network has two resonant points, with the lower frequency being the series resonance and the higher frequency being the parallel
[Microcontroller]
Several implementation methods of STM32 running lights
#include “stm32f10x.h” void RCC_Configuration(void);//2 void GPIO_Configuration(void);//GPIO void Delay(u32 count) { u32 i=0; for(;i count;i++); } int main(void) { RCC_Configuration();//3 LED_Heat(); while(1) { GPIO_SetBits(GPIOA,GPIO_Pin_0); //The first light is on Delay(800000); //Delay GPIO_ResetBits(GPIO
[Microcontroller]
STM32 serial port detailed explanation
What is a Serial Port UART: Universal Asynchronous Receiver/Transmitter USART: Universal Synchronous Asynchronous Receiver/Transmitter One is the most commonly used and simplest serial data transmission protocol. Only two data lines are needed to achieve full-duplex. Tx: Send data line Rx: Receive data line    
[Microcontroller]
Read MPU6050 data based on STM32 hardware I2C
MPU6050 is actually an I2C device with many registers (but we only use a few), and we operate this chip by reading and writing registers. So the first question is the I2C communication between STM32 and MPU6050. 1. Configure STM32 (using I2C1: PB6-SCL; PB7-SDA)       1) Clock RCC              RCC_APB2PeriphClockCmd(RC
[Microcontroller]
Read MPU6050 data based on STM32 hardware I2C
Design of closed-loop tension control system based on STM32
    Tension control systems are widely used in light industrial fields such as printing. When collecting and unwinding materials, it is important to maintain a constant tension to ensure the quality and efficiency of production. During the printing process or after printing is completed, the last step is generally to
[Microcontroller]
Design of closed-loop tension control system based on STM32
STM32 study notes development environment
This article mainly consists of two parts: one is the introduction and installation of the STM32 development environment MDK-ARM, and the other is the download and configuration of the STM32 official library files. 1. Development environment installation 1. Introduction to the development environment KEIL currently ha
[Microcontroller]
STM32 study notes development environment
Understanding STM32 library operations from tick clock
The library function operation of STM32 brings many conveniences to design developers. Developers do not need to fully understand the internal registers and hardware mechanisms of STM32. As long as they have a basic understanding of C language, they can complete the development of the microcontroller, which shortens t
[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号