cancel
Showing results for 
Search instead for 
Did you mean: 

STM8 UART2, Adding a parity bit to UART packet

Kmax18
Senior

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!

0693W00000bhF8OQAU.png

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);
}

1 ACCEPTED SOLUTION

Accepted Solutions
Kmax18
Senior

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():

0693W00000bhLyGQAU.png

View solution in original post

2 REPLIES 2

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.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Kmax18
Senior

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():

0693W00000bhLyGQAU.png