Can Anyone tell me the clock initiating sequence with code? I am getting problems.

  • 5
  • madhu
    /* Resets the clock configuration /
    RCM_Reset();
    /
    Set if necessary /
    //RCM_SetHSITrim(8);
    RCM_EnableHSI(); // HSI freq: 8MHz
    /
    Directly set to SYSCLK = 8MHz /
    RCM_ConfigSYSCLK(RCM_SYSCLK_SEL_HSI);
    /
    Set HCLK (includes GPIO & DMA) /
    /
    To ensure real-time data transmission,GPIO clock frequency cannot be divided /
    /
    HCLK = SYSCLK / 2 = 4MHz/
    RCM_ConfigAHB(RCM_SYSCLK_DIV_2);
    /
    Set APBCLK (ADC) /
    /
    APBCLK = HCLK / 1 = 4MHz */
    RCM_ConfigAPB(RCM_HCLK_DIV_1);

    /* Set when initialize ADC sequance /
    /
    ADCCLK = APBCLK / 2 = 2MHz */
    ADC_ClockMode(ADC_CLOCK_MODE_SYNCLKDIV2);

    [unknown] Please provide more information. Does your ADC signal input section have a filtering capacitor?

    [unknown] Please provide more information. Does your ADC signal input section have a filtering capacitor?

    [unknown] Please provide more information. Does your ADC signal input section have a filtering capacitor?

Hi madhu,
As for the clock initiating sequence, you can find RCC configuration (termed RCM in Geehy’s SDK) in the file apm32f0xx.c. Additionally, check the SDK/Example/RCM for an example program that includes a macro for setting the clock such as SystemClock_PLL_Init() and SystemClock_HSI_Init().
It’s worth noting that if you are intended to use HSI, you will need to adjust clock multiplication and division settings in apm32f0xx.c. If you are using HSE, the process would be easier—change a few parameters and you should be set.

    John573

    sample-code-with-clcok-initialized.zip
    204kB

    i tried to mail this code. but it was failing. please check this is this ok? it is written in keil v5.39.0.0

      madhu Based on the information you provided, it appears that the method used for your power supply might be causing the voltage drop issues.
      The series resistance approach does not provide sufficient current, which can also result in a voltage drop, especially under varying load conditions.
      So it is recommended to use LDOs (Low Dropout Regulator) as your power supply needs since it provides cleaner output with minimal ripple and more stable current, or, any other stable power supply would also be suitable.
      I have reviewed your code. There seems to be no issue with the initialization of the ADC and GPIO in the code you provided. However, ‘system_apm32f0xx.c’ contains initialization code that is executed automatically at startup and doesn’t need to be explicitly called again in ‘main.c’. On the other hand, the functions in ‘apm32f0xx_rcm.c’ provide methods to modify the clock settings within user code. Please take a closer look at the examples provided in the SDK folder for ideas on how to modify the clock settings.

      madhu Following steps might help you configuring system clock:

      1. Enable HSI;
      2. Select HSI as the PLL clock source;
      3. Configure PLL multiplication and division factors;
      4. Select PLL as the system clock source;
      5. Configure the division factors for the peripheral bus.
      RCM_SetHSITrim(8);
      RCM_EnableHSI();
      RCM_ConfigCLKDIV(1);
      RCM->CTRL1_B.PLLEN = BIT_RESET;
      while(RCM->CTRL1_B.PLLRDYFLG);
      RCM->CFG1_B.PLLMULCFG =1;
      RCM->CFG1_B.SCLKSEL = 2;
      RCM->CFG1_B.AHBPSC = 2;
      RCM->CFG1_B.APB1PSC =2;
      RCM->CFG1_B.ADCPSC = 1;
      RCM_ConfigPLL(RCM_PLL_SEL_HSI, 1);
      RCM_EnablePLL();

      SIR IS THIS CORRECT? for all peripherals DMA, GPIO, FMC and ADC. i want to set for ahb 4 mhz and 2 mhz for gpio and ADC

        and another problem is coming adc voltage and adc value is jumping too much

        madhu
        /* Resets the clock configuration /
        RCM_Reset();
        /
        Set if necessary /
        //RCM_SetHSITrim(8);
        RCM_EnableHSI(); // HSI freq: 8MHz
        /
        Directly set to SYSCLK = 8MHz /
        RCM_ConfigSYSCLK(RCM_SYSCLK_SEL_HSI);
        /
        Set HCLK (includes GPIO & DMA) /
        /
        To ensure real-time data transmission,GPIO clock frequency cannot be divided /
        /
        HCLK = SYSCLK / 2 = 4MHz/
        RCM_ConfigAHB(RCM_SYSCLK_DIV_2);
        /
        Set APBCLK (ADC) /
        /
        APBCLK = HCLK / 1 = 4MHz */
        RCM_ConfigAPB(RCM_HCLK_DIV_1);

        /* Set when initialize ADC sequance /
        /
        ADCCLK = APBCLK / 2 = 2MHz */
        ADC_ClockMode(ADC_CLOCK_MODE_SYNCLKDIV2);

        [unknown] Please provide more information. Does your ADC signal input section have a filtering capacitor?

        [unknown] Please provide more information. Does your ADC signal input section have a filtering capacitor?

        [unknown] Please provide more information. Does your ADC signal input section have a filtering capacitor?

          madhu Please use an oscilloscope to test if there is any jumping at the ADC pins.

          madhu Do you have any real-time talking app? This would make communication more convenient. And, based on your situation, It is suggested to build your application on the foundation of our official examples. This will make troubleshooting easier.

          Thank you sir for guidence. this solved my problem.

          Sir one more question now adc voltage isnot varying too much but adc value is varying.