1. As shown in Figure 13, the STM8S microcontroller has four main clock sources to choose from:
1).1-24MHz external crystal oscillator (HSE).
2).Maximum 24MHz external clock (HSE ext).
3).16MHz high speed internal RC oscillator (HSI).
4).128KHz low speed internal RC oscillator (LSI).
2. The main clock can be switched from any of these four clock sources, and the switching process can be automatic switching or manual switching.
Automatic switching process: enable the corresponding clock source, enable switching, and wait for the switching to complete.
For example: Switching from HSI to external HSE, the subroutine is as follows:
void CLKToHSE(void)
{
while(!(CLK_ECKR&0x02)); //Wait for HSE to be ready
CLK_ECKR |= 0x01; // Enable HSE
CLK_SWCR |= 0x20; //Enable switching
CLK_SWR = 0xB4; // (0xE1----HSI )
// (0xD2 ----LSI)
//(0xB4----HSE)
while(!(CLK_SWCR&0x01)); //Wait for clock switching to complete
CLK_ICKR &= ~0x01; //Disable HSI
}
Manual switch:
Manual switching is similar to automatic switching, except that you have to wait until the clock is stable before switching.
For example, the HSI switches to the internal LSI, and the subroutine is as follows:
void CLKToLSI(void)
{
while(!(CLK_ICKR&0x10)); //Wait for LSI to be ready
CLK_ICKR |= 0x08; // Enable LSI
CLK_SWR = 0xD2; // (0xE1----HSI)
// (0xD2 ----LSI)
// (0xB4----HSE)
while(!(CLK_SWCR&0x08));
CLK_SWCR |= 0x20; //Enable switching
CLK_ICKR &= ~0x01; //Disable HSI
}
3. Clock division
HSI can be divided by HSIDIV[1:0] of CLK_CKDIVR. The division factor can be 1, 2, 4, or 8.
The CPU clock can be divided by CPUDIV[2:0] of CLK_CKDIVR. The division ratio can be 1, 2, 4, 8, 16, 32, 64, 128.
The peripheral clock can be enabled or disabled through CLK_PCKENR1 and CLK_PCKENR2. Under reset, all peripheral clocks are enabled by default. If you are not familiar with it, you can choose the default to prevent the peripherals from being used without configuring the clock. Disabling unnecessary peripherals can reduce system power consumption.
There are also clock security system CSS, clock output, clock interrupt, SWIM clock control, HSI clock calibration, etc. We will discuss them next time.
Previous article:Detailed explanation of STM8L clock switching
Next article:【STM8 MCU】---A brief understanding of clock configuration
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Industry first! Xiaopeng announces P7 car chip crowdfunding is completed: upgraded to Snapdragon 8295, fluency doubled
- P22-009_Butterfly E3106 Cord Board Solution
- Keysight Technologies Helps Samsung Electronics Successfully Validate FiRa® 2.0 Safe Distance Measurement Test Case
- Innovation is not limited to Meizhi, Welling will appear at the 2024 China Home Appliance Technology Conference
- Innovation is not limited to Meizhi, Welling will appear at the 2024 China Home Appliance Technology Conference
- Huawei's Strategic Department Director Gai Gang: The cumulative installed base of open source Euler operating system exceeds 10 million sets
- Download from the Internet--ARM Getting Started Notes
- Learn ARM development(22)
- Learn ARM development(21)
- Learn ARM development(20)
- 【Mil MYD-YA15XC-T】- 0: How to power on?
- Xilinx Zynq-7015 SoC Industrial Core Board SOM-XQ7Z15 Cortex-A9 + Artix-7
- ADI Power Supply Expert Training Course Advanced Edition is in progress! What are you waiting for?
- ARM Architecture and Programming
- Gigabit RISC-V GD32VF103USB CDC debugging
- Problems encountered in debugging the Southchip SC8721 high-efficiency synchronous buck-boost converter
- (A-Current signal detection device) Chongqing "TI Cup" Award_Chongqing University of Posts and Telecommunications
- This appears and I can't choose it. It's grayed out.
- 【AT-START-F403A Review】3. Try USB Composite_Device
- Today at 10:00 AM, live broadcast with prizes: Protecting clean water sources - ADI water quality monitoring solutions