Since I will be using stm8 recently, I started to learn stm8 these days, but I found that there is too little information on the Internet, so here I sorted out some knowledge after answering some questions about stm8, which can be regarded as a small summary
For development environment, there are three commonly used ones: ST TOOLSET, COSMIC and IAR. Because I have used IAR to develop stm32, IAR is my first choice, although many people on the Internet say that the optimization of IAR for STM8 code is not as good as COSMIC.
After looking at the configuration of the development environment, it is not very complicated. I will post the configuration methods of these three tools for beginners to download and view:
http://download.csdn.net/detail/hzt12345hf/7666017
Let me talk about the precautions for using IAR. I won’t talk about the basic configuration environment.
The header file names used by iar and cosmic are different. iar uses the same format as "iostm8s103k3.h".
Regarding how to use interrupt vectors, the format of declaring an interrupt program is as follows:
#pragma vector=0x02
__interrupt void interrupt_handler(void)
{
//Your code
}
#pragma vector =0x02:
The number before the equal sign is the IAR interrupt vector instruction, and the number after the equal sign represents the interrupt vector number. The interrupt vector number can be calculated by yourself or found in your header file. It is basically placed at the bottom of the header file, about 4000 lines. If you calculate it yourself, it is (interrupt vector address - 0x0008000)/4, which is the interrupt vector number.
Since I came from the 51 MCU, I don't like the library functions of stm32/8 very much, because people who understand it can know what it is at a glance, but it is really troublesome for people who don't understand it. Although it is very common, it reduces readability (personal feeling), so I decisively gave up the library functions of stm8 and wrote registers like 51.
Of course, in 51, setting an IO port to 1 is a high level, and setting it to 0 is a low level, so I am also curious whether STM8 has this function. Due to too little information, I have searched for a long time but couldn't find it. It was still a friend of Amo Electronics who said it, that is, to use a macro definition like PC_ODR_ODR0, which is defined in the header file as follows:
This is just like using structures in stm32. By converting addresses into structures, registers can be accessed by accessing variables in the structure. Here are a few websites for you to discuss using bit control in stm8. There are other ways, and which method is more suitable for customization. Common access is used:
http://www.amobbs.com/forum.php?mod=viewthread&tid=5588812&pid=7705619&page=1&extra=page%3D1#pid7705619
http://bbs.21ic.com/icview-556542-1-1.html
Let's talk about the timer. Since I have just unlocked stm8, there are many things I don't understand thoroughly, simply because the timer function of stm8 is too powerful.
The simplest timer initialization routine is basically as follows:
void Init_TIM1(void)
{
TIM1_CR1 = 0x00; //Upward counting direction, interrupt counting continues
TIM1_IER = 0x01; //Enable update interrupt
TIM1_PSCRH = 0x3e; //Divide by 16000
TIM1_PSCRL = 0x80;
TIM1_ARRH = 0x03; //Generate an update interrupt every 1000 cycles 16 / 16000 * 1000 = 1
TIM1_ARRL = 0xe8;
TIM1_CR1 |=0x01; //Enable interrupt
}
First, enable the first bit of TIMx_IER so that the timer can generate an interrupt, set the counting direction at the same time, and then set the timer's divider. The frequency is the frequency of the main clock/the frequency division number. The 16-bit advanced timer uses TIMx_PSCRH and TIMx_PSCRL to jointly determine the frequency division number. The 16-bit general timer uses the first 4 bits of TIMx_PSCR as a power of 2, and the main clock frequency/2^TIMx_PSCR is used to calculate the frequency. The 8-bit basic timer is similar to the 16-bit general timer, except that the first 3 bits of TIMx_PSCR are used. Then set the overflow value. Both the 16-bit general and 16-bit advanced timers have two registers, TIMx_ARRH and TIMx_ARRL, to record the overflow value. In addition, the assignment must be assigned to TIMx_ARRH first and then to TIMx_ARRL, otherwise the count value cannot be automatically reloaded. Then enable the interrupt.
The most important point, and the one that is most easily forgotten, is to enable the total interrupt. The statement is assembly language:
asm("rim");/* enable interrupts */
The total interrupt is turned off
asm("sim");/* disable interrupts */
I also found a problem. For microcontrollers such as STM8s003k3, there is no TIM4_SR1 register in its header file, but TIM4_SR. Therefore, if you want to clear the interrupt flag of TIM4, you need to use TIM4_SR = 0x00 to implement it.
That's all for now, there will be more to come. Here are some materials for you to download:
Key points for using STM8 TIM timer: http://download.csdn.net/detail/hzt12345hf/7666019
STM8 Chinese DATASHEET: http://download.csdn.net/detail/hzt12345hf/7666021
STM8 C language programming: http://download.csdn.net/detail/hzt12345hf/7666025
stm8 sample program: http://download.csdn.net/detail/hzt12345hf/7666027
Previous article:Simple transplantation of printf function of msp430
Next article:IAR debugging stm8 optimization settings
Recommended ReadingLatest update time:2024-11-16 13:23
- Popular Resources
- Popular amplifiers
- IAR fully supports the new industrial-grade PX5 real-time operating system
- 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
- ARM Cortex-M4+Wi-Fi MCU Application Guide (Embedded Technology and Application Series) (Guo Shujun)
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
- ST programmable sensor + FSM on Unico
- Digital Circuits and Digital Systems: Experiments and Course Design Training Course
- AT91SAM7S256 serial port data loss
- Using DSP motor speed measurement and detailed explanation
- Low-power Qorvo chips enhance connectivity and reliability for new Luna smart home system
- Highlights of Bluetooth Mesh Technology
- ST NUCLEO-G071RB evaluation serial port printing and LED flashing
- Network port problem
- What is an ISO Connector?
- B-L4S5I-IOT01A development board has WIFI, Bluetooth, NFC, microphone, distance measurement, magnetometer, thermometer and hygrometer.