AnsweredAssumed Answered

STM32F3 Discovery - ADC Calibration Error

Question asked by fox.matthew on Jun 19, 2013
Latest reply on Oct 15, 2015 by AlStorm Prime
I'm trying to run the ADC Example code that came along with this board, but I keep getting stuck in a loop where the calibration bit (ADC1.CR - bit 31 of the control register) isn't getting set back to zero, and I'm getting stuck in this while loop:

while(ADC_GetCalibrationStatus(ADC1) != RESET )
{
          printf("No Reset\n\r");
}

Any idea what the issue could be?  I read in the reference manual that once this bit is set, hardware will return in to 0, but this doesn't seem to be the case.  

My code looks like this:

#include <stdint.h>
#include "stm32f30x_conf.h"
#include "peripherals.h"
#include "common.h"




__IO uint16_t calibration_value = 0;
__IO uint32_t TimingDelay = 0;


ADC_InitTypeDef       ADC_InitStructure;
ADC_CommonInitTypeDef ADC_CommonInitStructure;
GPIO_InitTypeDef GPIO_InitStructure;


void ADC_Initialize(void)
{
     /* Configure the ADC clock */
     RCC_ADCCLKConfig(RCC_ADC12PLLCLK_Div2);


     /* Enable ADC1 clock */
     RCC_AHBPeriphClockCmd(RCC_AHBPeriph_ADC12, ENABLE);


     /* Setup SysTick Timer for 1 µsec interrupts  */
     if (SysTick_Config(SystemCoreClock / 1000000))
     {
          /* Capture error */
          while (1)
          {}
     }


     /* ADC Channel configuration */
     /* GPIOC Periph clock enable */
     RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOC, ENABLE);


     /* Configure ADC Channel7 as analog input */
     GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1 ;
     GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
     GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;
     GPIO_Init(GPIOC, &GPIO_InitStructure);


     ADC_StructInit(&ADC_InitStructure);
     /* Calibration procedure */
     ADC_VoltageRegulatorCmd(ADC1, ENABLE);


     /* Insert delay equal to 10 µs */
     Delay(10);


     ADC_SelectCalibrationMode(ADC1, ADC_CalibrationMode_Single);
     ADC_StartCalibration(ADC1);


     while(ADC_GetCalibrationStatus(ADC1) != RESET )
     {
          printf("No Reset\n\r");
     }
     calibration_value = ADC_GetCalibrationValue(ADC1);


     ADC_CommonInitStructure.ADC_Mode = ADC_Mode_Independent;
     ADC_CommonInitStructure.ADC_Clock = ADC_Clock_AsynClkMode;
     ADC_CommonInitStructure.ADC_DMAAccessMode = ADC_DMAAccessMode_Disabled;
     ADC_CommonInitStructure.ADC_DMAMode = ADC_DMAMode_OneShot;
     ADC_CommonInitStructure.ADC_TwoSamplingDelay = 0;
     ADC_CommonInit(ADC1, &ADC_CommonInitStructure);


     ADC_InitStructure.ADC_ContinuousConvMode = ADC_ContinuousConvMode_Enable;
     ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b;
     ADC_InitStructure.ADC_ExternalTrigConvEvent = ADC_ExternalTrigConvEvent_0;
     ADC_InitStructure.ADC_ExternalTrigEventEdge = ADC_ExternalTrigEventEdge_None;
     ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
     ADC_InitStructure.ADC_OverrunMode = ADC_OverrunMode_Disable;
     ADC_InitStructure.ADC_AutoInjMode = ADC_AutoInjec_Disable;
     ADC_InitStructure.ADC_NbrOfRegChannel = 1;
     ADC_Init(ADC1, &ADC_InitStructure);


     /* ADC1 regular channel7 configuration */
     ADC_RegularChannelConfig(ADC1, ADC_Channel_7, 1, ADC_SampleTime_7Cycles5);


     /* Enable ADC1 */
     ADC_Cmd(ADC1, ENABLE);


     /* wait for ADRDY */
     while(!ADC_GetFlagStatus(ADC1, ADC_FLAG_RDY))
          printf("\fWaiting\n\r");


}


/**
 * @brief  Inserts a delay time.
 * @param  nTime: specifies the delay time length, in milliseconds.
 * @retval None
 */


void Delay(__IO uint32_t nTime)
{
     TimingDelay = nTime;


     while(TimingDelay != 0);
}

Outcomes