cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F303 ADC clocks

ilanh
Associate II
Posted on July 27, 2015 at 16:51

Hi All,

Why the ADC is work only with the following configuration :

RCC_ADCCLKConfig(RCC_ADC12PLLCLK_Div4);

 

ADC_CommonInitStructure.ADC_Clock = ADC_Clock_SynClkModeDiv4;

I try to configure as the following:

RCC_HCLKConfig (RCC_SYSCLK_Div1);

 

ADC_CommonInitStructure.ADC_Clock =ADC_Clock_SynClkModeDiv4

 

and the ADC stop working

thanks

8 REPLIES 8
Posted on July 27, 2015 at 17:10

I don't know. Define ''stop working'', the values are wrong, the ADC stops generating EOC's?

May be you can provide a complete/concise example of what you're doing and the speeds of the clocks involved.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
raptorhal2
Lead
Posted on July 28, 2015 at 00:17

My observations:

There are two clock sources for an ADC, each has its own prescaler. I am not very well versed on the 303, but I think the second prescalar definition needs be as follows:

ADC_CommonInitStructure.ADC_Clock =ADC_Clock_

As

ynClkModeDiv4;

 

 

Cheers, Hal

 

 

Posted on July 28, 2015 at 00:31

I think the OP explicitly wants the AHB (Synchronous) clock, and can't understand why the second configuration doesn't work as expected, where as the first one shouldn't, but does.

I'd like to know what the AHB setting is in the first case, but the context is far too narrow to tell what's going on, and I'm not wasting a bunch of my time fabricating a complete example to see if it works for me or not.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
ilanh
Associate II
Posted on July 28, 2015 at 08:37

this is the configuration:

void ADC_Configuration(void)

{

  ADC_InitTypeDef ADC_InitStructure;

      

  ADC_CommonInitTypeDef  ADC_CommonInitStructure; 

 

  /* HCLK = SYSCLK */

    RCC_HCLKConfig(RCC_SYSCLK_Div1);  

 

  RCC_ADCCLKConfig (RCC_ADC12PLLCLK_Div4);    

  

     //   Enable ADC1 Clock

  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_ADC12, ENABLE);

  

     

   ADC_StructInit(&ADC_InitStructure);

   

  /* Calibration procedure 

  ADC_VoltageRegulatorCmd(ADC1, ENABLE);

  

  Delay(0x0FFF);

  

  

  ADC_SelectCalibrationMode(ADC1, ADC_CalibrationMode_Single);

  ADC_StartCalibration(ADC1);

//       ADC Calibration...

  while(ADC_GetCalibrationStatus(ADC1) != RESET );

    

  calibration_valueADC1 = ADC_GetCalibrationValue(ADC1); 

 

  /* ADC1 configuration ------------------------------------------------------*/

  //    

  ADC_CommonStructInit(&ADC_CommonInitStructure);

  ADC_CommonInitStructure.ADC_Mode =  ADC_Mode_Independent; 

  ADC_CommonInitStructure.ADC_Clock = ADC_Clock_SynClkModeDiv4;

  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_InitStructure.ADC_ContinuousConvMode = ADC_ContinuousConvMode_Disable;    

  ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b;

  ADC_InitStructure.ADC_ExternalTrigConvEvent = ADC_ExternalTrigConvEvent_3;                     //   TIMER2 exetrnal trigger.... 

  ADC_InitStructure.ADC_ExternalTrigEventEdge = ADC_ExternalTrigEventEdge_RisingEdge;                 

  ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Left;

  ADC_InitStructure.ADC_OverrunMode = ADC_OverrunMode_Disable;

  ADC_InitStructure.ADC_AutoInjMode = ADC_AutoInjec_Disable;

  ADC_InitStructure.ADC_NbrOfRegChannel = 4;    

  

  

  ADC_Init(ADC1, &ADC_InitStructure);

  

  

  

  

  /* ADC1 regular channel1 configuration */

  //    The Sensor analog in channels are wired counter logic.

  //    The following lines puts them in their ''correct'' respective places.

  ADC_RegularChannelConfig(ADC1, ADC_Channel_1,2, ADC_SampleTime_7Cycles5);      

  ADC_RegularChannelConfig(ADC1, ADC_Channel_2,1, ADC_SampleTime_7Cycles5);      

  ADC_RegularChannelConfig(ADC1, ADC_Channel_3,4, ADC_SampleTime_7Cycles5);      

  ADC_RegularChannelConfig(ADC1, ADC_Channel_4,3, ADC_SampleTime_7Cycles5);      

}

void DMA_Config(void)

