cancel
Showing results for 
Search instead for 
Did you mean: 

STM32VLDiscovery EXTI

hprado
Associate II
Posted on September 08, 2013 at 06:54

My question is probably simple. Can I configure external interrupts triggered by PA10, PA11, PA12 and PA13?

Studing the EXTI example I understood something like this: PA0 is connected to EXTI_Line0 and about the handler: EXTI0_IRQHandler(). So... For PA10,11,12 and 13 how should it be? I was trying the following to configure the pins as IT sources:

void GPIO_IT_Setup()
{
EXTI_InitTypeDef EXTI_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
// Configure IT sources
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10 | GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_13;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
// Connect sources to EXTI Lines
GPIO_EXTILineConfig(GPIO_PortSourceGPIOA, GPIO_PinSource10);
GPIO_EXTILineConfig(GPIO_PortSourceGPIOA, GPIO_PinSource11);
GPIO_EXTILineConfig(GPIO_PortSourceGPIOA, GPIO_PinSource12);
GPIO_EXTILineConfig(GPIO_PortSourceGPIOA, GPIO_PinSource13);
// Configure Button EXTI lines
EXTI_InitStructure.EXTI_Line = EXTI_Line10 | EXTI_Line11 | EXTI_Line12 | EXTI_Line13;
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 EXTI Interrupts
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);
}

And the following to configure the handlers:

void EXTI10_IRQnHandler(void)
{
if (EXTI_GetITStatus(EXTI_Line10) != RESET)
{
// Random code
EXTI_ClearITPendingBit(EXTI_Line10);
}
}
void EXTI11_IRQnHandler(void)
{
if (EXTI_GetITStatus(EXTI_Line11) != RESET)
{
// Random code
EXTI_ClearITPendingBit(EXTI_Line11);
}
}
void EXTI12_IRQnHandler(void)
{
if (EXTI_GetITStatus(EXTI_Line12) != RESET)
{
// Random code
EXTI_ClearITPendingBit(EXTI_Line12);
}
}
void EXTI13_IRQnHandler(void)
{
if (EXTI_GetITStatus(EXTI_Line13) != RESET)
{
// Random code
EXTI_ClearITPendingBit(EXTI_Line13);
}
}

But obviously didn't work. I would love if someone could help me with this. Thanks since now! #stm32vldiscovery #stm32vl
6 REPLIES 6
Posted on September 08, 2013 at 13:28

Try this

// High order EXTI - STM32-VLDiscovery - sourcer32@gmail.com
#include ''STM32vldiscovery.h''
int main(void)
{
EXTI_InitTypeDef EXTI_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
// Enable clocks first so peripherals work, AFIO required for EXTI
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_AFIO, ENABLE);
// Configure IT sources
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10 | GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_13;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD; // You sure? For a button I'd pull up

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
// Connect sources to EXTI Lines
GPIO_EXTILineConfig(GPIO_PortSourceGPIOA, GPIO_PinSource10);
GPIO_EXTILineConfig(GPIO_PortSourceGPIOA, GPIO_PinSource11);
GPIO_EXTILineConfig(GPIO_PortSourceGPIOA, GPIO_PinSource12);
GPIO_EXTILineConfig(GPIO_PortSourceGPIOA, GPIO_PinSource13);
// Configure Button EXTI lines
EXTI_InitStructure.EXTI_Line = EXTI_Line10 | EXTI_Line11 | EXTI_Line12 | EXTI_Line13;
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 EXTI Interrupts
NVIC_InitStructure.NVIC_IRQChannel = EXTI15_10_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
while(1);
}
void EXTI15_10_IRQHandler(void)
{
if (EXTI_GetITStatus(EXTI_Line10) != RESET)
{
EXTI_ClearITPendingBit(EXTI_Line10);
// Random code
}
if (EXTI_GetITStatus(EXTI_Line11) != RESET)
{
EXTI_ClearITPendingBit(EXTI_Line11);
// Random code
}
if (EXTI_GetITStatus(EXTI_Line12) != RESET)
{
EXTI_ClearITPendingBit(EXTI_Line12);
// Random code
}
if (EXTI_GetITStatus(EXTI_Line13) != RESET)
{
EXTI_ClearITPendingBit(EXTI_Line13);
// Random code
}
}

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
hprado
Associate II
Posted on September 08, 2013 at 17:12

Thank you very much Clive!

EXTI_Line10, 11 and 12 are working perfectly. But EXTI_Line13 is firing even without the external trigger. You know what can be?

I'm configuring the GPIO_Mode as GPIO_Mode_IPD because the triggers are mechanical keys that are normally open. It's a mistake?

One more thing. There is some document that contains a Pin_Function/AF table for stm32vl board?

Thanks again!
Posted on September 08, 2013 at 17:52

And how are they connected when they are closed?

Pull-down and Falling Edge are counter-intuitive, if they close to ground (ie H->L), then a pull-up surely?

The VL-Discovery has a user manual, the F100 part has a data sheet/manual.

Wouldn't PA13 conflict with the SWDIO pin of the debug interface?
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
hprado
Associate II
Posted on September 08, 2013 at 19:06

The keys  (in series with a resistor [1K]) are connected to 3.0V. When closed they put high level in the IO port (L > H). It's working fine...

I need to handle with rising and falling events of the keys to drive some lights.

The interrupts configured to PA10, PA11 and PA12 are good. But for PA13, 14 and 15 aren't. 

I don't have any idea about what is the cause. I'll configure the EXTI_Line1 and use PA1 instead of PA13.

Thanks for all Clive. If you discover why the Pins 13~15 didn't work please let me know.

Posted on September 08, 2013 at 21:37

If you discover why the Pins 13~15 didn't work please let me know.

I don't think I need to discover why PA13/PA14 are problematic. PA15 is going to require JTAG being remapped.

http://www.st.com/st-web-ui/static/active/en/resource/technical/document/user_manual/CD00267113.pdf

http://www.st.com/st-web-ui/static/active/en/resource/technical/document/datasheet/CD00251732.pdf

http://www.st.com/st-web-ui/static/active/en/resource/technical/document/reference_manual/CD00246267.pdf

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
hprado
Associate II
Posted on September 08, 2013 at 22:49

Okay! Got it mate.