2010-07-30 03:17 AM
ADC 1
2011-05-17 05:00 AM
Post your code so we can see if everything is initialized properly.
Cheers, Hal2011-05-17 05:00 AM
/* Enable ADC1 clock */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);
// RC5 - analog input - ADC
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
GPIO_Init (GPIOC, &GPIO_InitStructure);
ADC_InitTypeDef ADC_InitStructure;
ADC_DeInit(ADC1);
// ADC Structure Initialization
ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;
ADC_InitStructure.ADC_ScanConvMode = DISABLE;
ADC_InitStructure.ADC_ContinuousConvMode = DISABLE;
ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
ADC_InitStructure.ADC_NbrOfChannel = 2;
// Enable Temperature channel
ADC_TempSensorVrefintCmd ( ENABLE );
// Init ADC1
ADC_Init ( ADC1, &ADC_InitStructure );
ADC_RegularChannelConfig ( ADC1 , ADC_Channel_15 , 1 , ADC_SampleTime_41Cycles5 );
ADC_RegularChannelConfig ( ADC1 , ADC_Channel_16 , 2 , ADC_SampleTime_239Cycles5 );
// Enable the ADC
ADC_Cmd ( ADC1, ENABLE );
// ADC calibration
// Enable ADC1 reset calibaration register
ADC_ResetCalibration(ADC1);
// Check the end of ADC1 reset calibration register
while(ADC_GetResetCalibrationStatus(ADC1) == SET);
// Start ADC1 calibaration
ADC_StartCalibration(ADC1);
// Check the end of ADC1 calibration
while(ADC_GetCalibrationStatus(ADC1) == SET);
/* Function for ADC1 read
int32_t GetADC1Channel(void)
{
// Start the conversion
ADC_SoftwareStartConvCmd(ADC1, ENABLE);
// Wait until conversion completion
while(ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC) == RESET);
// Get the conversion value
return (int32_t)((ADC_GetConversionValue(ADC1)*100)/4095); // return percentage
}
2011-05-17 05:00 AM
Each ADC has one conversion data register, not one register per channel, so you need to use DMA for two or more channels.
Cheers, Hal2011-05-17 05:00 AM