STM8 UART2, Adding a parity bit to UART packet
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2023-03-30 5: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.
- Labels:
-
UART-USART
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2023-03-30 7: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():
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2023-03-30 7: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.
Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2023-03-30 7: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():
