2017-01-02 08:01 AM
This is my CODE:
void ADC_t_init(void)
{ ADC_InitTypeDef ADC_InitStrc; ADC_CommonInitTypeDef ADC_CmmInitStrc;/* Configure the ADC clock */
RCC_ADCCLKConfig(RCC_ADC12PLLCLK_Div256);/* Enable ADC1 clock */
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_ADC12, ENABLE);/* Calibration procedure */
ADC_StructInit(&ADC_InitStrc); ADC_Init(ADC1, &ADC_InitStrc);ADC_Cmd(ADC1, DISABLE);
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));
calibration_value = ADC_GetCalibrationValue(ADC1); ADC_CmmInitStrc.ADC_Mode = ADC_Mode_Independent; ADC_CmmInitStrc.ADC_Clock = ADC_Clock_AsynClkMode; ADC_CmmInitStrc.ADC_DMAAccessMode = ADC_DMAAccessMode_Disabled; ADC_CmmInitStrc.ADC_DMAMode = ADC_DMAMode_OneShot; ADC_CmmInitStrc.ADC_TwoSamplingDelay = 0;ADC_CommonInit(ADC1, &ADC_CmmInitStrc);
ADC_InitStrc.ADC_ContinuousConvMode = ADC_ContinuousConvMode_Enable; ADC_InitStrc.ADC_Resolution = ADC_Resolution_12b; ADC_InitStrc.ADC_ExternalTrigConvEvent = ADC_ExternalTrigConvEvent_0; ADC_InitStrc.ADC_ExternalTrigEventEdge = ADC_ExternalTrigEventEdge_None; ADC_InitStrc.ADC_DataAlign = ADC_DataAlign_Right; ADC_InitStrc.ADC_OverrunMode = ADC_OverrunMode_Disable; ADC_InitStrc.ADC_AutoInjMode = ADC_AutoInjec_Disable; ADC_InitStrc.ADC_NbrOfRegChannel = 1; ADC_Init(ADC1, &ADC_InitStrc);/* ADC1 Temperature sensor configuration */
ADC_RegularChannelConfig(ADC1, ADC_Channel_TempSensor, 1, ADC_SampleTime_601Cycles5); /* Enable ADC1 */ ADC_Cmd(ADC1, ENABLE);/* Enable temperature sensor */
ADC_TempSensorCmd(ADC1,ENABLE);/* wait for ADRDY */
while(!ADC_GetFlagStatus(ADC1, ADC_FLAG_RDY));/* Start ADC1 Software Conversion */
ADC_StartConversion(ADC1);}and the program not exit from:
while(ADC_GetCalibrationStatus(ADC1));
anyone know where is the problem?
thenks for help.
Solved! Go to Solution.
2017-01-10 01:32 AM
Hi
Giacomo.Cimarelli
,- Theline 'ADC_Cmd(ADC1, DISABLE);' will set the ADDIS bit (ADDIS=1).
Your ADC was never enabled before this line, so ADEN=0.- On the reference manual, it's indicated that :
'Software is allowed to set ADDIS only when ADEN=1 and both ADSTART=0 and JADSTART=0 (which ensures that no conversion is ongoing)'-> What you are trying to do is out of specification.
What you should do is to comment the line below: 'ADC_Cmd(ADC1, DISABLE);'
And your code will be executedconveniently.
Khouloud.
2017-01-02 08:40 AM
Hi
Giacomo.Cimarelli
,You have disabled the
ADC1 peripheral using: ADC_Cmd(ADC1, DISABLE);
Try to enable it beforechecking the end of calibration.
If this solves your issue, please click on correct
:)
.Happy new year .
Khouloud.
2017-01-02 04:33 PM
Hi
Khouloud G
.On the ST Reference Manual is written:
The calibration is then initiated by software by setting bit ADCAL=1. Calibration can only be
initiated when the ADC is disabled (when ADEN=0). ADCAL bit stays at 1 during all thecalibration sequence. It is then cleared by hardware as soon the calibration completes. Atthis time, the associated calibration factor is stored internally in the analog ADC and also inthe bits CALFACT_S[6:0] or CALFACT_D[6:0] of ADCx_CALFACT register (depending onsingle-ended or differential input calibration)For the calibration need kept ADC disabled right?
I have try to enabling it but not work.
2017-01-10 01:32 AM
Hi
Giacomo.Cimarelli
,- Theline 'ADC_Cmd(ADC1, DISABLE);' will set the ADDIS bit (ADDIS=1).
Your ADC was never enabled before this line, so ADEN=0.- On the reference manual, it's indicated that :
'Software is allowed to set ADDIS only when ADEN=1 and both ADSTART=0 and JADSTART=0 (which ensures that no conversion is ongoing)'-> What you are trying to do is out of specification.
What you should do is to comment the line below: 'ADC_Cmd(ADC1, DISABLE);'
And your code will be executedconveniently.
Khouloud.
2017-01-10 04:56 AM
Thenks for the help now work!