IAR+STM8_EXTI external IO interrupt

Publisher:ohp991养生的香菇Latest update time:2021-10-14 Source: eefocusKeywords:IAR Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

MCU: STM8S207SB

IO port to be operated: PD7 uses falling edge to trigger interrupt


Code:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
twenty one
twenty two
twenty three
twenty four
25
26
27
28
29
30
31
32
33
34
35
36
#include
 
#define LED1_FLASH PD_ODR_ODR3 = !PD_ODR_ODR3 // LED1 on the development board is connected to PD3
 
void GPIO_init(void)
{
PD_DDR = 0x08; // Configure the direction register PD3 output of the PD port
PD_CR1 = 0x08; // Set PD3 to push-pull output
PD_CR2 = 0x80; // Enable PD7 external interrupt
}
 
void EXTI_init(void)
{
EXTI_CR1 = 0x80; // PD port falling edge triggers interrupt
}
 
#pragma vector=0x02 // This is critical! See the following instructions.
__interrupt void EXTI_PD7_TLI(void)
{
LED1_FLASH;
}
void init_devices(void)
{
asm("sim"); // Turn off global interrupts
GPIO_init();
EXTI_init();
asm("rim"); // Enable global interrupt
}
 
void main( void )
{
init_devices();
 
// There is no program to execute in the main loop
while(1);

}


One important point to note here is the external interrupt program of PD7. I looked at the chip manual and found that the interrupt vector number of the PD port external interrupt EXTI3 is 6. Of course, according to IAR rules, the interrupt vector should be added by 2, so I wrote #pragma vector=0x08. As a result, when I pressed the button, the program did not respond and kept interrupting. Next, I had to find another way. After carefully reading the information, I found that PD7 is different from other PD ports. PD7 has a small tail TLI behind it. Looking at the TLI description in the manual, wow, TLI has the highest level of interrupt on the chip and has an independent and dedicated interrupt vector number 0. This is easy to deal with. According to IAR rules, the interrupt vector number in the chip manual + 2 = IAR interrupt vector number. The program was changed to #pragma vector=0x02. I compiled, downloaded, and ran it again, and the button finally obeyed.

Keywords:IAR Reference address:IAR+STM8_EXTI external IO interrupt

Previous article:STM8 uses TIM1 to measure PWM wave
Next article:stm8 pwm implementation core code

Recommended ReadingLatest update time:2024-11-15 08:50

STM8's TIM4 timer 1ms enters interrupt
TIM4 — 8-bit basic timer ● 8-bit auto-load adjustable prescaler, the ratio can be selected as any power of 2 between 1 and 128 ● Clock source: CPU clock ● Interrupt source: 1 overflow/update interrupt It is necessary to implement an interrupt once every 1ms, which can be used as a system timer TIM4 initialization
[Microcontroller]
STM8 "line inversion" scan matrix keyboard
The wiring diagram of the line reversal method is as follows. The principle is simply as follows: The four row pins push-pull to output low level (set to 0), and the four column pins pull-up to input. If a key is pressed, the row and column will be connected, causing the voltage of a column pin to be pulled down,
[Microcontroller]
STM8
IAR+STM8_EXTI external IO interrupt
MCU: STM8S207SB IO port to be operated: PD7 uses falling edge to trigger interrupt Code: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 twenty one twenty two twenty three twenty four 25 26 27 28 29 30 31 32 33 34 35 36 #include iostm8s207sb.h   #define LED1_FLASH PD_ODR_ODR3 = !PD_ODR_ODR3 // LED1 on the d
[Microcontroller]
Stm8 serial port redirection and problem solving
1. Code and its settings #include stdio.h int fputc(int ch, FILE *f) //Stm8005 redirection {    while (!(UART2- SR&0x80));    UART2- DR=ch;   return ch;  }  At the same time, you need to change the Library item in IAR's Project- Options- General Options- Library Configuration from "Normal" to "Full". 2. Problem S
[Microcontroller]
Stm8 serial port redirection and problem solving
The pitfalls of stm8
Some pins of stm8 are truly open-drain and must be connected to external pull-up resistors, otherwise they cannot be pulled high. This is different from stm32. For example, the stm8al3188 pc0 pin has no internal pull-up.
[Microcontroller]
STM8 Assembly Learning Notes 2: Development Environment
Preface As far as I know, there are two development platforms for STM8: STVD from ST and IAR for STM8. I haven't tried STVD. Anyway, IAR feels OK, and it has all the necessary functions, but the interface is not very user-friendly. I guess it's because of the low version. Since my eyes hurt from staring at the screen
[Microcontroller]
STM8 Assembly Learning Notes 2: Development Environment
STM8 master clock switching
The clock switching function provides STM8 users with an easy-to-use, fast and safe way to switch from one clock source to another. System Startup To enable the STM8 system to start quickly, the clock controller automatically uses HSI divided by 8 (HSI/8) as the main clock after reset. The reason is that HSI has a s
[Microcontroller]
STM8 master clock switching
STM8 study notes---create a new IAR project file
1. Open IAR tool 2. Select Project—Create New Project 3. Select Empty project and click OK. 4. Select the file storage path, enter the project name, and click the Save button. 5Click the New File button in the upper left corner At this time, a new file will appear on the right. The new file is a text file an
[Microcontroller]
STM8 study notes---create a new IAR project file
Latest Microcontroller Articles
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号