2020-06-22 03:07 AM
#include "stm32f10x.h"
void EXTI3_IRQ_IRQHandler(void)
{
if(EXTI->PR & EXTI_PR_PR3)
{
EXTI->PR |= EXTI_PR_PR3;
GPIOA-> BRR |= GPIO_BRR_BS1;
}
}
int main(void)
{
RCC ->APB2ENR |= RCC_APB2ENR_IOPAEN; //LED(OUTPUT PIN)(PA1)
GPIOA->CRL &= ~(GPIO_CRL_CNF1);
GPIOA->CRL |= GPIO_CRL_MODE1_0;
GPIOA->CRL &= ~(GPIO_CRL_MODE1_1);
RCC ->APB2ENR |= RCC_APB2ENR_IOPBEN; //PUSH BUTTON(INPUT PIN)(PB3)
GPIOB->CRL |= GPIO_CRL_CNF3_0;
GPIOB->CRL &= ~(GPIO_CRL_CNF3_1);
GPIOB->CRL &= ~(GPIO_CRL_MODE3);
RCC ->APB2ENR |= RCC_APB2ENR_AFIOEN; //FOR ALTERNATE FUNCTION
EXTI->IMR |= EXTI_IMR_MR3; //INTERRUPT MASK REGISTER(0:MASKING, 1:NON-MASKING)
EXTI->RTSR |= EXTI_RTSR_TR3; // RISING EDGE TRIGGERED INTERRUPT
AFIO->EXTICR[0] = AFIO_EXTICR1_EXTI3_PB;
NVIC_EnableIRQ(EXTI3_IRQn);
NVIC_SetPriority(EXTI3_IRQn,0);
while(1)
{
GPIOA-> BSRR |= GPIO_BSRR_BR1;
}
}
Solved! Go to Solution.
2020-06-23 07:03 AM
Thanks, i detected the glitch/error, and you are right: i had to only add a delay (not a breakpoint exactly, but a delay function) before the line: GPIOA-> BSRR |= GPIO_BSRR_BR1; in the while loop because the interrupt handler function returns to the while loop after handling the interrupt so maybe my code looks like this:
void EXTI3_IRQHandler(void)
{
if(EXTI->PR & EXTI_PR_PR3)
{
EXTI->PR |= EXTI_PR_PR3;
GPIOA-> BRR |= GPIO_BRR_BS1;
}
}
int main(void)
{
RCC ->APB2ENR |= RCC_APB2ENR_IOPAEN; //LED(OUTPUT PIN)(PA1)
GPIOA->CRL &= ~(GPIO_CRL_CNF1);
GPIOA->CRL |= GPIO_CRL_MODE1_0;
GPIOA->CRL &= ~(GPIO_CRL_MODE1_1);
RCC ->APB2ENR |= RCC_APB2ENR_IOPBEN; //PUSH BUTTON(INPUT PIN)(PB3)
GPIOB->CRL |= GPIO_CRL_CNF3_0;
GPIOB->CRL &= ~(GPIO_CRL_CNF3_1);
GPIOB->CRL &= ~(GPIO_CRL_MODE3);
RCC ->APB2ENR |= RCC_APB2ENR_AFIOEN; //FOR ALTERNATE FUNCTION
EXTI->IMR |= EXTI_IMR_MR3; //INTERRUPT MASK REGISTER(0:MASKING, 1:NON-MASKING)
EXTI->RTSR |= EXTI_RTSR_TR3; // RISING EDGE TRIGGERED INTERRUPT
AFIO->EXTICR[0] = AFIO_EXTICR1_EXTI3_PB; //ALTERNATE FUNCTION CONFIGURATION FOR-PB3)
NVIC_EnableIRQ(EXTI3_IRQn);
NVIC_SetPriority(EXTI3_IRQn,0);
while(1)
{
for(volatile int i=0; i<=10000000; i++);
GPIOA-> BSRR |= GPIO_BSRR_BR1;
}
}
2020-06-22 04:44 AM
Put a breakpoint in EXTI3_IRQ_IRQHandler and see if it's getting there.
Could be that the LED lights up for only a few clock cycles and your eye can't see it.
2020-06-22 07:23 AM
I'm using STM32F10x_StdPeriph_Lib_V3.5.0 and the programme becomes more readable.
/**
* @brief Configure the EXTI 4.
* The external signal is connected to EXTI4 pin (PB.4)
* The Rising edge is used as active edge
* @param None
* @retval None
*/
void EXTI4_Configuration() {
EXTI_InitTypeDef EXTI_InitStructure;
//select EXTI line4
EXTI_InitStructure.EXTI_Line = EXTI_Line4;
//select interrupt mode
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
//generate interrupt on rising edge
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
//enable EXTI line
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
//send values to registers
EXTI_Init(&EXTI_InitStructure);
}
/**
* @brief This function calculates left motor speed.
* @param None
* @retval None
*/
void EXTI4_IRQHandler(void) {
short ms;
__IO short h;
//Check if EXTI_Line4 is asserted
if(EXTI_GetITStatus(EXTI_Line4) == SET) {
//we need to clear line pending bit manually
EXTI_ClearITPendingBit(EXTI_Line4);
....
}
In main:
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_StructInit (& GPIO_InitStructure);
// EXTI4 configuration
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_EXTILineConfig(GPIO_PortSourceGPIOB, GPIO_PinSource4);
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4);
// Enable the EXTI4 Interrupt
NVIC_InitStructure.NVIC_IRQChannel = EXTI4_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 7;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
2020-06-23 07:03 AM
Thanks, i detected the glitch/error, and you are right: i had to only add a delay (not a breakpoint exactly, but a delay function) before the line: GPIOA-> BSRR |= GPIO_BSRR_BR1; in the while loop because the interrupt handler function returns to the while loop after handling the interrupt so maybe my code looks like this:
void EXTI3_IRQHandler(void)
{
if(EXTI->PR & EXTI_PR_PR3)
{
EXTI->PR |= EXTI_PR_PR3;
GPIOA-> BRR |= GPIO_BRR_BS1;
}
}
int main(void)
{
RCC ->APB2ENR |= RCC_APB2ENR_IOPAEN; //LED(OUTPUT PIN)(PA1)
GPIOA->CRL &= ~(GPIO_CRL_CNF1);
GPIOA->CRL |= GPIO_CRL_MODE1_0;
GPIOA->CRL &= ~(GPIO_CRL_MODE1_1);
RCC ->APB2ENR |= RCC_APB2ENR_IOPBEN; //PUSH BUTTON(INPUT PIN)(PB3)
GPIOB->CRL |= GPIO_CRL_CNF3_0;
GPIOB->CRL &= ~(GPIO_CRL_CNF3_1);
GPIOB->CRL &= ~(GPIO_CRL_MODE3);
RCC ->APB2ENR |= RCC_APB2ENR_AFIOEN; //FOR ALTERNATE FUNCTION
EXTI->IMR |= EXTI_IMR_MR3; //INTERRUPT MASK REGISTER(0:MASKING, 1:NON-MASKING)
EXTI->RTSR |= EXTI_RTSR_TR3; // RISING EDGE TRIGGERED INTERRUPT
AFIO->EXTICR[0] = AFIO_EXTICR1_EXTI3_PB; //ALTERNATE FUNCTION CONFIGURATION FOR-PB3)
NVIC_EnableIRQ(EXTI3_IRQn);
NVIC_SetPriority(EXTI3_IRQn,0);
while(1)
{
for(volatile int i=0; i<=10000000; i++);
GPIOA-> BSRR |= GPIO_BSRR_BR1;
}
}