AnsweredAssumed Answered

STM32F303CB ==> RCC_ADCCLKConfig

Question asked by morpheus87 on Nov 21, 2013
Latest reply on Nov 22, 2013 by Clive One
Hello,

I have a problem with the RCC_ADCCLKConfig, I want to change the  ADC frequency and I followed the example from st.

   /* Configure the ADC clock */
  RCC_ADCCLKConfig(RCC_ADC12PLLCLK_Div64);
 
  /* Enable ADC1 clock */
  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_ADC12, ENABLE);   
  /* ADC Channel configuration */
  /* GPIOC Periph clock enable */
  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
  /* Configure ADC Channel7 as analog input */
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 ;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;
  GPIO_Init(GPIOA, &GPIO_InitStructure);
  ADC_StructInit(&ADC_InitStructure);

....


after I check the ADC frequency these commands
    RCC_ClocksTypeDef ClockHw;
  RCC_GetClocksFreq(&ClockHw);

the frequency hasn't modified, 48MHz, so I check step by step and I found a strange part.

in Rcc.h
#define RCC_ADC12PLLCLK_Div64                  ((uint32_t)0x00000190)

in Rcc.c , void RCC_ADCCLKConfig(uint32_t RCC_PLLCLK)

when I call this function I check the writter, and it's ok , RCC->CFGR2 |= RCC_PLLCLK; = 400


When I check the frequency with this function RCC_GetClocksFreq()

 /* Get ADC12CLK prescaler */
  tmp = RCC->CFGR2 & RCC_CFGR2_ADCPRE12; //here cfgr2 = 0x190 and ADCPRE12 = 0x1F0 , so the result is 0x190 (dec 400)

  tmp = tmp >> 4; // 400/16 => 25
  presc = ADCPrescTable[tmp]; //here ADCPrescTable is a table with 13 cases, and I try to read the 25 case!!!! //ADCPrescTable[13] = {0, 1, 2, 4, 6, 8, 10, 12, 16, 32, 64, 128, 256};
  if ((presc & 0x10) != 0) // so the test is false I go in the else part
  {
     /* ADC12CLK clock frequency is derived from PLL clock */
     RCC_Clocks->ADC12CLK_Frequency = pllclk / presc;
  }
  else
  {
   /* ADC12CLK clock frequency is AHB clock */
     RCC_Clocks->ADC12CLK_Frequency = RCC_Clocks->SYSCLK_Frequency; //same frequency as before 48MHz
  }


My first opinion , I think the mask is wrong RCC_CFGR2_ADCPRE12 the value is 0x1F0 I think with 0xF0 it's best but not perfect...

so I could have an information about that,  maybe I don't use correctly the ADC/RCC function

thanks a lot

Outcomes