Steps and methods for implementing external interrupts in STM32 microcontroller

Let's start with the simplest problem, using the STM32 external interrupt method to realize the PB.0 button to control the PA.0 LED light:

First, let's talk about the steps to achieve interrupt:

1. Configure the NVIC register (function), set the interrupt to which group, the first priority and the second priority;

Function method:

void NVIC_ConfiguraTIon()

{

NVIC_InitTypeDef NVIC_InitStruct;

NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);

NVIC_InitStruct.NVIC_IRQChannel=EXTI0_IRQn;

NVIC_InitStruct.NVIC_IRQChannelPreempTIonPriority=0;

NVIC_InitStruct.NVIC_IRQChannelSubPriority=1;

NVIC_InitStruct.NVIC_IRQChannelCmd=ENABLE;

NVIC_Init(&NVIC_InitStruct);

}

The above are the general steps to configure the priority: set the priority group, set the interrupt channel, set the first priority, the second priority, enable, etc.;

Steps and methods for implementing external interrupts in STM32 microcontroller

2. Configure the EXTI register and (function), set the interrupt line, interrupt mode, etc.;

voidEXTI_Configuration()

{

EXTI_InitTypeDefEXTI_InitStructure;

EXTI_ClearITPendingBit(EXTI_Line0);

GPIO_EXTILineConfig(GPIO_PortSourceGPIOB, GPIO_PinSource0);

EXTI_InitStructure.EXTI_Line=EXTI_Line0;

EXTI_InitStructure.EXTI_Mode=EXTI_Mode_Interrupt;

EXTI_InitStructure.EXTI_Trigger=EXTI_Trigger_Falling;

EXTI_InitStructure.EXTI_LineCmd=ENABLE;

EXTI_Init(&EXTI_InitStructure);

}

Like configuring NVIC, this is also the general step of EXTI configuration: clear the corresponding interrupt line flag (this is very important, I have not found this problem at the beginning), connect the port and the interrupt line (it can also be configured during GPIO initialization), Select the interrupt line, set the interrupt mode, interrupt mode, enable, etc.;

3, write interrupt service function

The interrupt service routine is generally written in the STM32F10X_it.c file:

voidEXTI0_IRQHandler(void)

{

if(EXTI_GetITStatus(EXTI_Line0)==SET)

{

EXTI_ClearITPendingBit(EXTI_Line0);

if(GPIO_ReadOutputDataBit(GPIOA,GPIO_Pin_0)==Bit_RESET)

{

GPIO_SetBits(GPIOA, GPIO_Pin_0);

}

else

{

GPIO_ResetBits(GPIOA, GPIO_Pin_0);

}

}

}

The most important point: need to pay attention to clear the interrupt flag after entering the service routine;

A few things that are easy to ignore:

1. The interrupt service routine must clear the interrupt flag bit;

2. Connect the corresponding port and interrupt line;

3. The key port is set to pull-up input;

4. Clear the interrupt flag when configuring EXTI;

The short circuit of the button part is connected by itself:

Here's how to manipulate registers directly:

1. GPIO initialization: here, just pay attention to setting GPIOB.0 as a pull-up input (not only to set GPIOB->CRL=0X08, but also to set GPIOB->ODR=0X01, in order to distinguish it from the pull-down)

voidGPIO_Config()

{

GPIOA->CRL=0X03;

GPIOA->ODR=0X01;

GPIOB->CRL=0X08;

GPIOB->ODR=0X01;

}

2. NVIC initialization:

Go directly to the code:

voidNVIC_Configuration()

{

u32temp;

temp=SCB->AIRCR;

temp&=0x0000f8ff;

temp|=0x05fa0000;

temp|=0x0700;

SCB->AIRCR=temp;

NVIC-"ISER[0]=1""6;

NVIC->IP[1]=0;

}

3. EXTI initialization

Similar to using the function method, set several registers; what I don't understand is that it seems that there is no need to clear the flag bit here;

voidEXTI_Configuration()

{

AFIO->EXTICR[0]=0X0001;

EXTI-"IMR=0X01;

EXTI->RTSR=0X01;

}

Then the interrupt service routine:

voidEXTI0_IRQHandler(void)

{

if(EXTI_GetITStatus(EXTI_Line0)==SET)

{

EXTI-"PR=0X01;

if(GPIO_ReadOutputDataBit(GPIOA,GPIO_Pin_0)==Bit_RESET)

{

GPIO_SetBits(GPIOA, GPIO_Pin_0);

}

else

{

GPIO_ResetBits(GPIOA, GPIO_Pin_0);

}

}

}

Here is the entire code with the function:

#include "stm32f10x.h"

voidGPIO_Config();

voidNVIC_Configuration();

voidEXTI_Configuration();

voidSysclkConfiguration();

intmain()

{

SysclkConfiguration();

GPIO_Config();

EXTI_Configuration();

NVIC_Configuration();

while(1);

return0;

}

voidSysclkConfiguration()

{

RCC_DeInit();

RCC_HSEConfig(RCC_HSE_ON);

if(RCC_WaitForHSEStartUp()==SUCCESS)

{

RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9);

RCC_PLLCmd(ENABLE);

while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY)==RESET);

RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);

while(RCC_GetSYSCLKSource() != 0X08);

RCC_HCLKConfig(RCC_SYSCLK_Div1);

RCC_PCLK1Config(RCC_HCLK_Div2);

RCC_PCLK2Config(RCC_HCLK_Div1);

RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOB|RCC_APB2Periph_AFIO, ENABLE);

}

}

voidGPIO_Config()

{

GPIO_InitTypeDefGPIO_InitStructure;

GPIO_InitStructure.GPIO_Pin=GPIO_Pin_0;

GPIO_InitStructure.GPIO_Speed=GPIO_Speed_10MHz;

GPIO

LiFePO4 Battery Pack

LiFePO4 Battery Pack

We have come up with the LiFePO4 battery pack for telecom towers successfully. This LiFePO4 battery is a modular design, it is lightweight and compact in size making it suitable for limited space. It is designed with excellent safety features, a long lifespan, better energy density with flexible expandability in parallel to achieve higher storage capacity needs.
Each LiFePO4 battery module for telecom towers is equipped with a UFO independent BMS ( Battery Management System), providing you confidence in monitoring battery performance and health. Besides, it is equipped with GPRS function, so batteries can be monitored remotely through an online way.

When providing power for cell towers, system reliability is critical. In remote areas, maintenance and transport costs of traditional batteries will increase the telecom tower`s cost. Therefore, battery choice is the critical decision to control the costs. This is why we design this UFO LiFePO4 battery pack for telecom towers. This Lithium Battery for telecom towers will help you save costs.


6 100ah 2 Lifepo4 Battery Cropped


Feature of Rack Mount LiFePO4 Battery for Telecom Towers

● Safe LiFePO4 Battery Cells
● Modular Design for Limited Space
● GPRS for Battery Remote Monitoring
● Communication Function
● Flexible capacity scalability

Protection of Rack Mount LiFePO4 Battery for Telecom Towers

● Over charge/ discharge Protection
● Over current Protection
● Over voltage Protection
● Over temperature Protection
● Short Circuit Protection

Lifepo4 Battery Pack,Lifepo4 Ebike Battery,Lifep04 Battery Pack,Lithium Phosphate Battery

ShenZhen UFO Power Technology Co., Ltd. , https://www.ufobattery.com