cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F3 Discovery - ADC Calibration Error

mattfox
Associate II
Posted on June 19, 2013 at 22:17

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:

&sharpinclude <stdint.h>

&sharpinclude ''stm32f30x_conf.h''

&sharpinclude ''peripherals.h''

&sharpinclude ''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);

}

#adc
15 REPLIES 15
306086914
Associate
Posted on July 03, 2013 at 05:37

hi,have you solve your problem?

I also study to use F3 discovery board, however your problem(could not get out of the while loop) didn't come out when I tested the ADC example.

about the HSE: there is no 8MHz

Crystal

on the discovery board for f303 chip,the HSE clock come from the ST-Link part. you can reference MB1035_stm32f3discovery_sch.pdf for help about the HSE CLOCK.

Posted on July 03, 2013 at 06:10

the HSE clock come from the ST-Link part.

This is true of several of the Discovery series boards, the F103 part implementing the ST-LINK and having USB connectivity, outputs its own HSE via the MCO (PA8) pin. This permits the F0 and F3 Discovery's to have an 8 MHz source, and use USB as required. Things like USB and CAN require the accuracy of a crystal based clock source.

Many of the boards also fail to populate the LSE 32.768 KHz crystal, and support components, and this can be problematic if you want to use STANDBY mode, and have the RTC keep ticking. Typically LSI is NOT in the backup power domain.

Finally, watch for peripherals needing the PLL running. On the F2/F4 the SDIO peripheral needs a 48 MHz, or so, clock tap off the PLL. If the system is running on the HSE or HSI directly the PLL may not be running, and the peripheral will not function.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
mattfox
Associate II
Posted on July 03, 2013 at 15:26

Unfortunately, I haven't solved the issue yet.  I've been doing a lot of reading up on the topic, but I can't seem to find any reason why it shouldn't work.  I emailed ST's technical center, but i'm not sure anything will result from that.  If anyone has any ideas, they would be welcome.

mattfox
Associate II
Posted on July 08, 2013 at 23:52

ST's response wasn't particularly helpful, but I did eventually get it working by commenting out the loop waiting for hardware to reset this bit.  I know this isn't the best way of solving the problem, but it's working for my purposes for now.

seb1
Associate II
Posted on September 13, 2013 at 15:27 I think your ADC doesn't have a clock when your start the calibration. You should put the part :

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);

Just before the calibration. Sébastien L.
pichkorsky
Associate II
Posted on October 15, 2015 at 15:56

Just for the history and to close this ''issue'':

When you say 

ADC_CommonInitStructure.ADC_Clock = ADC_Clock_AsynClkMode;

 

The clock derived from PLL will be used as ADC clock source.

By default PLL is turned off and you need to configure and enable it before using.

Also you can use AHB clock to drive ADC. SPL allows you to configure this throu ADC_CommonInit Structer 'ADC_clock' member.

For example - ADC_CommonInitStructure.ADC_Clock = ADC_Clock_SynClkModeDiv4;

 

Will do the job. 

This will configure CKMODE[1:0] of the ADCx_CCR register to one of 4 possible configuration.

P.S. tested on the STM32F3-Discovery board only