Associate III
February 9, 2019
Solved
Unable to set PLL as main clock derived from the HSI
- February 9, 2019
- 1 reply
- 2011 views
Hi All,
I am working with the STM32F302R8. I want to set the system clock as the PLL through derived from the HSI. I want a clock of 64MHz which I should have set through the appropriate registers.
I think I have set all I need however, after the RCC configration is done, the system clock switch status (SWS) in the RCC->CFGR register still indicates 0x00, initiating that the HSI is used as a clock directly.
I have a blinky at the end which currently the LED stays on while the code is running and never turns on when I am debugging.
#include "stm32f302x8.h"
int x =0;
void Delay (uint32_t nTime);
uint16_t ADC1ConvertedValue = 0;
uint16_t ADC1ConvertedVoltage = 0;
uint16_t calibration_value = 0;
volatile uint32_t TimingDelay = 0;
int init ()
{
//RCC->CR = 0x1; //HSI on
RCC->CFGR = 0x003C0002; //PLLSCr = HSI/2 , PLLMUL = x116 (62Mhz), PLL = sys clock
RCC->CR |= 0x01000000; //PLL on
RCC->AHBENR |= (1<<18); //Enabling AHB GPIOB
//RCC->AHBENR |= (1<<28); //Enabling ADC Clocks
// At this stage the microcontroller clock tree is already configured
// RCC->CFGR2 &= 0x00000013; //ADC12 clock diveded by 6
GPIOB->MODER |= 0x00000010; // PB2 Output
GPIOB->OSPEEDR |= 0x0; //Low speed output on all of port B
GPIOB->PUPDR |= 0x30; // PB2 pull down
GPIOB->MODER |= 0x0000000C; // GPIOB PB1 set to Analog Mode
GPIOB->PUPDR |= 0x0000000B; // GPIOB PB1 set to Pull dowm
return(0);
}
int main()
{
init();
while (1)
{
GPIOB->BSRR = (1<<2) ;
for ( x = 0; x<500000; x++);
GPIOB->BSRR = (1<<(2+16));
for ( x = 0; x<500000; x++);
}
}


