Skip to main content
lernd
Associate II
December 29, 2021
Question

I am using STM32F030C6T6 I am unable to configure usart1 in the code. None of the registers get configured for usart1 below is the code Please Help. I am using Standard Peripheral Libraries.

  • December 29, 2021
  • 5 replies
  • 2080 views

void RCC_Configuration(void)

  RCC_DeInit();

  //RCC_AdjustHSICalibrationValue(0x00);

  RCC_HSICmd(ENABLE);

  while(RCC_GetFlagStatus(RCC_FLAG_HSIRDY) == RESET)

    {;}

  //PLL out = (8M/2)*12 = 48 MHz

  RCC_PLLConfig(RCC_PLLSource_HSI_Div2,RCC_PLLMul_12);

  RCC_PLLCmd(ENABLE);

  while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET)

    {;}

    

  FLASH_PrefetchBufferCmd(ENABLE);

  FLASH_SetLatency(FLASH_Latency_1);

  //SYSclk = PLL clk

  RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);

  while(RCC_GetSYSCLKSource() != 0x08)//if PLL used as system clock

    {;}

  //HCLK = SYSCLK/1=48MHz

  RCC_HCLKConfig(RCC_SYSCLK_Div1);

  RCC_PCLKConfig(RCC_HCLK_Div1);//48MHz

    

  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);

  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE);

  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOC, ENABLE);

  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOF, ENABLE);

  RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);  

 }

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

 void USART_Config(void)

{

  USART_DeInit(USART1);

  RCC_APB2PeriphResetCmd(RCC_APB2Periph_USART1, ENABLE);

  GPIO_PinAFConfig(GPIOA, GPIO_PinSource2, GPIO_AF_0);

  GPIO_PinAFConfig(GPIOA, GPIO_PinSource3, GPIO_AF_0);

  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;

  GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;

  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_Level_3;

  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;

  GPIO_InitStructure.GPIO_Pin = TX_485_PIN;

  GPIO_Init(TX_485_PORT, &GPIO_InitStructure);

  GPIO_InitStructure.GPIO_Pin = RX_485_PIN;

  GPIO_Init(RX_485_PORT, &GPIO_InitStructure);

  USART_OverSampling8Cmd(USART1, DISABLE);

  USART_OneBitMethodCmd (USART1, DISABLE);

  USART_InitStructure.USART_BaudRate = 9600;

  USART_InitStructure.USART_WordLength = USART_WordLength_8b;

  USART_InitStructure.USART_StopBits = USART_StopBits_1;

  USART_InitStructure.USART_Parity = USART_Parity_No;

  USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;

  USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;

  USART_Init(USART1, &USART_InitStructure);

  // USART enable

  USART_Cmd(USART1, ENABLE);

  USART_ITConfig(USART1,USART_IT_TXE , DISABLE);

  USART_ITConfig(USART1,USART_IT_RXNE , ENABLE);

  USART_ITConfig(USART1,USART_IT_TC , ENABLE);

}

This topic has been closed for replies.

5 replies

AME MCU SM
ST Employee
December 29, 2021

Are you strapped to using the standard peripheral library, why not use STM32CubeMX? We also have HAL based examples for a similar MCU here: STM32CubeF0/Projects/STM32F030R8-Nucleo/Examples/UART at master · STMicroelectronics/STM32CubeF0 · GitHub

If the registers are not being configured as you say then make sure you're are providing clock to the peripheral you're wanting to use.

lernd
lerndAuthor
Associate II
December 29, 2021

I HAVE ENABLED

RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);  

Some other clock have to be enabled ?

with Stmcube it works but i have to do with standard peripheral library

i am not using cube.

MM..1
Super User
December 29, 2021

My std code use

 // Enable USART clock
 USART1_APBPERIPHCLOCK(USART1_CLK, ENABLE);

Tesla DeLorean
Guru
December 29, 2021

You are holding the USART in reset, don't do that or understand the correct mechanics.​

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
lernd
lerndAuthor
Associate II
December 30, 2021

Thank you For correction .I have Put Reset instruction by mistake,

now my code is working.