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;
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
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- 12 "Wanli" Raspberry Pi car - socket learning (Android sending and receiving)
- How does Windows know the last startup failure?
- An adjustable voltage regulator circuit with 6V input and 8V output
- 【2022 Digi-Key Innovation Design Competition】Latest unboxing post
- EEWORLD University Hall----Live Replay: Intel FPGA Deep Learning Acceleration Technology
- How to assign IMX6-CB200 GPIO
- [Precise delay function] Precise delay function in IAR (MSP430)
- After reading this article from the Research Institute, I feel that 6-lane Wi-Fi still has a long way to go.
- Warning for trouble~~~~ la la la~ hurry to the front of the post to find out
- mcgs Kunlun Tongtai Modbus RTU, Modbus TCP communication method Modicon Modbus communication configuration steps