Skip to main content
yogui_ricardo
Associate III
June 26, 2024
Solved

usart3 on nucleo-h753 not work fine

  • June 26, 2024
  • 2 replies
  • 1733 views

I have been trying to transmit and receive from putty through the USB virtual com (CN1) of the core board, I tried with different baud rates and the result is always the same, garbage arrives at the putty, and I am not receiving anything either, it is my configuration and tks in advance =  

static void MX_USART3_UART_Init(void)

{ huart3.Instance = USART3;

 

huart3.Init.BaudRate = 115200;

huart3.Init.WordLength = UART_WORDLENGTH_8B;

huart3.Init.StopBits = UART_STOPBITS_1;

huart3.Init.Parity = UART_PARITY_NONE;

huart3.Init.Mode = UART_MODE_TX_RX;

huart3.Init.HwFlowCtl = UART_HWCONTROL_NONE;

huart3.Init.OverSampling = UART_OVERSAMPLING_16;

huart3.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;

huart3.Init.ClockPrescaler = UART_PRESCALER_DIV1;

huart3.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_MSBFIRST_INIT;

huart3.AdvancedInit.MSBFirst = UART_ADVFEATURE_MSBFIRST_ENABLE;

if (HAL_UART_Init(&huart3) != HAL_OK)

{

Error_Handler();

}

if (HAL_UARTEx_SetTxFifoThreshold(&huart3, UART_TXFIFO_THRESHOLD_1_8) != HAL_OK)

{

Error_Handler();

}

if (HAL_UARTEx_SetRxFifoThreshold(&huart3, UART_RXFIFO_THRESHOLD_1_8) != HAL_OK)

{

Error_Handler();

}

if (HAL_UARTEx_DisableFifoMode(&huart3) != HAL_OK)

{

Error_Handler();

}

}

Call to send

void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) //

{

if(htim->Instance == TIM1)

{

cada2segundos();

}

}

 

void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart) {

if (huart->Instance == USART3) {

HAL_GPIO_TogglePin(GPIOB, LD1_Pin);

}

}

 

 

void cada2segundos(void)

{

HAL_GPIO_TogglePin(GPIOE, LD2_Pin);// ambar

HAL_UART_Receive_DMA(&huart3, rx_buffer,RX_BUFFER_SIZE);

uint8_t mensaje[] = "Hola de nuevo";

HAL_UART_Transmit_IT(&huart3, mensaje, sizeof(mensaje) - 1);

}

 

 

Best answer by yogui_ricardo

The problem was the clock configuration, I had done some tests with the callback at different mhz.

Tks  (i´m new in stm32 family)

2 replies

Tesla DeLorean
Guru
June 26, 2024

Show the MSP code that initializes the clocks and the GPIOs

NUCLEO-H753ZI

Should be using USART3 PD8 / PD9 provided SB12 and SB19 are intact

Serial is typically LSB first!!

huart3.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_MSBFIRST_INIT; // ??

Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
Tesla DeLorean
Guru
June 26, 2024
//****************************************************************************

void USART3_Init(uint32_t BaudRate) // TX/RX VCP NUCLEO-H753ZI
{
 GPIO_InitTypeDef GPIO_InitStruct = {0};
 UART_HandleTypeDef UartHandle = {0};

 __USART3_CLK_ENABLE();
 __GPIOD_CLK_ENABLE();

 /* UART RX/TX GPIO pin configuration */
 GPIO_InitStruct.Pin = GPIO_PIN_8 | GPIO_PIN_9;
 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
 GPIO_InitStruct.Pull = GPIO_PULLUP;
 GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
 GPIO_InitStruct.Alternate = GPIO_AF7_USART3;

 HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);

 /*## Configure the UART peripheral ######################################*/
 /* Put the USART peripheral in the Asynchronous mode (UART Mode) */
 /* USART3 configured as follow:
 - Word Length = 8 Bits
 - Stop Bit = One Stop bit
 - Parity = NO parity
 - BaudRate = 115200 baud
 - Hardware flow control disabled (RTS and CTS signals) */
 UartHandle.Instance = USART3;

 UartHandle.Init.BaudRate = BaudRate;
 UartHandle.Init.WordLength = UART_WORDLENGTH_8B;
 UartHandle.Init.StopBits = UART_STOPBITS_1;
 UartHandle.Init.Parity = UART_PARITY_NONE;
 UartHandle.Init.HwFlowCtl = UART_HWCONTROL_NONE;
 UartHandle.Init.Mode = UART_MODE_TX_RX;

 UartHandle.Init.OverSampling = UART_OVERSAMPLING_16;
#ifdef UART_ONE_BIT_SAMPLE_DISABLE
 UartHandle.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
#endif

 if (HAL_UART_Init(&UartHandle) != HAL_OK)
 {
 /* Initialization Error */
 Error_Handler();
 }

 HAL_NVIC_SetPriority(USART3_IRQn, 1, 0);
 HAL_NVIC_EnableIRQ(USART3_IRQn);
}

//****************************************************************************
Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
mƎALLEm
Technical Moderator
June 26, 2024

Hello and welcome to the community.

First I suggest you to read these recommandations about how to pot a thread on this community: https://community.st.com/t5/community-guidelines/how-to-write-your-question-to-maximize-your-chances-to-find-a/ta-p/575228

Secont I'm wondering why are you using a timer to send your string at this level? What about the periodicity of the timer IT?

Did you try to send the string once? I suggest you to inspire from this "printf" example over UART: https://github.com/STMicroelectronics/STM32CubeH7/tree/master/Projects/STM32H743I-EVAL/Examples/UART/UART_Printf

To give better visibility on the answered topics, please click "Best answer" on the reply which solved your issue or answered your question.