Reputation: 21
I'm new to STM32, and I use STM32L476 I programmed a UART communication using CubeIDE, and I tried to use inverse convetion so the MSB will be first, instead the default convention which is the LSB first. I configured the UART as the following:
static void UART_Init(void)
{
/* Peripheral clock enable */
__HAL_RCC_USART1_CLK_ENABLE();
huart1.Instance = USART1;
huart1.Init.BaudRate = 9600;
huart1.Init.Mode = UART_MODE_TX_RX;
huart1.Init.Parity = UART_PARITY_EVEN;
huart1.Init.StopBits = UART_STOPBITS_1;
huart1.Init.OverSampling = UART_OVERSAMPLING_16;
huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
huart1.Init.WordLength = UART_WORDLENGTH_8B;
huart1.AdvancedInit.MSBFirst = UART_ADVFEATURE_MSBFIRST_ENABLE;
huart1.AdvancedInit.DataInvert = UART_ADVFEATURE_DATAINV_ENABLE;
if (HAL_UART_Init(&huart1) != HAL_OK)
{
while(1);
}
}
I using scope, and see that the data is transmitted in direct convention (LSB first).
Can someone help me, to solve this issue?
Thanks in advance.
Upvotes: 0
Views: 672
Reputation: 21
To solve this issue, we need to add the followingl line:
huart1.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_MSBFIRST_INIT;
There is no need for the line:
huart1.AdvancedInit.DataInvert = UART_ADVFEATURE_DATAINV_ENABLE;
It works properly without it.
Upvotes: 0