Skip to main content
JK.4
Associate II
July 29, 2020
Question

Hi all, I am trying to get the USART1 working with STM32F072VB micro (only USART-1 and no other peripheral). At CubeMX, I have seleted PA9 and PA10 as the GPIO pins configured for USART-1 and have selected the NVIC option at USART configuration at Cu

  • July 29, 2020
  • 2 replies
  • 1465 views
huart1.Instance = USART1;
 huart1.Init.BaudRate = 9600;
 huart1.Init.WordLength = UART_WORDLENGTH_8B;
 huart1.Init.StopBits = UART_STOPBITS_1;
 huart1.Init.Parity = UART_PARITY_NONE;
 huart1.Init.Mode = UART_MODE_TX_RX;
 huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
 huart1.Init.OverSampling = UART_OVERSAMPLING_16;
 huart1.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
 huart1.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
 if (HAL_UART_Init(&huart1) != HAL_OK)
 {
 Error_Handler();
 }
void HAL_UART_MspInit(UART_HandleTypeDef* huart)
{
 GPIO_InitTypeDef GPIO_InitStruct = {0};
 if(huart->Instance==USART1)
 {
 /* USER CODE BEGIN USART1_MspInit 0 */
 
 /* USER CODE END USART1_MspInit 0 */
 /* Peripheral clock enable */
 __HAL_RCC_USART1_CLK_ENABLE();
 
 __HAL_RCC_GPIOA_CLK_ENABLE();
 /**USART1 GPIO Configuration 
 PA9 ------> USART1_TX
 PA10 ------> USART1_RX 
 */
 GPIO_InitStruct.Pin = GPIO_PIN_9|GPIO_PIN_10;
 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
 GPIO_InitStruct.Pull = GPIO_NOPULL;
 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
 GPIO_InitStruct.Alternate = GPIO_AF1_USART1;
 HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
 
 /* USART1 interrupt Init */
 HAL_NVIC_SetPriority(USART1_IRQn, 0, 0);
 HAL_NVIC_EnableIRQ(USART1_IRQn);
 /* USER CODE BEGIN USART1_MspInit 1 */
 
 /* USER CODE END USART1_MspInit 1 */
 }
 
}

This topic has been closed for replies.

2 replies

Tesla DeLorean
Guru
July 29, 2020

But how are you call this?

Can you output data in non IT modes?

What about IRQ Handler code and call backs?​

Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
JK.4
JK.4Author
Associate II
July 29, 2020

Can you output data in non IT modes?

We tried in interrupt mode only.

 HAL_UART_Receive_IT(&huart1,RX_DATA,1);

What about IRQ Handler code and call backs?​

void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart1)

{

  if (huart1->Instance == USART1){

      HAL_UART_Receive_IT(huart1,RX_DATA,1);

  }

}

We are able to send the data, but not able to receive.

prain
Visitor II
July 29, 2020

Previously I encountered the same problem. In my case the usart overrun flag was set and locked the entire RX facility. check your usart SR register when you unable to receive. maybe your case is similar to mine.