Use and precautions of external interrupts in STM8L firmware library

Publisher:SereneSerenityLatest update time:2019-12-23 Source: eefocusKeywords:STM8L Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

1. Initialization function


GPIO_Init(GPIOB, GPIO_Pin_3, GPIO_Mode_In_FL_IT);

EXTI_SetPinSensitivity(GPIO_Pin_3, EXTI_Trigger_Falling); //Error, will be explained below


2. Interrupt function


INTERRUPT_HANDLER(EXTI3_IRQHandler,11)

{


EXTI_ClearITPendingBit(EXTI_IT_Pin3);


//


}


3. Questions and explanations


I won't go into details about the specific use of the function, which can be found in the firmware library and manual. When testing, I found that when the signal input is a falling edge and remains at a low level, it will trigger repeatedly, which seems to be configured as a falling edge and low level trigger mode. I debugged for a long time but couldn't find the problem. Finally, I looked at the library function again and found the correct configuration is


EXTI_SetPinSensitivity(EXTI_Pin_3, EXTI_Trigger_Falling);


At first I also noticed that EXTI_Pin_3 should be used instead of GPIO_Pin_3, but based on my experience in programming AVR, I thought that these two macros were both defined as 3, and if they were not 3, they should be the same, so I didn't think much about it.


Open the corresponding header file and look at these two macro definitions


  GPIO_Pin_0    = ((uint8_t)0x01),   /*!< Pin 0 selected */

  GPIO_Pin_1    = ((uint8_t)0x02),   /*!< Pin 1 selected */

  GPIO_Pin_2    = ((uint8_t)0x04),   /*!< Pin 2 selected */

  GPIO_Pin_3    = ((uint8_t)0x08),   /*!< Pin 3 selected */

  GPIO_Pin_4    = ((uint8_t)0x10),   /*!< Pin 4 selected */

  GPIO_Pin_5    = ((uint8_t)0x20),   /*!< Pin 5 selected */

  GPIO_Pin_6    = ((uint8_t)0x40),   /*!< Pin 6 selected */

  GPIO_Pin_7    = ((uint8_t)0x80),   /*!< Pin 7 selected */




  EXTI_Pin_0 = (uint8_t)0x00, /*!< GPIO Pin 0 */

  EXTI_Pin_1 = (uint8_t)0x02, /*!< GPIO Pin 1 */

  EXTI_Pin_2 = (uint8_t)0x04, /*!< GPIO Pin 2 */

  EXTI_Pin_3 = (uint8_t)0x06, /*!< GPIO Pin 3 */

  EXTI_Pin_4 = (uint8_t)0x10, /*!< GPIO Pin 4 */

  EXTI_Pin_5 = (uint8_t)0x12, /*!< GPIO Pin 5 */

  EXTI_Pin_6 = (uint8_t)0x14, /*!< GPIO Pin 6 */

  EXTI_Pin_7 = (uint8_t)0x16 /*!< GPIO Pin 7 */


You can see that they are not the same.


Looking at the manual again, the interrupt is configured as falling edge and low level trigger mode by default.


summary:


Using library functions is certainly convenient and quick, but sometimes you can't be too quick on the slack. If you encounter a problem, you should carefully read the library functions and manuals.


Keywords:STM8L Reference address:Use and precautions of external interrupts in STM8L firmware library

Previous article:STM8L052R8 big and small end test
Next article:STM8 low power design

Recommended ReadingLatest update time:2024-11-16 13:00

STM8L serial communication baud rate is abnormal
The baud rate of the serial port configuration 2400/9600/57600/115200 is abnormal When using 16M clock, 2400 and 115200 are abnormal and garbled, but the frequency in between is good; modify the clock to adapt to different clock frequencies. . . ;Looking at the register configuration, there is no problem at all. A
[Microcontroller]
STM8L Discovery Kit Study Notes-CLK Clock Control (IV)
STM8L inherits the clock architecture of STM32, which is divided into four types of clocks: HSI (high-speed internal RC 16M), HSE (high-speed external 1-16M), LSI (low-speed internal 38K), LSE (low-speed external 32768). It does not have a PLL multiplier, and also uses the clock switch of the control peripherals to red
[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号