AnsweredAssumed Answered

Getting Started with PLL and USART3--STM32F100C8

Question asked by dsouza.hansen.001 on Apr 10, 2012
Latest reply on Apr 12, 2012 by dsouza.hansen.001
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

Outcomes