cancel
Showing results for 
Search instead for 
Did you mean: 

STM32f3 STD lib ADC init problem

thang le
Associate

Hello everyone.

I have problem with ADC module of STM32F3. I have two board, one board use STM32F334K8T6 is the first version of my prototype, one board use STM32F334C8T6 is new version. I have use ADC module in my program and using STD lib. but with the same code, it can only init ADC module of STM32F334K8T6 success, STM32F334C8T6 can't init. I try to init ADC1 of STM32F334C8T6 with HAL lib, it work done. I have tried to search datasheet and reference menuer of them to find out the difference but still not find out it. This is my code to init ADC1 module, when run with STM32F334C8T6, it stuck in "while(READ_BIT(ADCx->CR, ADC_CR_ADCAL));" line.

void ADC1_Indep_Init(ADC_TypeDef* ADCx)

{

/*--------------------------------------------------------------------------*/

ADC_InitTypeDef ADC_Init_Struct;

 ADC_CommonInitTypeDef ADC_Common_Struct;

GPIO_ADC1_Init();

/*--------------------------------------------------------------------------*/

/* ADC begin and clock config */

RCC_ADCCLKConfig(RCC_ADC12PLLCLK_Div1);              //ADC clock prescaler

RCC_AHBPeriphClockCmd(RCC_AHBPeriph_ADC12, ENABLE);        //Enable ADC clock if ADC clock sync AHB 

ADC_VoltageRegulatorCmd(ADCx, ENABLE);              //ADC vol regulator

Delay_10(2);

CLEAR_BIT(ADCx->CR, ADC_CR_ADCALDIF);               //Select calibration mode

SET_BIT(ADCx->CR, ADC_CR_ADCAL);                 //Start calibration

while(READ_BIT(ADCx->CR, ADC_CR_ADCAL));             //Wairt process

/*--------------------------------------------------------------------------*/

/* ADC common mode config */

ADC_Common_Struct.ADC_Clock = ADC_Clock_AsynClkMode;       //ADC clock source select 

ADC_Common_Struct.ADC_DMAAccessMode = ADC_DMAAccessMode_Disabled; //DMA mode select for dual ADC

ADC_Common_Struct.ADC_DMAMode = ADC_DMAMode_Circular;       //DMA mdoe select for single ADC        

ADC_Common_Struct.ADC_Mode = ADC_Mode_Independent;        //ADC mode dual or single

ADC_Common_Struct.ADC_TwoSamplingDelay = 0;            //Delay between 2 sample in anternate trigger mode

ADC_CommonInit(ADCx, &ADC_Common_Struct);

/*--------------------------------------------------------------------------*/

/* ADC module enable */

ADC_Cmd(ADCx, ENABLE);

while(!ADC_GetFlagStatus(ADCx, ADC_FLAG_RDY));

/*--------------------------------------------------------------------------*/

/* ADC1 init */

ADC_Init_Struct.ADC_AutoInjMode = ADC_AutoInjec_Disable;             //Auto injected group conversion mode

ADC_Init_Struct.ADC_ContinuousConvMode = ADC_ContinuousConvMode_Disable;     //Regular group continuous conversion mode

ADC_Init_Struct.ADC_DataAlign = ADC_DataAlign_Right;               //ADC data type

ADC_Init_Struct.ADC_ExternalTrigConvEvent = ADC_ExternalTrigConvEvent_13;     //External trigger event select

ADC_Init_Struct.ADC_ExternalTrigEventEdge = ADC_ExternalTrigEventEdge_None;    //External trigger edge select 

ADC_Init_Struct.ADC_NbrOfRegChannel = 1;                     //Number of conversion channel in regular group

ADC_Init_Struct.ADC_OverrunMode = ADC_OverrunMode_Disable;            //ADC result overrun mode

ADC_Init_Struct.ADC_Resolution = ADC_Resolution_12b;               //ADC resolution

ADC_Init(ADCx, &ADC_Init_Struct);

/*--------------------------------------------------------------------------*/

/* Auto delay mode if used */

ADC_AutoDelayCmd(ADCx, DISABLE);                          //This mode used conjungtion with 

                                          //ADC continuous mode to handle ADC convertion   

/*--------------------------------------------------------------------------*/

/* Analog watchdog config (if used) */

 ADC_AnalogWatchdogCmd(ADCx, ADC_AnalogWatchdog_AllRegEnable);

ADC_AnalogWatchdog1ThresholdsConfig(ADCx, 3722, 0);                //2.8V 

/*--------------------------------------------------------------------------*/

/* ADC DMA request enable */

ADC_DMAConfig(ADCx, ADC_DMAMode_Circular);

/*--------------------------------------------------------------------------*/

/* ADC1 regular group channels select and config, each channel need 

one saperate follwing function to config */

// ADC_RegularChannelConfig(ADCx, ADC_Channel_2, 1, ADC_SampleTime_4Cycles5);

ADC_RegularChannelConfig(ADCx, ADC_Channel_3, 1, ADC_SampleTime_4Cycles5);

}

1 REPLY 1
Ozone
Lead II

Did you check the ADC channel is routed to the same GPIO pin on both variants ?