Problem in external interrupt on PORTB
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2017-11-06 9:31 PM
I am using STM32F0308 Dicovery Board. I want to use external interrupt on PIN11 of PORTB. Problem is that I am not able to invoke the PORTB. Microcontroller is still uses PIN11 of PORTA. I know that pins of ports are clubbed together but I am specifying PORTB still micro is using PORTA.
I think there is some problem in this code line
SYSCFG->EXTICR[3] = SYSCFG_EXTICR3_EXTI11_PB;
Here is code
#include'stm32f0xx.h'
volatile int portBPin10Counter;
void EXTI4_15_IRQHandler(void)
{
if(EXTI->PR & EXTI_PR_PR11)
{
EXTI->PR |= EXTI_PR_PR11;
portBPin10Counter++;
}
}
int main(void)
{
RCC->AHBENR |=RCC_AHBENR_GPIOBEN;
GPIOB->MODER &= ~GPIO_MODER_MODER11;
GPIOB->PUPDR &= ~GPIO_PUPDR_PUPDR11;
SYSCFG->EXTICR[3] =SYSCFG_EXTICR3_EXTI11_PB;
EXTI->RTSR |= EXTI_RTSR_TR11;
EXTI->IMR |= EXTI_IMR_MR11;
NVIC_EnableIRQ(EXTI4_15_IRQn);
NVIC_SetPriority(EXTI4_15_IRQn,1);
while(1)
{
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2017-11-08 4:14 PM
Do you have SYSCFG clock enabled in RCC?
JW
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2017-11-08 8:16 PM
Yes this worked. Thanks. ST have not mentioned about this in code example of reference manual on page no732. Index of array EXTICR is also wrong. Final code is like this
#include'stm32f0xx.h'
volatile int portBPin11Counter;void EXTI4_15_IRQHandler(void)
{ if((EXTI->PR & EXTI_PR_PR11)&&(EXTI->IMR & EXTI_IMR_MR11)) { EXTI->PR |= EXTI_PR_PR11; portBPin11Counter++; }}int main(void){ RCC->AHBENR |=RCC_AHBENR_GPIOCEN; RCC->APB2ENR |=RCC_APB2ENR_SYSCFGEN;SYSCFG->EXTICR[2] = (uint16_t)SYSCFG_EXTICR3_EXTI11_PC;
EXTI ->FTSR |= EXTI_FTSR_TR11;
EXTI->IMR |= EXTI_IMR_MR11;NVIC_EnableIRQ(EXTI4_15_IRQn);
NVIC_SetPriority(EXTI4_15_IRQn,0);while(1)
{ }}- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2017-11-09 1:29 AM
Index of array EXTICR is also wrong.
Indeed, the numbering from 1 is confusing.
In such cases I tend to write the index as
SYSCFG->EXTICR[3 - 1]
to hint for the future myself that it is a gotcha. Although, in this very particular case I might be also inclined to write
SYSCFG->EXTICR[11 / 4]
and add a comment to explain the '3' in the constant's name.
JW
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2017-11-09 4:15 AM
Hi friend. I try this code on my STM32F407, and I have a problem. I have this code, but interrupt doesn't generate.
My intterupt pin is PD4.
int8_t PD4_init(void)
{ LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_GPIOD); LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_SYSCFG);SYSCFG->EXTICR[1] = (uint16_t)SYSCFG_EXTICR2_EXTI4_PD;
LL_EXTI_EnableFallingTrig_0_31(EXTI_FTSR_TR4);
LL_EXTI_EnableIT_0_31(EXTI_IMR_MR4);NVIC_EnableIRQ(EXTI4_IRQn);
NVIC_SetPriority(EXTI4_IRQn,0); /* output pin with LED*/ LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_GPIOD); LL_GPIO_SetPinMode(GPIOD,LL_GPIO_PIN_14,LL_GPIO_MODE_OUTPUT);return 0;
}void EXTI4_IRQHandler (void)
{if ( LL_EXTI_IsActiveFlag_0_31(EXTI_PR_PR4) && LL_EXTI_IsEnabledIT_0_31(EXTI_IMR_MR4) )
{ LL_EXTI_ClearFlag_0_31(EXTI_PR_PR4);LL_GPIO_TogglePin(GPIOD,LL_GPIO_PIN_14); //toggle with RED LED
}}Any idea, what can be wrong?? Thank you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2017-11-09 4:24 AM
ST have not mentioned about this in code example of reference manual on page no732.
Indeed. However, those code fragments are meant only as a rough guideline. It's better to use the
http://www.st.com/en/embedded-software/stm32snippetsf0.html
as a starting point, as they form a complete working example.JW
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2017-11-10 12:32 AM
A lots of thanks for the link. I recently migrated from arduino to ST and this is really helpfull for people like me. But that refrence manual teach me how to code from data sheet. It is lengthy process but I am sure it will help in ling run. Keep up the good work.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2017-11-10 1:57 AM
Can't see any obvious problem. Verify the input signal is present on pin, e.g. by toggling the LED in a trivial check in a loop in main(), with no interrupts and no other code.
JW
