Question
ADC1 Interrupt on EOC stopping after one conversion
Posted on January 27, 2014 at 11:22
Hi,
Basically I have an issue with the ADC1 interrupt on EOC. It fires once in continuous mode but then after reading the value (thus resetting the EOC) it never fires again. Im stumped as to why this happens. Any advice much appreciated:
#include <
stdio.h
>
#include ''serial.h''
#include <
stm32f4xx.h
>
#include <
stm32f4_discovery.h
>
#include <
stm32f4xx_adc.h
>
#include <
stm32f4xx_rcc.h
>
void init_ADC(void){
ADC_InitTypeDef ADC_init1; // ADC structure to configure an ADC
GPIO_InitTypeDef GPIO_init1; // Configures the gpio that the adc is coming in on
// Sets up the parameters for the
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE); // Enables ADC1s clock
RCC_AHB1PeriphClockCmd(RCC_AHB1ENR_GPIOCEN, ENABLE); // Enables the GPIO clock for the pin that the cable in plugged into
/* Configure the GPIO to take analogue voltages in */
GPIO_init1.GPIO_Pin = GPIO_Pin_2; // Use PC2 for the ADC input
GPIO_init1.GPIO_Mode = GPIO_Mode_AN; // Analogue input
GPIO_init1.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOC, &GPIO_init1);
/* Configures the ADC */
ADC_init1.ADC_DataAlign = ADC_DataAlign_Right;
ADC_init1.ADC_Resolution = ADC_Resolution_12b;
ADC_init1.ADC_ContinuousConvMode = ENABLE;
ADC_init1.ADC_ExternalTrigConv = ADC_ExternalTrigConvEdge_None;
ADC_init1.ADC_NbrOfConversion = 1;
ADC_init1.ADC_ScanConvMode = DISABLE;
ADC_Init(ADC1, &ADC_init1);
// Enables interrupts
ADC1->CR1 |= ADC_CR1_EOCIE;
NVIC_EnableIRQ(ADC_IRQn); //Enable IRQ for ADC complete.
ADC_Cmd(ADC1,ENABLE); // Turn on ADC1
}
int main(void) {
serial_init();
printf(''System Test\r\n'');
printf(''0123456789ABCDEF\r\n'');
init_ADC();
ADC1->CR2 |= ADC_CR2_SWSTART; // Starts the ADC
/* Infinite loop: embedded software must never end */
while(1) {
}
}
void ADC_IRQHandler (void) {
float step = 3.3 / 4096;
float voltage;
int convertedValue;
convertedValue = ADC1->DR; // Gets the converted value. Should also reset the EOC flag
voltage = (float)convertedValue * (float)step;
printf(''Converted Value is: %.5fV\r\n'', voltage);
}
#interrupts #adc