cancel
Showing results for 
Search instead for 
Did you mean: 

Problems using EXTI_Line1 Interrupt [PB1]

eng22
Associate II
Posted on March 28, 2009 at 14:45

Problems using EXTI_Line1 Interrupt [PB1]

9 REPLIES 9
eng22
Associate II
Posted on May 17, 2011 at 13:06

I´m having trouble to put the EXTI_Line1 to work properly. I need to use both, Rising and Falling edge interrupt, but I´m just being able to receive the Falling edge interrupt.

I tried the same code with the PB5 and PB6 ports and both works fine, Bur when I try with PB1 I just receive the falling edge interrupt.

Does anyone knows why this happens?

Thanks

sofiene
Associate III
Posted on May 17, 2011 at 13:06

Hi eng;

Can you share your configurations? and your EXTI IRQ code? so we can help you!

B.R.

M3allem

guyvo67
Associate II
Posted on May 17, 2011 at 13:06

Hi,

I saw your using the floating type. Maybe it's better to take a weak pull-up.

Do you have any external pull-up resistors used ?

Comes to rising edge very close after the falling edge ?

PUTTING A PRINTF() into an interrupt handler is most likely a BAD thing to do. Increment your counter and put a setFlag which you poll into you main routine. Be aware as if you code is now that the cortex stays in you EXTI routine as long as the printf will take (which is a huge amount of time compared with the speed of the cortex ints) So it coud be that you loose some edges here. Your EXTI_ClearITPendingBit(EXTI_Line1) is also after the printf.

Hope this will help

-G

[ This message was edited by: guyvo67 on 20-03-2009 18:31 ]

eng22
Associate II
Posted on May 17, 2011 at 13:06

Wow! I just notice that the problem was happening just with high frequency consecutive borders.

I change the orders between printf and the bit clearing and now it´s working perfect!!

It surely was happening because the serial communication of the printf.

Thank you very much for your help.

eng22
Associate II
Posted on May 17, 2011 at 13:06

This are my configurations, I´m using USART Printf example as base code and for debug purposes. I don´t have an emulator.

GPIO Configuration:

Code:

<BR>void GPIO_Configuration(void) <BR>{ <BR> GPIO_InitTypeDef GPIO_InitStructure; <BR> <BR> /* Configure USARTx_Tx as alternate function push-pull */ <BR> GPIO_InitStructure.GPIO_Pin = GPIO_TxPin; <BR> GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; <BR> GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; <BR> GPIO_Init(GPIOx, &GPIO_InitStructure); <BR> <BR> /* Configure USARTx_Rx as input floating */ <BR> GPIO_InitStructure.GPIO_Pin = GPIO_RxPin; <BR> GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; <BR> GPIO_Init(GPIOx, &GPIO_InitStructure); <BR> <BR> /* Configure Key Button GPIO Pin as input floating (Key Button EXTI Line) */ <BR> GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1; <BR> GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; <BR> GPIO_Init(GPIOB, &GPIO_InitStructure); <BR>} <BR>

I´ve also tried enabling the weak pull-up.

This is my main code:

Code:

<BR>int main(void) <BR>{ <BR> /* System Clocks Configuration */ <BR> RCC_Configuration(); <BR> <BR> /* Configure the GPIO ports */ <BR> GPIO_Configuration(); <BR> <BR>/* USARTx configuration ---*/ <BR> /* USARTx configured as follow: <BR> - BaudRate = 115200 baud <BR> - Word Length = 8 Bits <BR> - One Stop Bit <BR> - No parity <BR> - Hardware flow control disabled (RTS and CTS signals) <BR> - Receive and transmit enabled <BR> */ <BR> USART_InitStructure.USART_BaudRate = 115200; <BR> USART_InitStructure.USART_WordLength = USART_WordLength_8b; <BR> USART_InitStructure.USART_StopBits = USART_StopBits_1; <BR> USART_InitStructure.USART_Parity = USART_Parity_No ; <BR> USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; <BR> USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; <BR> <BR> /* Configure the USARTx */ <BR> USART_Init(USARTx, &USART_InitStructure); <BR> /* Enable the USARTx */ <BR> USART_Cmd(USARTx, ENABLE); <BR> <BR> /* Output a message on Hyperterminal using printf function */ <BR> printf(''nrUSART Printf Example: retarget the C library printf function to the USARTnr''); <BR> <BR> GPIO_EXTILineConfig(GPIO_PortSourceGPIOB,GPIO_PinSource1); <BR> <BR> /* Configure Key Button EXTI Line to generate an interrupt on rising and falling edge */ <BR> EXTI_InitStructure.EXTI_Line = EXTI_Line1; <BR> EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; <BR> EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising_Falling; <BR> EXTI_InitStructure.EXTI_LineCmd = ENABLE; <BR> EXTI_Init(&EXTI_InitStructure); <BR> <BR> /* NVIC configuration */ <BR> NVIC_Configuration(); <BR> <BR> while (1) <BR> {} <BR>} <BR>

