2014-09-26 12:29 PM
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
2014-09-26 12:40 PM
ADC_StartCalibration(ADC1); //???
ADC_StartConversion(ADC1); // <--- THIS Also reading the conversion implicitly clears EOC, so no point in that.2014-09-27 01:13 PM