STM32L151CBU UART 8E1 (Parity) Problem
Hello everyone,
I have created a project with STM32L151CBU and used UART2 (PA2, PA3) for communication with some other transceiver IC.
I have configured my UART as follows for (1-bit start, 8 bits data, 1 bit EVEN parity, and 1 bit stop) communication.
/** USART2 GPIO Configuration
* PA1 ------> USART2_RTS
* PA2 ------> USART2_TX
* PA3 ------> USART2_RX
*/
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pin = IOLink_TxEn_Pin;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Alternate = GPIO_AF7_USART2;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStruct.Pin = IOLink_Tx_Pin | IOLink_Rx_Pin;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
/* USART2 interrupt Init */
HAL_NVIC_SetPriority(USART2_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(USART2_IRQn);
huart2.Init.BaudRate = 38400;
huart2.Instance = USART2;
huart2.Init.Mode = UART_MODE_TX_RX;
huart2.Init.StopBits = UART_STOPBITS_1;
huart2.Init.Parity = UART_PARITY_EVEN;
huart2.Init.WordLength = UART_WORDLENGTH_9B;
huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE;
huart2.Init.OverSampling = UART_OVERSAMPLING_16;
HAL_UART_Init(&huart2);
I have also enabled the receive interrupt and I am getting some data but that is the problem.
Normally I should receive 0xA2, but I am getting sometimes 0x1FD, and mostly 0x69.
The 0x1FD is ok and normal. Because my transmitter device is tries to send 3 different baud rate. When transmits first baud rate data 0xA2, it means in 38400 baud 0x1FD (including parity). But I don't know about the 0x69.
When try to receive or transmit same data from F0 mcu, there is no problem. But I could not successfully receive with this mcu.
By the way, I am checking the data from mcu's rx pin with logic analyzer and everything is as it is.
What is wrong here? What am I missing?
