cancel
Showing results for 
Search instead for 
Did you mean: 

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 CubeMX.

JK.4
Associate II
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 */
  }
 
}

3 REPLIES 3

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

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
Senior III

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.