cancel
Showing results for 
Search instead for 
Did you mean: 

stm32f303 external interrupt

bifrost
Associate II
Posted on March 01, 2014 at 01:53

hello,

i'm trying to set up PDE0-1-2-3-4-5 for external interrupt. I want to have 6 pin near each other just to have a nicer cabling layout.

I set up the clock, the pin as input.

Then i have to set up SYSCFG_EXTILineConfig() for every pin, right?

Then i set up EXTI_Init() with EXTI_LineX, where X goes from 0 to 5, because every pin is in a different line (reference manual page 190)

Then i have to set up NVIC_Init(), i use EXTI0_IRQn, but is it only about priority and to group interrupt?, or there is HW related, like for line? i'm a bit confused.

also, now i'll have to write a void EXTI0_IRQHandler(void), with have to pay attention on witch pin generate the interrupt, or there is alredy somenthing that does that for me?

thank you.

#stm32f3-interrupt-discovery
2 REPLIES 2
Posted on March 01, 2014 at 04:17

You'll set up ONE pin per EXTI Line#, and set up the multiple interrupts (NVIC/Handler) they will be directed too. EXTI Line#5 thru #9 going to EXTI9_5_IRQHandler

EXTI0_IRQHandler                  ; EXTI Line0

EXTI1_IRQHandler                  ; EXTI Line1

EXTI2_TS_IRQHandler               ; EXTI Line2 and Touch

EXTI3_IRQHandler                  ; EXTI Line3

EXTI4_IRQHandler                  ; EXTI Line4

EXTI9_5_IRQHandler                ; External Line[9:5]s

See also STM32F3-Discovery_FW_V1.1.0\Project\Peripheral_Examples\EXTI_Example

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
bifrost
Associate II
Posted on March 01, 2014 at 15:16

Thank you very much! DS was not really clear, and because ''multiuple'' EXT_IRQ wasn's near other EXT_IRQ, i missed them.

found out the the IRQ 10-15 is perferct for me, as i want to READ 6 asinc PPM signal. that's my code, hope it is right and will help someone (nb: micros() is a function that return number of us from the board start up, i don't care about overflow as it is an unsigned int 32, so the subtraction math will always be correct)

/*
thanks to clive1
*/
uint32_t high_start[] = { 0, 0, 0, 0, 0, 0 };
volatile uint32_t ppm_value[] = { 0, 0, 0, 0, 0, 0 };
void
external_interrupt_init() {
GPIO_InitTypeDef GPIO_InitStructure;
EXTI_InitTypeDef EXTI_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
/* Enable the pin Clock */
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOE, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE); 
//or TIM
int
i = 0;
for
(i = 0; i < 6; i++) {
/* Configure pin as input */
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_InitStructure.GPIO_Pin = 1<<(i+10);
GPIO_Init(GPIOE, &GPIO_InitStructure);
/* Connect Button EXTI Line to GPIO Pin */
SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOE, i + 10);
/* Configure EXTI line */
EXTI_InitStructure.EXTI_Line = i + 10;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising_Falling;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
}
/* Enable and set EXTI Interrupt with the lowest priority */
NVIC_InitStructure.NVIC_IRQChannel = EXTI15_10_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x0F;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x0F;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
void
EXTI15_10_IRQHandler(
void
) {
int
i;
for
(i = 0; i < 6; i++) {
if
(EXTI_GetITStatus(i + 10) == SET){ 
//IF pin is now HIGH
if
(high_start[i] == 0){ 
//and no read as started
high_start[i] = micros(); 
//nail it as HIGH signal start
}
}
else
{ 
//IF pin is now LOW
if
(high_start[i] != 0){ 
//and just before there was HIGH signal
ppm_value[i] = micros() - high_start[i]; 
//calculate PPM value (should be between ~1000us and ~1800us)
high_start[i] = 0; 
//prepare for the next reading
}
}
EXTI_ClearITPendingBit(i+10); 
//clear pending interrupt
}
}