2014-04-05 08:22 PM
Hey,
I'm currently working on a project for my class with the STM32F4 board, and am having difficulty trying to configure the user push button to cause an interrupt. I have used the F3 board a few times, and have made the same approach to configuring and handling the user button, however, can not get it to function correctly on the F4. - I am using the IAR Embedded Workbench IDE - I have initialized the pin as follows:STM_EVAL_PBInit(BUTTON_USER, BUTTON_MODE_EXTI);
- My interrupt handler is as follows:
void EXTI0_IRQHandler(void)
{
if(EXTI_GetITStatus(EXTI_Line0) != RESET){
button_push = 1; // Global variable
EXTI_ClearFlag(EXTI_Line0);
}
EXTI_ClearITPendingBit(EXTI_Line0);
}
I apologize if I have left any other details out. I have tried to configure EXTI0 without the use of ''STM_EVAL_PBInit'', and still was unable to configure the button.
Any help would be much appreciated! Thanks!
#stm32f4 #discovery #exti
2014-04-05 09:22 PM
Configured NVIC?
// STM32F4-Discovery ORANGE/GREEN LED Toggle from USER Button - sourcer32@gmail.com
#include ''stm32f4_discovery.h''
/**************************************************************************************/
void EXTI0_IRQHandler(void)
{
if(EXTI_GetITStatus(EXTI_Line0) != RESET)
{
/* Clear the EXTI line 0 pending bit */
EXTI_ClearITPendingBit(EXTI_Line0);
/* Toggle LED3 */
STM_EVAL_LEDToggle(LED3);
/* Toggle LED4 */
STM_EVAL_LEDToggle(LED4);
}
}
/**************************************************************************************/
int main(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
EXTI_InitTypeDef EXTI_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
/* Enable GPIOA clock */
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
/* Enable SYSCFG clock */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
/* Configure PA0 pin as input floating */
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
GPIO_Init(GPIOA, &GPIO_InitStructure);
/* Connect EXTI Line0 to PA0 pin */
SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOA, EXTI_PinSource0);
/* Configure EXTI Line0 */
EXTI_InitStructure.EXTI_Line = EXTI_Line0;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
/* Enable and set EXTI Line0 Interrupt to the lowest priority */
NVIC_InitStructure.NVIC_IRQChannel = EXTI0_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x01;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x01;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
/* Initialize LEDs mounted on STM32F4-Discovery board */
STM_EVAL_LEDInit(LED3);
STM_EVAL_LEDInit(LED4);
STM_EVAL_LEDOn(LED3);
STM_EVAL_LEDOff(LED4);
while(1); // Do not want to exit
}
/**************************************************************************************/
#ifdef USE_FULL_ASSERT
/**
* @brief Reports the name of the source file and the source line number
* where the assert_param error has occurred.
* @param file: pointer to the source file name
* @param line: assert_param error line source number
* @retval None
*/
void assert_failed(uint8_t* file, uint32_t line)
{
/* User can add his own implementation to report the file name and line number,
ex: printf(''Wrong parameters value: file %s on line %d
'', file, line) */
while (1)
{}
}
#endif
/**************************************************************************************/
2014-04-05 09:49 PM
Thanks for the quick reply.
I've tried that, and it did not work. I even copied/pasted that code and it did not work. I believe I may be missing some file in my project. I created a new blank project according to the following post:http://dccharacter.blogspot.com/2013/03/creating-new-project-for-stm32f4.htmlI think thestm32f4xx_it.c and stm32f4xx_it.h files I used may be causing problems. Any advice on which to use? This is my first time creating the blank project.
2014-04-05 10:03 PM
I don't use IAR, but would suggest you look at the template projects in STM32F4-Discovery_FW_v1.1.0\Project\Peripheral_Examples and clone one of those as a starting point.