AnsweredAssumed Answered

ADC1 Interrupt on EOC stopping after one conversion

Question asked by lindley.david on Jan 27, 2014
Latest reply on Jan 27, 2014 by Clive One
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:

01.#include <stdio.h>
02.#include "serial.h"
03.#include <stm32f4xx.h>
04.#include <stm32f4_discovery.h>
05.#include <stm32f4xx_adc.h>
06.#include <stm32f4xx_rcc.h>
07.  
08.void init_ADC(void){
09.      
10.    ADC_InitTypeDef ADC_init1; // ADC structure to configure an ADC
11.    GPIO_InitTypeDef GPIO_init1; // Configures the gpio that the adc is coming in on
12.      
13.    // Sets up the parameters for the
14.    RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);  // Enables ADC1s clock
15.    RCC_AHB1PeriphClockCmd(RCC_AHB1ENR_GPIOCEN, ENABLE); // Enables the GPIO clock for the pin that the cable in plugged into
16.      
17.    /* Configure the GPIO to take analogue voltages in */
18.    GPIO_init1.GPIO_Pin = GPIO_Pin_2; // Use PC2 for the ADC input
19.    GPIO_init1.GPIO_Mode = GPIO_Mode_AN; // Analogue input
20.    GPIO_init1.GPIO_PuPd = GPIO_PuPd_NOPULL;
21.    GPIO_Init(GPIOC, &GPIO_init1);
22.      
23.    /* Configures the ADC */
24.    ADC_init1.ADC_DataAlign = ADC_DataAlign_Right;
25.    ADC_init1.ADC_Resolution = ADC_Resolution_12b;
26.    ADC_init1.ADC_ContinuousConvMode = ENABLE;
27.    ADC_init1.ADC_ExternalTrigConv = ADC_ExternalTrigConvEdge_None;
28.    ADC_init1.ADC_NbrOfConversion = 1;
29.    ADC_init1.ADC_ScanConvMode = DISABLE;
30.    ADC_Init(ADC1, &ADC_init1);
31.      
32.    // Enables interrupts
33.    ADC1->CR1 |= ADC_CR1_EOCIE;
34.      
35.    NVIC_EnableIRQ(ADC_IRQn); //Enable IRQ for ADC complete.
36.      
37.    ADC_Cmd(ADC1,ENABLE); // Turn on ADC1
38.}
39.  
40.int main(void) {
41.    serial_init();
42.      
43.    printf("System Test\r\n");
44.    printf("0123456789ABCDEF\r\n");
45.      
46.    init_ADC();
47.      
48.    ADC1->CR2 |= ADC_CR2_SWSTART; // Starts the ADC
49.    /* Infinite loop: embedded software must never end */
50.    while(1) {
51.    }
52.}
53.  
54.void ADC_IRQHandler (void) {
55.    float step = 3.3 / 4096;
56.    float voltage;
57.    int convertedValue;
58.    convertedValue = ADC1->DR; // Gets the converted value. Should also reset the EOC flag
59.    voltage = (float)convertedValue * (float)step;
60.    printf("Converted Value is: %.5fV\r\n", voltage);
61.}

Outcomes