Why does the STM8L external interrupt operate in an endless loop?

Publisher:JoyfulSunflowerLatest update time:2016-05-12 Source: eefocusKeywords:STM8L Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
  The STM8L series MCU is a low-power MCU launched by ST. Compared with the STM8S series, the power consumption is much lower, but the internal structure is also much reduced. Be sure to read the manual carefully when using it. This is the first time I use STM8. Since the functions are not very complicated, I did not want to study the library functions. I was ready to directly control the register operation. I didn't expect that I would be entangled in the interrupt problem for most of the day.

This is very different in external interrupts. STM8S automatically clears external interrupts, while STM8L requires software to clear them. The register that clears the flag bit varies depending on the setting, as explained below.

 

The following takes the STM8L external interrupt PB1 as an example to illustrate the operation of the external interrupt register

There are several steps to set up external interrupts:

The first step is to set the IO port as interrupt input by setting (PB_DDR = 0X00; PB_CR1 = 0X02; PB_CR2 = 0X02;)

Step 2: Set the interrupt trigger mode (00: Falling edge and low level; 01: Rising edge only; 10: Falling edge only; 11: Rising and falling edge)

Step 3: Change the interrupt vector table (in the stm8_interrupt_vector.c file)

Step 4: Write an interrupt handling function and remember to clear the interrupt in the function

 


 

 Step 1: Set the IO port as interrupt input

   PB_DDR = 0X00; // Input

 PB_CR1 = 0X02; // 0_0010  

 PB_CR2 = 0X02; // 0_0010 CR1 and CR2 are combined to determine the pull-up external interrupt input

Step 2: Set the interrupt trigger mode. The PB and PD ports in STM8L are special and can have two trigger modes.

 EXTI_CONF = 0x00;

  These two trigger modes are set through the register EXTI_CONF 

  The first method is the same as port A and C. The trigger mode is set by the following two registers. Set register EXTI_CONF[0] to 0, indicating that port B[3:0] uses the first method (which I call the normal method here).

  EXTI_CR1 register sets the 3, 2, 1, 0 pins of Port A, B, C and/or D external interrupts

  EXTI_CR2 register sets the 7, 6, 5, 4 pins of Port A, B, C and/or D external interrupts

  The second method is to set the trigger mode EXTI_CONF[0] to 1 through the EXTI_CR3 register, indicating that Port B[3:0] uses the second method (I named it the special method here)

  Bits [3:2] of the EXTI_CR3 register set the trigger mode of port D. 

  Bits [1:0] of the EXTI_CR3 register set the trigger mode of port B.

Step 3: Change the interrupt vector table 

  {0x82, KEY_Interrupt}, /* irq9 */

  The PB1 normal mode interrupt vector number is 9, where KEY_Interrupt can be named according to actual needs as long as it is consistent with the interrupt function name written later.

  Why choose 9? Look at the picture below to know.

Step 4: Write an interrupt handling function

  @far @interrupt void KEY_Interrupt(void)
  {
    LED1 = !LED1;
    //EXTI_SR2 = 0x01; // If set to special mode, clear the interrupt flag through this register
    EXTI_SR1 =0x02; // If set to normal mode, clear the interrupt flag through this register

  } 

There are two points to note in this step:

1. If the interrupt execution function does not want to be written in the stm8_interrupt_vector.c file, you need to add such a function in the stm8_interrupt_vector.c file

  @far @interrupt void KEY_Interrupt(void);

2. EXTI_SR2 = 0x01; // If set to special mode, clear the interrupt flag through this register
  EXTI_SR1 = 0x02; // If set to normal mode, clear the interrupt flag through this register


 

Interrupt vector level: 

From the first table below, we can see that if we use normal interrupt mode, the interrupt of port B1 belongs to EXTI1 (if it is PB2, it belongs to EXTI2), and the interrupt of special mode port B belongs to EXTIB and EXTID,

 

Why does the STM8L external interrupt operate in an endless loop?

 

After knowing this, we can combine it with the interrupt vector table in the manual to know where we should write the interrupt entry function name.

 Why does the STM8L external interrupt operate in an endless loop?

Why does the STM8L external interrupt operate in an endless loop?

Why does the STM8L external interrupt operate in an endless loop?

 

Keywords:STM8L Reference address:Why does the STM8L external interrupt operate in an endless loop?

Previous article:Microcontroller learning notes external interrupt, timer, serial port interrupt
Next article:STC11F04 MCU timer simulation multi-tasking program

Recommended ReadingLatest update time:2024-11-16 22:24

Notes on STM8S and STM8L debugging serial port interrupts
Note on STM8L serial port interruption  When debugging the PM2.5 sensor GP2Y1051, it is found that data can be received at the beginning of simulation, but if it is paused, it cannot receive data. In fact, it only receives complete data once. Solution if(USART_GetITStatus(USART1, USART_IT_RXNE)) { RecevieData = 
[Microcontroller]
STM8L TAB segment LCD driver
Introduction: The STM8L152XX series has an on-chip segment LCD driver, which provides a guarantee for low-cost applications and high-density system design. The on-chip LCD driver module can effectively control the overall power consumption of the system, simplify the system structure, and improve the overall reliabili
[Microcontroller]
Record a stm8l program running out of control
The project uses stm8l051f3 as the master control and CC2500 for data reception, not sending. The phenomenon of running away is that it can run at the beginning, but after a period of unknown length of time, which may be 3 minutes or 30 minutes, the indicator light no longer flashes and the interrupt button microcon
[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号