UART Oversampling 8 and 16
STM32 experts,
I bought 2xNUCLEO-F042K6 for testing purposes.
Reference manual says that uart speed at oversampling 16 is 3mbit/s, for oversampling 8 is 6mbit/s.
Here is my working configuration. I send 100 bytes data at 3mbit/s and oversampling 16 from first nucleo to the second nucleo board:
huart1.Instance = USART1;
huart1.Init.BaudRate = 3000000;
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(__FILE__, __LINE__);
}everything works fine.
But...
When I change to 6mbit/s and oversampling 8 not all data is received. Above 3mbit/s data is corrupted.
huart1.Instance = USART1;
huart1.Init.BaudRate = 6000000;
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_8;
huart1.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
huart1.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
if (HAL_UART_Init(&huart1) != HAL_OK)
{
_Error_Handler(__FILE__, __LINE__);
}Default nucleo configuration made by CubeMX. Clock configuration:
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
RCC_OscInitStruct.HSICalibrationValue = 16;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL6;
RCC_OscInitStruct.PLL.PREDIV = RCC_PREDIV_DIV1;
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
{
_Error_Handler(__FILE__, __LINE__);
}Do I need some external oscilator?
Data cable lenght: 10cm
//sending
if(HAL_UART_Transmit_IT(&huart1, (uint8_t*)data, 100)!= HAL_OK)
{
while(1)
{}
}
HAL_Delay(100);
//receiving
if(HAL_UART_Receive_IT(&huart1, (uint8_t*)data, 100)!= HAL_OK)
{
while(1)
{}
}
HAL_Delay(50);