cancel
Showing results for 
Search instead for 
Did you mean: 

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.

lernd
Associate II

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);

}

5 REPLIES 5
AME MCU SM
ST Employee

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.

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.

My std code use

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

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
Up vote any posts that you find helpful, it shows what's working..

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

now my code is working.