2023-03-30 05:42 PM
I am attempting to configure the UART2 peripheral of the STM8S105C4 MCU with an even parity control using this development environment: ST Visual Develop, ST Visual Programmer, STM8 Cosmic compiler, Library: STM8 Standard Peripheral Library (SPL).
Problem: No parity bit generated, as shown by the Logic8 logic analyzer. See the below screenshot: the parity bit is configured but is missing in the signal.
Question: why is the Parity Control not working? The following SPL function UART_Config() should configure one even parity bit per byte.
Thank you!
static void UART_Config(void)
{
/* UART2 configured as follow:
- BaudRate = 38400
- Word Length = 8 Bits
- Two Stop Bit
- One parity bit (even)
- Receive and transmit enabled
*/
UART2_DeInit();
UART2_Init((uint32_t) 38400, UART2_WORDLENGTH_8D,
UART2_STOPBITS_2, UART2_PARITY_EVEN,
UART2_SYNCMODE_CLOCK_DISABLE, UART2_MODE_TXRX_ENABLE);
/* UART2: Disable the Receive interrupt: */
/* RXNE - Received data ready to be read */
/* OR - Overrun error detected */
UART2_ITConfig(UART2_IT_RXNE_OR, DISABLE);
/* UART2: Disable the Transmit interrupt: */
/* TXE - Transmit buffer not empty, still transmitting */
UART2_ITConfig(UART2_IT_TXE, DISABLE);
/* Enable general interrupts */
enableInterrupts();
/* Enable UART Half Duplex Mode (NOT AVAILABLE FOR UART2) */
//UART2_HalfDuplexCmd(ENABLE);
/* Enable UART2 communication */
UART2_Cmd(ENABLE);
}
Solved! Go to Solution.
2023-03-30 07:48 PM
Thank you @Community member, that also works for the STM8S MCU.
The only required change was to increase the UART word length from 8 to 9 bits, because:
UART word length = 8 Data bits + 1 Parity bit = 9 bits.
Updated the function UART_Config():
2023-03-30 07:02 PM
On the STM32 you have to select 9-bit mode to account for the parity bit in the counts, not sure about the STM8 but they share common lineage.
2023-03-30 07:48 PM
Thank you @Community member, that also works for the STM8S MCU.
The only required change was to increase the UART word length from 8 to 9 bits, because:
UART word length = 8 Data bits + 1 Parity bit = 9 bits.
Updated the function UART_Config():