STM8S study notes-clock control 1

Publisher:MysticJourneyLatest update time:2021-10-09 Source: eefocusKeywords:STM8S Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

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.

Keywords:STM8S Reference address:STM8S study notes-clock control 1

Previous article:Detailed explanation of STM8L clock switching
Next article:【STM8 MCU】---A brief understanding of clock configuration

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号