cancel
Showing results for 
Search instead for 
Did you mean: 

Getting Started with PLL and USART3--STM32F100C8

hansen
Associate II
Posted on April 10, 2012 at 08:12

Hi,

I am having difficulty getting sysclock to work at 24Mhz using HSI and PLL.

I am also facing difficulty in getting USART3 to transmit something.I have seen and tried what other members on this forum , with similar situation did but have not able to get it to work for me.

I am looking forward to your suggestions if I missed out anything.Thanks

//main starts here

RCC_ClocksTypeDef RCC_Clocks;

RCC_HSICmd(ENABLE);

/* HCLK = SYSCLK */

RCC_HCLKConfig(RCC_SYSCLK_Div1); 

/* PCLK2 = HCLK */

RCC_PCLK2Config(RCC_HCLK_Div1); 

/* PCLK1 = HCLK */

RCC_PCLK1Config(RCC_HCLK_Div1);

RCC_PLLConfig(RCC_PLLSource_HSI_Div2, 6);

/* Enable PLL */ 

RCC_PLLCmd(ENABLE);

/* Wait till PLL is ready */

while (RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET);

RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);

while (RCC_GetSYSCLKSource() != 0x08);

RCC_GetClocksFreq(&RCC_Clocks); //SYS clock is still 8mhz.

//Starting USART 3 below

/* Enable GPIOx Clock */

  RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);

RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO| RCC_APB2Periph_GPIOB, ENABLE);  

  GPIO_InitTypeDef  GPIO_InitStructure;   

  USART_InitTypeDef USART_InitStructure;   

  USART_ClockInitTypeDef USART_ClockInitStructure;

  RCC_APB1PeriphResetCmd(RCC_APB1Periph_USART3, ENABLE);

  /* Configure USART3 Rx (PB11) as input floating                             */   

  GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_11;   

  GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_IN_FLOATING; 

  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;     

  GPIO_Init(GPIOB, &GPIO_InitStructure);   

   

  /* Configure USART3 Tx (PB10) as alternate function push-pull                */   

  GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_10;   

  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;   

  GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_AF_PP; 

  GPIO_Init(GPIOB, &GPIO_InitStructure);   

USART_ClockStructInit(&USART_ClockInitStructure);

USART_ClockInit(USART3,&USART_ClockInitStructure);

USART_StructInit(&USART_InitStructure);  

USART_Init(USART3, &USART_InitStructure);

 USART_Cmd(USART3, ENABLE);   

USART_SendData(USART3, 'B'); 

while (!USART_GetFlagStatus(USART3,USART_FLAG_TXE)); //execution loops here forever

#stm32f100
8 REPLIES 8
domen23
Associate II
Posted on April 10, 2012 at 10:46

You're only resetting, not enabling USART3 clock.

hansen
Associate II
Posted on April 10, 2012 at 13:26

Hi,

Thanks Domen, I called the function RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3,Enable);

and it is working now.

Can you please also see if  I'm missing out something in the PLL initialization

Im using HSI/2 as the clock input to the PLL and then mutiplying it by 6 to get 24Mhz.

But calling RCC_GetClocksFreq(&RCC_Clocks); reveals SYSCLOCK is 8Mhz

Regards,

Hansen

Posted on April 10, 2012 at 17:54

RCC_PLLConfig(RCC_PLLSource_HSI_Div2, RCC_PLLMul_6);

RCC_PLLMul_6 = 0x00100000, ie NOT 6

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
hansen
Associate II
Posted on April 11, 2012 at 11:43

Hi,

Thanks Clive , I replaced 6 with the correct library reference but I'm still getting 8MHz

Can you please take a look again 

RCC_ClocksTypeDef RCC_Clocks;

RCC_HSICmd(ENABLE);

/* Enable PLL */ 

RCC_PLLCmd(ENABLE);

RCC_PLLConfig(RCC_PLLSource_HSI_Div2, RCC_PLLMul_6);

/* Wait till PLL is ready */

while (RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET)

{

}

/* Select PLL as system clock source */

RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);

/* Wait till PLL is used as system clock source */

while (RCC_GetSYSCLKSource() != 0x08)

{

}

/* HCLK = SYSCLK */

RCC_HCLKConfig(RCC_SYSCLK_Div1); 

/* PCLK2 = HCLK */

RCC_PCLK2Config(RCC_HCLK_Div1); 

/* PCLK1 = HCLK */

RCC_PCLK1Config(RCC_HCLK_Div1);

RCC_GetClocksFreq(&RCC_Clocks);//SYSCLOCK is still 8Mhz at this point

hansen
Associate II
Posted on April 11, 2012 at 11:48

Hi,

I was supposed to RCC_PLLcmd(Enable) after RCC_PllConfig(....)

Its working now at 24 Mhz

Thanks all for helping me out.

Regards,

Hansen

hansen
Associate II
Posted on April 11, 2012 at 11:58

Hi

Im able to run the sysclock at 56Mhz by pll..wow..Uart and GPIO are working fine.Has anyone tried this?

Regards,

Posted on April 11, 2012 at 20:07

Im able to run the sysclock at 56Mhz by pll..wow..Uart and GPIO are working fine.Has anyone tried this?

 

I've run some at 32 MHz without issues, beyond that I'm pretty sure you'd need to add FLASH wait states.

I also have F205 parts with more RAM and FLASH memory than specified. These are fun to test in the lab, but something I would avoid in shipping product.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
hansen
Associate II
Posted on April 12, 2012 at 07:32

Hi,

Yes maybe it does need flash wait cycles because it just stops sometimes.I will just run it at 24Mhz for now

Thanks,

Hansen