{

 DMA_InitTypeDef DMA_InitStructure;

 

     /* Enable DMA1 clock */

  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);

  DMA_StructInit(&DMA_InitStructure);

 

  /* DMA1 channel1 configuration ----------------------------------------------*/

  DMA_DeInit(DMA1_Channel1);//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

  DMA_InitStructure.DMA_PeripheralBaseAddr = (u32)ADC1_DR_Address;

  DMA_InitStructure.DMA_MemoryBaseAddr = (u32)ADC_DualConvertedValueTab;

  DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;

  DMA_InitStructure.DMA_BufferSize = (512>> 1 ); 

  DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;

  DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;

  DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;    

  DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;            

  DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;

  DMA_InitStructure.DMA_Priority = DMA_Priority_VeryHigh;

  DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;

  DMA_Init(DMA1_Channel1, &DMA_InitStructure);

////   DMA_Cmd(DMA1_Channel1, ENABLE);//enable DMA

 

 

}

void DMA1_Channel1_IRQHandler(void)

{

  u8                  *adcPtr;

    if (DMA_GetITStatus(DMA1_IT_HT1)) {

      

        numBytesRead = DMA_GetCurrDataCounter(DMA1_Channel1);

         adcPtr=(u8 *)((u32)ADC_DualConvertedValueTab );

        DMA_ClearFlag(DMA1_FLAG_HT1);

        DMA_ClearITPendingBit(DMA1_IT_HT1);

   }

   

    if (DMA_GetITStatus(DMA1_IT_TC1)) 

    {

        numBytesRead = DMA_GetCurrDataCounter(DMA1_Channel1);

        adcPtr=(u8 *)((u32)ADC_DualConvertedValueTab + (ADC_VAL_SIZE/2));

        

        DMA_ClearFlag(DMA1_FLAG_TC1);       

        DMA_ClearITPendingBit(DMA1_IT_TC1);

        

    }

    

When the RCC_ADCCLKConfig (RCC_ADC12PLLCLK_Div4); removed then the ADC stop generating EOC's.

thanks

Amel NASRI
ST Employee
Posted on July 28, 2015 at 13:19

Hiioeoa.001,

If you want to use AHB as clock source for ADC input clock, you have to use:

RCC_ADCCLKConfig(RCC_ADC12PLLCLK_OFF);

and not remove the call for

RCC_ADCCLKConfig (RCC_ADC12PLLCLK_Div4);

-Mayla-

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

ilanh
Associate II
Posted on July 28, 2015 at 14:45

Hi Mayla,

I add the 

RCC_ADCCLKConfig(RCC_ADC12PLLCLK_OFF); after the 

RCC_ADCCLKConfig (RCC_ADC12PLLCLK_Div4);

The ADC stop generating EOC's.

Amel NASRI
ST Employee
Posted on July 28, 2015 at 17:27

Sorry, it seems that my answer created some confusion.

In fact, if you need the synchronous mode (The ADC clock derived from the AHB clock), you call

RCC_ADCCLKConfig(RCC_ADC12PLLCLK_OFF);

And you select value for ADC_Clock parameter:ADC_Clock_SynClkModeDiv1 orADC_Clock_SynClkModeDiv2 orADC_Clock_SynClkModeDiv4. If you need to use PLL as clock source (ADC in asynchronous mode),you call

RCC_ADCCLKConfig(RCC_ADC12PLLCLK_Div4); //Div1 to Div256

And you select value for ADC_Clock parameter:ADC_Clock_AsynClkMode -Mayla-

RCC_ADCCLKConfig(RCC_ADC12PLLCLK_OFF);

and

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

ilanh
Associate II
Posted on July 30, 2015 at 08:31

Hi Mayla,

In order to work with sync clock it should be defined after the clock selection(sync or async) as the following:

/* ADC1 configuration ------------------------------------------------------*/

  //    

  ADC_CommonStructInit(&ADC_CommonInitStructure);

  ADC_CommonInitStructure.ADC_Mode =  ADC_Mode_Independent; 

  ADC_CommonInitStructure.ADC_Clock = ADC_Clock_SynClkModeDiv4;

  ADC_CommonInitStructure.ADC_DMAAccessMode = ADC_DMAAccessMode_Disabled;         

  ADC_CommonInitStructure.ADC_DMAMode = ADC_DMAMode_OneShot;

  ADC_CommonInitStructure.ADC_TwoSamplingDelay = 0;

  ADC_CommonInit(ADC1, &ADC_CommonInitStructure);

  

  /* Calibration procedure 

  ADC_VoltageRegulatorCmd(ADC1, ENABLE);

  

  Delay(0x0FFF);

  

  

  ADC_SelectCalibrationMode(ADC1, ADC_CalibrationMode_Single);

  ADC_StartCalibration(ADC1);

//       ADC Calibration...

  while(ADC_GetCalibrationStatus(ADC1) != RESET );

    

  calibration_valueADC1 = ADC_GetCalibrationValue(ADC1);

thanks for your help