Hello everyone, I have some problems with my stm32p103.
I am currently in a robotic team, in charge of the informatic part, and my problem is dealing with interrupts. In fact I have already tested input and ouput ports that I use, and my LED too, and everything is working well.
I have a sensor connected to the port C6, and my goal is to have an interrupt each time the sensor(1or0 state) detect something, but it doesn’t works.
My init files own theses declarations:
void GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_EXTILineConfig(GPIO_PortSourceGPIOC, GPIO_PinSource6);
GPIO_Init(GPIOC, &GPIO_InitStructure);
}
void EXTI_it_Configuration(void)
{
EXTI_InitTypeDef EXTI_InitStructure;
….
EXTI_InitStructure.EXTI_Line = EXTI_Line8 ;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising_Falling;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_GenerateSWInterrupt(EXTI_Line8);
EXTI_Init(&EXTI_InitStructure);
}
void NVIC_Configuration(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
…
// Enable the EXTI9_5 Interrupt
NVIC_InitStructure.NVIC_IRQChannel = EXTI9_5_IRQn; // I have already seen an exemple with: EXTI9_5_IRQChannel instead of EXTI9_5_IRQn
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
My stm32f10x_it.c fils own this :
void EXTI9_5_IRQHandler(void)
{
if(EXTI_GetITStatus(EXTI_Line8) == SET)
{
EXTI_ClearITPendingBit(EXTI_Line8);
setLed();
}
}
Thank you for helping me!
|
Hi,
Several issues in your code:
1) On STM32 each peripheral has to be "clocked" before it can be used. You need the following lines at the beginning of your code:
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC | RCC_APB2Periph_AFIO, ENABLE);
2) You messed up the EXTI line numbers: If you want to trigger on PC6 (as the GPIO is configured), you need to activate EXTI_Line6, NOT Line8!
Following is a code that works fine on REva with STM32F103-DB, needs the LED0 pin to be raised to Vcc to trigger the interrupt:
Best Regards,
It works well! Tahnk you very much!