I just learned STM8 and recorded how to solve the problems that occurred during debugging.
The chip used is STM8S103F3P6. I am going to make a card swiping module, in which the delay function is implemented with the tim2 timer. In the routines downloaded from the Internet, the delay function unit is 1ms. I think the interval time is a bit long, so I am going to change it to 10us, use the HSE external crystal oscillator 8MHz, 8 division, count 10 numbers to generate update interrupts. Then make a ms delay function, and implement 100 10us delay functions.
Problem phenomenon:
During the running process, it was found that after timer2 was initialized and the interrupt function enableinterrupts was turned on, the program could not jump out.
Problem analysis steps:
1. I debugged it first and found that the program could not jump out of the interrupt service function of tim2. At first, I thought that the code for clearing the interrupt flag was not executed, or that the code for clearing the interrupt flag should be executed immediately after entering the interrupt service function. I moved the code to the first sentence in the interrupt service function and ran it again, but it still did not work.
2. Open the register display window, refer to the Chinese manual of stm8s, find the register related content of tim2, debug in single step, and find that the clear interrupt bit of TIM2->SR1 is set to 0, but it will be set to 1 again after a few steps. I first analyzed that it might be a problem in a certain code, but after restarting four or five times, I found that the timing of setting to 1 is not fixed. Only then did I notice the CNTRL register. It seems that SR1 is set to 1 every time the value of this register becomes 0x09. Only then did I react that it might be that during the processing of the interrupt service function of tim2, another update interrupt came in and reset the update interrupt bit of SR1 to 1, which means that the timing of my tim2 is too short.
problem solved:
After extending the update time of the timer (100us), the problem was solved.
Summarize:
During the debugging process, I discovered the power of checking registers, which is a way to solve problems faster. When I used stm32 before, due to the rich online resources, basically any kind of problem could be searched. At the beginning, I also learned the library function version, so I didn’t use register debugging much, and mostly used the watch window to check the variable value. However, there are fewer online resources for stm8, and more of it needs to be done by yourself, which reflects the advantage of checking register values. It took about three hours from discovering the problem to solving it.
Previous article:STM8L052 timer 1 configuration 30S
Next article:ST official library function GPIO port read and write function
Recommended ReadingLatest update time:2024-11-16 15:54
- Popular Resources
- Popular amplifiers
- STM8 C language programming (1) - basic program and startup code analysis
- Description of the BLDC back-EMF sampling method based on the STM8 official library
- STM32 MCU project example: Smart watch design based on TouchGFX (8) Associating the underlying driver with the UI
- MC9S12XS MCU Principle and Embedded System Development
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
- How to get started with embedded development?
- [Perf-V Review] Transplanting the Hummingbird E203 open source SOC to the FPGA board
- How to control a switch with stm32
- Design USB3.1 high-speed SD Card reader based on Genesys GL3224
- If you want to make the three-pole tube work in the amplification area, what is the idea? You need to calculate the static working point ib ic VCE three...
- How to save the bricks with the RVB2601 board
- Does the AD18 library have this kind of package? Do I have to draw it myself?
- 77Ghz single-chip millimeter wave sensor enables automatic parking
- What is the function of this circuit in ESP32_Audio_kit?
- Please ask about the problem in TI official application manual - boost principle