cancel
Showing results for 
Search instead for 
Did you mean: 

Adc issue stm32f3

d4ng3r09
Associate II
Posted on September 26, 2014 at 21:29

Hello, i am using the adc from stm32f3 discovery board.I read the documentation and had a look at the example and came out with this code which doesn t work.

Any helpfull suggestions please?

#include ''stm32f30x.h''
#include ''stm32f30x_adc.h''
#include ''stm32f30x_gpio.h''
#include ''stm32f30x_rcc.h''
__IO uint32_t TimingDelay = 10;
/* Private typedef */
/* Private define */
/* Private macro */
/* Private variables */
/* Private function prototypes */
/* Private functions */
/* Global variables */
uint32_t timerFlag = 0;
/**
**===========================================================================
**
** Abstract: main program
**
**===========================================================================
*/
int main(void) {
ADC_InitTypeDef ADC_InitStruct;
GPIO_InitTypeDef GPIO_InitStruct;
ADC_CommonInitTypeDef ADC_CommonInitStructure;
TimingDelay = 10;
int ConvValue=0;
int calibration_value;
RCC_ADCCLKConfig(RCC_ADC12PLLCLK_Div1);
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_ADC12, ENABLE);
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_0;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AN;
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_InitStruct.GPIO_OType = GPIO_OType_PP;
GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOA, &GPIO_InitStruct);
GPIO_PinLockConfig(GPIOA, GPIO_Pin_0);
ADC_InitStruct.ADC_ContinuousConvMode = ENABLE;
ADC_InitStruct.ADC_Resolution = ADC_Resolution_12b;
ADC_InitStruct.ADC_ExternalTrigConvEvent = ADC_ExternalTrigConvEvent_0;
ADC_InitStruct.ADC_ExternalTrigEventEdge = ADC_ExternalTrigEventEdge_None;
ADC_InitStruct.ADC_DataAlign = ADC_DataAlign_Right;
ADC_InitStruct.ADC_OverrunMode = DISABLE;
ADC_InitStruct.ADC_AutoInjMode = DISABLE;
ADC_InitStruct.ADC_NbrOfRegChannel = 1;
ADC_RegularChannelConfig(ADC1, ADC_Channel_1, 1, ADC_SampleTime_1Cycles5);
ADC_VoltageRegulatorCmd(ADC1, ENABLE);
// while(TimingDelay != 0);
//{TimingDelay--;
//}
ADC_SelectCalibrationMode(ADC1, ADC_CalibrationMode_Single);
ADC_StartCalibration(ADC1);
while (ADC_GetCalibrationStatus(ADC1) != RESET)
;
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_Cmd(ADC1, ENABLE);
ADC_StartCalibration(ADC1);
while (1) {
while (ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC) != RESET) {
ConvValue =ADC_GetConversionValue(ADC1);
ADC_ClearFlag(ADC1, ADC_FLAG_EOC);
}
}
return (0);
}

#coding---its-about-being-precise
2 REPLIES 2
Posted on September 26, 2014 at 21:40

ADC_StartCalibration(ADC1); //???

ADC_StartConversion(ADC1); // <--- THIS

Also reading the conversion implicitly clears EOC, so no point in that.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
d4ng3r09
Associate II
Posted on September 27, 2014 at 22:13

That is it!!

Thank you sir.