The STC microcontroller selects an external crystal oscillator and the programming program cannot switch back to the internal crystal oscillator, causing the microcontroller to be unusable.

The STC microcontroller selects an external crystal oscillator and the programming program cannot switch back to the internal crystal oscillator, causing the microcontroller to be unusable.

1 Overview

In the process of learning the 51 microcontroller, I chose STC's 12C2052AD model microcontroller as the entry-level chip. The first few subject experiments used the default internal crystal oscillator programming program and ran without problems.
A topic of LED brightness gradient was selected for experiment, and an external crystal oscillator burning program was set up. After successful programming for the first time, it can no longer be programmed. Could it be that the microcontroller is burned? it's broken? Then I started all kinds of tossing and tried using the internal crystal oscillator programming program, but there was no response when programming the external crystal oscillator. I was troubled by this problem. In the next few days, I will read the STC12C2052AD microcontroller user manual to find the answer. . .

2. Scene recurrence

2.1. LED light gradient experimental steps

  • 1. Connect the components on the breadboard according to the wiring diagram given in the figure below. If you don't have multiple LED lights, you can just connect one of them.
  • 2. Use the STC-ISP program to burn the program and select an external crystal oscillator. Click to download the program successfully.
  • 3. The LED runs according to the written program, and the brightness gradually changes from dark to bright. This experiment is completed.
  • 4. Cut off the power supply of the microcontroller and remove the components connected to the microcontroller.
  • 5. Power on the microcontroller, then program the microcontroller and select the internal crystal oscillator. No response, cannot be burned.
  • 6. Select an external crystal oscillator and program the microcontroller, but there is still no response and the program cannot be programmed.

file

3. MCU comes back to life

3.1.Process of locating the problem

Make a hypothesis and verify it for the first time

Is this microcontroller broken, or is the STC-ISP programming software setting incorrect, or the voltage is unstable, causing the program to fail to be programmed? Let’s start to verify these assumptions.

  • First, I changed to a new microcontroller and burned the program according to the above steps. The first time it was successful, but the second time it could not be burned either.
  • The problem arises when using an external crystal oscillator. Is it caused by hardware?

Due to the lack of understanding of microcontrollers, there is no idea for the time being. At this time, it is necessary to have a deeper understanding of microcontrollers and master more information to solve this problem.
By reading the STC12C2052AD microcontroller user manual, I found the following two key information

  • The microcontroller receives data through the UART serial port and requires a crystal oscillator to start.
  • STC-ISP sets the external crystal oscillator to take effect after the next cold start
Make a hypothesis and verify it a second time
  • 1. The first time the external crystal oscillator is selected for the burning process, the burning process is not done through the external crystal oscillator. The burning process is still completed using the internal crystal oscillator. It needs to be switched to the external crystal oscillator after the next power outage.
  • 2. When burning the program for the second time, power off the microcontroller in step 4 of the LED light gradient experiment and remove the external crystal oscillator. As a result, the second burning program uses the external crystal oscillator mode, but there is no external crystal oscillator in the hardware, and the UART serial port cannot transmit data, causing the burning to fail. Even if you try to set the internal crystal oscillator on the STC-ISP burning software later, you will not be able to burn it because the default mode at this time is the external crystal oscillator. Only after the external crystal oscillator is successfully programmed can the program be switched to the internal crystal oscillator mode.

3.2.Solution

1. External crystal oscillator programming program
  1. First, connect the crystal oscillator to the microcontroller according to the figure above, so that the microcontroller can start oscillating through the external crystal oscillator.
  2. The STC-ISP programming software can set the internal crystal oscillator or the external crystal oscillator, because the current microcontroller uses an external crystal oscillator. Assume that we set the STC-ISP to the external crystal oscillator mode, click to download the program, and the program is burned successfully!
2. Freely switch internal and external crystal oscillator programming programs

The above attempt has verified that the second reasoning is correct. After mastering this principle, you can switch the internal and external crystal oscillator programming program at will.

  • Internal crystal oscillator switches to external crystal oscillator
1.单片机硬件上是否外接晶振不重要,只有一个单片机即可。
2.在STC-ISP上设置外部晶振,然后点击下载程序。此次烧录程序使用的是内部晶振,他会成功。
3.断掉单片机5V正极电源,在接通5V电源。此时单片机才切换到了外部晶振。
4.再次烧录程序就不会成功了,因为它切换为了外部晶振,只有硬件外接晶振才可烧录程序。
  • Switch external crystal oscillator to internal crystal oscillator
1.当前单片机是外部晶振模式,第一次烧录程序必须为单片机硬件外接晶振,这样他才能通过外部晶振起振。
2.在STC-ISP上设置内部晶振,然后点击下载程序。此次烧录程序使用的是外部晶振。
3.断掉单片机5V正极电源,在接通5V电源。此时单片机才切换到了内部晶振。

4. Summary

There are two reasons for the problem described in the article overview.

  1. Setting the internal and external crystal oscillator mode in STC-ISP does not take effect after the first burning program. It needs to be manually cold-started after the burning process is completed.
  2. The MCU programming program is through the UART serial port, which relies on a crystal oscillator for data transmission. Without a crystal oscillator, data cannot be transmitted.

Therefore, the key point to solve this problem is to determine whether the current microcontroller is using an internal or external crystal oscillator. If it is impossible to determine which crystal oscillator is currently used, then connect the external crystal oscillator to provide both internal and external crystal oscillators for the microcontroller. When burning the program, there is a microcontroller Choose for yourself. As long as it finds the crystal oscillator, it solves the problem of not being able to program.

Guess you like

Origin blog.csdn.net/m0_38039437/article/details/134540357