iar for stm8 beginner summary

Publisher:温暖梦想Latest update time:2018-05-31 Source: eefocusKeywords:iar  stm8 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

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:


  1. #pragma vector=0x02  

  2. __interrupt void interrupt_handler(void)  

  3. {  

  4.     //Your code  

  5. }  



#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:


  1. void Init_TIM1(void)  

  2. {  

  3.       

  4.       

  5.     TIM1_CR1 = 0x00; //Upward counting direction, interrupt counting continues  

  6.     TIM1_IER = 0x01; //Enable update interrupt  

  7.     TIM1_PSCRH = 0x3e; //Divide by 16000  

  8.     TIM1_PSCRL = 0x80;  

  9.     TIM1_ARRH = 0x03; //Generate an update interrupt every 1000 cycles 16 / 16000 * 1000 = 1  

  10.     TIM1_ARRL = 0xe8;  

  11.   

  12.   

  13.     TIM1_CR1 |=0x01; //Enable interrupt  

  14.       

  15. }  


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:


  1. asm("rim");/* enable interrupts */  


The total interrupt is turned off


  1. 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


Keywords:iar  stm8 Reference address:iar for stm8 beginner summary

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

stm8 RTC automatic wake-up
After two days of exploration, I finally got the RCT automatic wakeup of stm8l05b13 working. There are libraries and registers to implement it. Let me share it with you. Here I will only talk about the function. You can read the manual for the principle. Without further ado, here is the program. RTC initialization.  
[Microcontroller]
The difference between PWM1 and PWM2 in STM8
The PWM1 and PWM2 modes in STM8 are mandatory parameters for clock output PWM waveform control. The prototype of the library function is as follows: void TIMx_OC2Init(TIM2_OCMode_TypeDef TIM2_OCMode,                   TIM2_OutputState_TypeDef TIM2_OutputState,                   uint16_t TIM2_Pulse,                  
[Microcontroller]
STM8 low power consumption problem
I encountered a problem when using STM8S003: In order to reduce the power consumption of MCU, the Schmitt trigger was disabled during initialization. It was found that IO- PD3 was always 0 as the input register IDR. So I looked up information and found that the Schmitt trigger must be turned on when the IO port is us
[Microcontroller]
STM8 low power consumption problem
IAR for AVR_Proteus—Joint Modulation
1) First of all, IAR for AVR can generate many types of files. However, in the case we encountered, only the following setting can make the generated file get perfect simulation effect on PROTEUS. The following figure shows the detailed setting method: Two points to note: a. (Please note that if the suffix of its
[Microcontroller]
IAR for AVR_Proteus—Joint Modulation
STM8 PWM routines
In single-chip microcomputer application systems, PWM signal output is often used, such as motor speed control. They are also integrated with PWM function modules to facilitate user applications.       For PWM signals, there are two main concepts involved, one is the period or frequency of the PWM signal, and the oth
[Microcontroller]
Explanation of IdMask mode of STM8 CAN bus
Preface In the CAN protocol, the identifier of the message does not represent the address of the node, but is related to the content of the message. Therefore, the sender sends the message to all receivers in the form of broadcast. When receiving the message, the node determines whether the software needs the message
[Microcontroller]
Explanation of IdMask mode of STM8 CAN bus
IAR FOR STM8 Simple Tutorial
1. Create a project 1. Create a workplace first. Select File New Workplace 2. Create a new project, select Project Create New Project, if you are using IAR FOR STM8, there is no need to change the default. Save and enter the Project name, the following is displayed in the workplace window 3. Before adding files t
[Microcontroller]
IAR FOR STM8 Simple Tutorial
IAR compiles STM8S pin operation to modify the library function
IAR compiles the built-in library functions of STM8S. We all know that there is a definition of each IO port as follows: typedef enum {  GPIO_PIN_0 = ((u8)0x01), /*! Pin 0 selected */  GPIO_PIN_1 = ((u8)0x02), /*! Pin 1 selected */  GPIO_PIN_2 = ((u8)0x04), /*! Pin 2 selected */  GPIO_PIN_3 = ((u8)0x08), /*! Pin 3
[Microcontroller]
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号