cancel
Showing results for 
Search instead for 
Did you mean: 

Uart parity issue.

Scott Dev
Senior

Hi,

I am running a STML433 with external xtal. I have a serial port that works fine when I set the parity to NONE (I set the port to 9600 baud No parity 8bits 1stop bit). And works well , as expected. I have to set it to parity even (set to 9600 baud Even parity 8n bits 1 stop bit), so I set the register as follows:

USARTx->CR1 |= USART_CR1_PCE;// set parity

 USARTx->CR1 &= ~USART_CR1_PS;// even parity

everything else in the uart is the same. But I dont get the correct info coming out of the serial port, the only way is if I set the terminal window on the receiving side to E 7 bits and 2 stop bits , which isnt any use. My complete setup is:

USARTx->CR1 &= ~USART_CR1_UE; //disable uart

   USARTx->CR1 &= ~USART_CR1_M;// 8 bits

   USARTx->CR2 &= ~USART_CR2_STOP;// 1 stop bit

   if(Parity==NO_PARITY)

   USARTx->CR1 &= ~USART_CR1_PCE;// no parity

   else

   {

      //even only other option at the moment

      USARTx->CR1 |= USART_CR1_PCE;// set parity

      USARTx->CR1 &= ~USART_CR1_PS;// even parity

   }

   USARTx->CR1 &= ~USART_CR1_OVER8; //oversample

   USARTx->BRR = 1666;

Anyone let me know what I am doing wrong? I am running the clock at 16MHz.

Many thanks

Scott

1 ACCEPTED SOLUTION

Accepted Solutions
Dvorak.Peter
Senior II

Try the cubemx initialization.

USARTx->CR1 &= ~USART_CR1_M;// 8 bits

with parity set to 9 bits

View solution in original post

4 REPLIES 4
Dvorak.Peter
Senior II

Try the cubemx initialization.

USARTx->CR1 &= ~USART_CR1_M;// 8 bits

with parity set to 9 bits

Alex R
Senior

Do you have a logic analyzer (or oscilloscope) that can capture the raw data coming out of the serial port?

Have you measured the bit length, number of bits, etc?

Do you have matching settings on the receive side (9600, 8 bit, Even Parity, 1 stop bit)?

What kind of error you get when if fails? (Failed parity, overrun)?

Hi

This worked. I never realised I had to set to 9 bits if I wanted parity.

Many Thanks

Scott

Well the bit count includes parity in ST's U(S)ART implementation 7E1 would be 8-bit 8On1 would be 9-bit, for example. They also use 9-bit for "multi-processor communication" mode or whatever hack the 8051 used.

When reading the DR directly, mask the bits you want to see/remove

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