This is my NVIC configuration code:

Code:

<BR>void NVIC_Configuration(void) <BR>{ <BR>NVIC_InitTypeDef NVIC_InitStructure; <BR> <BR> /* Set the Vector Table base location at 0x08000000 */ <BR> NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0); <BR> <BR> /* Enable the EXTI9_5 Interrupt */ <BR> NVIC_InitStructure.NVIC_IRQChannel = EXTI1_IRQChannel; <BR> NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; <BR> NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; <BR> NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; <BR> NVIC_Init(&NVIC_InitStructure); <BR>} <BR>

RCC configuration code:

Code:

<BR>void RCC_Configuration(void) <BR>{ <BR> /* RCC system reset(for debug purpose) */ <BR> RCC_DeInit(); <BR> <BR> /* Enable HSE */ <BR> RCC_HSEConfig(RCC_HSE_ON); <BR> <BR> /* Wait till HSE is ready */ <BR> HSEStartUpStatus = RCC_WaitForHSEStartUp(); <BR> <BR> if(HSEStartUpStatus == SUCCESS) <BR> { <BR> /* Enable Prefetch Buffer */ <BR> FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable); <BR> <BR> /* Flash 2 wait state */ <BR> FLASH_SetLatency(FLASH_Latency_2); <BR> <BR> /* HCLK = SYSCLK */ <BR> RCC_HCLKConfig(RCC_SYSCLK_Div1); <BR> <BR> /* PCLK2 = HCLK */ <BR> RCC_PCLK2Config(RCC_HCLK_Div1); <BR> <BR> /* PCLK1 = HCLK/2 */ <BR> RCC_PCLK1Config(RCC_HCLK_Div2); <BR> <BR> /* PLLCLK = 8MHz * 9 = 72 MHz */ <BR> RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9); <BR> <BR> /* Enable PLL */ <BR> RCC_PLLCmd(ENABLE); <BR> <BR> /* Wait till PLL is ready */ <BR> while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET) <BR> { <BR> } <BR> <BR> /* Select PLL as system clock source */ <BR> RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK); <BR> <BR> /* Wait till PLL is used as system clock source */ <BR> while(RCC_GetSYSCLKSource() != 0x08) <BR> { <BR> } <BR> } <BR> <BR> /* Enable GPIOx clock */ <BR> RCC_APB2PeriphClockCmd(RCC_APB2Periph_ALL, ENABLE); <BR> <BR>/* Enable USARTx clocks */ <BR> RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE); //unecessary <BR>} <BR>

Into my interruption code I just print to USART1 the number of times the program has executed that code. Just to keep track of how many interrupts were generated.

Code:

Code:

<BR>void EXTI1_IRQHandler(void) <BR>{ <BR> if(EXTI_GetITStatus(EXTI_Line1) != RESET) <BR> { <BR> printf(''Executed %i times!n'',++i); <BR> EXTI_ClearITPendingBit(EXTI_Line1); <BR> } <BR>} <BR>

I Appreciate if someone can help me to figure it out.

[ This message was edited by: eng3 on 20-03-2009 14:07 ]

eng22
Associate II
Posted on May 17, 2011 at 13:06

I solved the problem of receiveing both interrupts by removing the USART printf code from the interrupt, now, inside the interrupt I just verifiy wich interrupt happend, clear the IT pending bit and change the state of an external pin. But the problem was just partially solved. When I try to raise the interrupts frequency (something about 1 or 2 MHz) it works for few times and then stop receiving interrupts.

I think that some kind of interrupt stack overflow is happening, but I´m not shure if this is possible.

The rest of the code is pretty much the same, this is my new EXTI function:

Code:

<BR>void EXTI1_IRQHandler(void) <BR>{ <BR> if(EXTI_GetITStatus(EXTI_Line1) != RESET) <BR> { <BR> EXTI_ClearITPendingBit(EXTI_Line1); <BR> GPIO_WriteBit(GPIOB, GPIO_Pin_5, pin5val); <BR> pin5val ^= 1; <BR> } <BR>} <BR>

How can I make it work with interrupt source frequency about 15 MHz ?

[ This message was edited by: eng3 on 25-03-2009 13:07 ]

sofiene
Associate III
Posted on May 17, 2011 at 13:06

Hi eng,

Can you tell us what's the purpose of using the EXTI interrupt and what's the signal nature you are measuring? may using the timer input capture solves your problem!

B.R.

M3allem

eng22
Associate II
Posted on May 17, 2011 at 13:06

I can´t figure outr how the timer can help me, but I´m using de EXTI1 interrupt to receive the SPI chip select signal so I can assert and deassert the SSI bit for software NSS.

Hope someone can help me.

andreas2
Associate II
Posted on May 17, 2011 at 13:06

Wow... You run the Cortex at 72 MHz and want an interrupt frequency of 15 MHz(!). Do you realize that would give the poor core 4.8 cycles to save the context, execute your handler and pop the context back?

Besides, a chip select at 15 MHz seems off by a few decades.