2024-06-18 02:44 AM - last edited on 2024-06-26 01:02 AM by SofLit
Hi
i am receive data using UART 4 and transfer same data back like loopback but data is mismatch.
same process in stm32f207 is working,
#include "main.h"
UART_HandleTypeDef huart4;
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_UART4_Init(void);
int main(void)
{
char rx_buffer[10]={0};
HAL_Init();
SystemClock_Config();
MX_GPIO_Init();
MX_UART4_Init();
while (1)
{
HAL_UART_Receive(&huart4, rx_buffer, 10, 1000);
HAL_Delay(100);
HAL_UART_Transmit(&huart4, rx_buffer, 10, 100);
// HAL_Delay(1000);
}
/* USER CODE END 3 */
}
void SystemClock_Config(void)
{
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
/** Supply configuration update enable
*/
HAL_PWREx_ConfigSupply(PWR_LDO_SUPPLY);
/** Configure the main internal regulator output voltage
*/
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE2);
while(!__HAL_PWR_GET_FLAG(PWR_FLAG_VOSRDY)) {}
/** Initializes the RCC Oscillators according to the specified parameters
* in the RCC_OscInitTypeDef structure.
*/
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
RCC_OscInitStruct.HSIState = RCC_HSI_DIV1;
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
{
Error_Handler();
}
/** Initializes the CPU, AHB and APB buses clocks
*/
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2
|RCC_CLOCKTYPE_D3PCLK1|RCC_CLOCKTYPE_D1PCLK1;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI;
RCC_ClkInitStruct.SYSCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.AHBCLKDivider = RCC_HCLK_DIV1;
RCC_ClkInitStruct.APB3CLKDivider = RCC_APB3_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_APB1_DIV1;
RCC_ClkInitStruct.APB2CLKDivider = RCC_APB2_DIV1;
RCC_ClkInitStruct.APB4CLKDivider = RCC_APB4_DIV1;
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1) != HAL_OK)
{
Error_Handler();
}
}
static void MX_UART4_Init(void)
{
/* USER CODE END UART4_Init 1 */
huart4.Instance = UART4;
huart4.Init.BaudRate = 115200;
huart4.Init.WordLength = UART_WORDLENGTH_8B;
huart4.Init.StopBits = UART_STOPBITS_1;
huart4.Init.Parity = UART_PARITY_NONE;
huart4.Init.Mode = UART_MODE_TX_RX;
huart4.Init.HwFlowCtl = UART_HWCONTROL_NONE;
huart4.Init.OverSampling = UART_OVERSAMPLING_16;
huart4.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
huart4.Init.ClockPrescaler = UART_PRESCALER_DIV1;
huart4.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
if (HAL_UART_Init(&huart4) != HAL_OK)
{
Error_Handler();
}
if (HAL_UARTEx_SetTxFifoThreshold(&huart4, UART_TXFIFO_THRESHOLD_1_8) != HAL_OK)
{
Error_Handler();
}
if (HAL_UARTEx_SetRxFifoThreshold(&huart4, UART_RXFIFO_THRESHOLD_1_8) != HAL_OK)
{
Error_Handler();
}
if (HAL_UARTEx_DisableFifoMode(&huart4) != HAL_OK)
{
Error_Handler();
}
}
static void MX_GPIO_Init(void)
{
/* GPIO Ports Clock Enable */
__HAL_RCC_GPIOC_CLK_ENABLE();
__HAL_RCC_GPIOH_CLK_ENABLE();
__HAL_RCC_GPIOA_CLK_ENABLE();
/* USER CODE BEGIN MX_GPIO_Init_2 */
/* USER CODE END MX_GPIO_Init_2 */
}
void Error_Handler(void)
{
/* USER CODE BEGIN Error_Handler_Debug */
/* User can add his own implementation to report the HAL error return state */
__disable_irq();
while (1)
{
}
/* USER CODE END Error_Handler_Debug */
}
Solved! Go to Solution.
2024-07-24 02:57 AM - edited 2024-07-24 02:58 AM
@Naresh_ wrote:I am receive data using UART 4 and transfer same data back like loopback but data is mismatch.
The commonest reason for receiving "junk" characters is wrong baud rate:
Baud rate depends on your clock setup - so check that.
Use the debugger to check if the corruption happens on reception or transmission - or both!
@Naresh_ wrote:same process in stm32f207 is working,
So look carefully at the differences between those two systems.
Again, use the debugger to see what is happening in the stm32f207, and compare/contrast what is happening in the STM32H753 ...
2024-06-18 03:00 AM
Hello,
Please use the button </> to insert your code.
Please read these recommendations on how to post a thread: https://community.st.com/t5/community-guidelines/how-to-write-your-question-to-maximize-your-chances-to-find-a/ta-p/575228
Thank you for your understanding
2024-06-18 07:15 AM
try resetting the buffer after transfer, also why different delays?
If full data is not received than it wont be sent as expected. Use a debugger to check if you receive what you are expecting.
2024-06-26 12:42 AM
Hi
This is working in custom board but it's not working EVK board, what is issue?
Thank you
2024-07-24 02:43 AM
Hello,
@Naresh_ wrote:This is working in custom board but it's not working EVK board, what is issue?
Need to check your hardware differences on both boards: what is connected externally on UART4 pins apart of your looping-back wire?
2024-07-24 02:50 AM
Hi SofLit,
thank you quick response,
yes loop back is also requirement, but in receive side some data+ ACK is also loop back.
2024-07-24 02:55 AM
What do you mean by "ACK"?
Again check your HW and the differences between the boards on UART4_TX and UART4_RX pins
2024-07-24 02:57 AM - edited 2024-07-24 02:58 AM
@Naresh_ wrote:I am receive data using UART 4 and transfer same data back like loopback but data is mismatch.
The commonest reason for receiving "junk" characters is wrong baud rate:
Baud rate depends on your clock setup - so check that.
Use the debugger to check if the corruption happens on reception or transmission - or both!
@Naresh_ wrote:same process in stm32f207 is working,
So look carefully at the differences between those two systems.
Again, use the debugger to see what is happening in the stm32f207, and compare/contrast what is happening in the STM32H753 ...