Interrupt Handler Setup
Hello,
I just got an STM32f4 discovery board and I seem to be having trouble making the interrupts work. I was able to get the button to work on the external interrupt and timer 4 to work similar to the demo code, however I cannot get the ADC EOC interrupt to work.
I have it set so then LED5 on the discovort board turns on if the ADC_IRQHandler is entered and then it should start a new conversion. My main initializes the LEDs, the Button, timer4 and the ADC as seen below. After the ADC is initialized, I start a conversion then sit in an empty while(1).
This first conversion complietes, I can see the value in the ADC_DR register, however I only get the one conversion and as I said I don’t enter the IRQ handler.
Can anyone with a little more experiance please point out what I might have missed with respect to setting up my interrupts?
Thank you.
Here is my ADC init function, incase I missed something.
void ADC3_CH12_Config(void)
{
ADC_InitTypeDef ADC_InitStructure;
ADC_CommonInitTypeDef ADC_CommonInitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
// Enable ADC3, DMA2 and GPIO clocks ****************************************
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC3, ENABLE);
// Configure ADC3 Channel12 pin as analog input ******************************
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;
GPIO_Init(GPIOC, &GPIO_InitStructure);
// ADC Common Init **********************************************************
ADC_CommonInitStructure.ADC_Mode = ADC_Mode_Independent;
ADC_CommonInitStructure.ADC_Prescaler = ADC_Prescaler_Div2;
ADC_CommonInitStructure.ADC_DMAAccessMode = ADC_DMAAccessMode_Disabled;
ADC_CommonInitStructure.ADC_TwoSamplingDelay = ADC_TwoSamplingDelay_5Cycles;
ADC_CommonInit(&ADC_CommonInitStructure);
// ADC3 Init ****************************************************************
ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b;
ADC_InitStructure.ADC_ScanConvMode = DISABLE;
ADC_InitStructure.ADC_ContinuousConvMode = DISABLE;
ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None;
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
ADC_InitStructure.ADC_NbrOfConversion = 1;
ADC_Init(ADC3, &ADC_InitStructure);
// ADC3 regular channel12 configuration *************************************
ADC_RegularChannelConfig(ADC3, ADC_Channel_12, 1, ADC_SampleTime_3Cycles);
ADC_ITConfig(ADC3, ADC_IT_EOC, ENABLE);
// Enable ADC3
ADC_Cmd(ADC3, ENABLE);
}
Then this is my IRQ Handler
void ADC_IRQHandler(void)
{
//Turn on LED if IRQ is entered
GPIO_PinOn(GPIOD, LED5_PIN);
if(ADC_GetITStatus(ADC3, ADC_FLAG_EOC) != RESET)
{
ADCvalue = ADC_GetConversionValue(ADC3);
ADC_ClearITPendingBit(ADC3, ADC_FLAG_EOC);
}
ADC_SoftwareStartConv(ADC3);
}
My startup_stm32f4xx.s file has these entries in it and it was generated when I created my project.
.word ADC_IRQHandler /* ADC1, ADC2 and ADC3s */
.weak ADC_IRQHandler
.thumb_set ADC_IRQHandler,Default_Handler