1. STM32 clock configuration initialization function:
void Stm32_Clock_Init(){
unsigned char temp = 0; //define an unsigned char type variable named temp
MYRCC_DeInit(); //Reset and configure the vector table. This function is automatically written by Keil, so you don't need to worry about it.
RCC->CR |= 0x00010000; //Set the 16th bit of the clock control register of stm32 to 1 to enable the external clock (HSE). For details, see the description of the RCC_CR register on page 85 of the STM32 reference manual.
while(! (RCC->CR>>17)); //Judge the 17th bit of the RCC_CR register, that is, whether the external high-speed clock is ready
RCC->CFGR = 0x00000400; //Set the 10th to 8th bits of the clock configuration register to make the APB1 clock not exceed 36MHz to prevent system disorder caused by APB1 clock exceeding 36MHz
PLL-=2; //Subtract 2 from the PLL value to configure the system's phase-locked loop frequency multiplication factor. For specific requirements, see bits 21-18 of the RCC_CFGR register.
RCC_CFGR |=(PLL<<18); // Shift the PLL value minus 2 by 18 bits and perform an OR operation with the original RCC_CFGR value to configure the PLL value.
RCC_CFGR|=(1<<16); //Use external clock as system clock
FLASH_ACR |= 0x32; //Delay FLASH by two cycles. For details, refer to the ST document PM0042 programming manual "STM32F10XXX Flash Programming"
RCC_CR |= 0x01000000; // Enable PLL
while(!(RCC->CR>>25)); //Judge whether PLL is enabled successfully
RCC_CFGR |= 0x0000002; //Use PLL output as system clock
while(temp!=0x02) { //Wait for PLL output to be set as system clock successfully
temp=RCC-CFGR>>2;
temp&=0x03;
}
}
Previous article:STM32F407ZGT6 uses Systic timer to achieve delay
Next article:STM32 SysTick timer delay function
Recommended ReadingLatest update time:2024-11-16 16:00
- 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
- TI CC2540 USB CDC Serial Port driver installation failure reasons and solutions
- TMS320DM642 learning connection method
- How to copy the files used in the compiler and IDE installation directory to the project folder when creating a new CCS project
- Puzhong 89C52, burning program error
- [GigaDevice GD32F310 Review] + Interactive Detection Device
- Unboxing record of the new IoT player mPower1203
- 4. Differential and Integral Circuits
- Is there a green, free-installation version of Excel for download?
- [CB5654 Intelligent Voice Development Board Review] Create a sample project and download the test
- GPIO3_28, why is it still shown as occupied?