7 years, 7 months ago.

Parity is not enabled

#include "mbed.h"

Serial uart(PA_9, PA_10);

int main()
{
    uart.baud(9600);
    uart.format(8, Serial::Even, 1);

    for (;;)
    {
        uart.puts("ABC");
        wait_ms(200);
    }
}

/media/uploads/matsujirushi/20170517a.png

Question relating to:

Affordable and flexible platform to ease prototyping using a STM32L476RGT6 microcontroller.

Maybe... NOT change M bits when parity enable. Look at Table 237 on RM0351 reference manual.

posted by Takashi Matsuoka 17 May 2017

1 Answer

7 years, 7 months ago.

Ok - the corrected code works but the right answer is posted here (see Jan's comments):

https://community.st.com/thread/39105-st32f302rc-usart-with-parity-not-working

#include "mbed.h"
 
Serial uart(PA_9, PA_10);
 
int main()
{
    uart.baud(9600);
    uart.format(8, uart::Even, 1); // see below
 
    for (;;)
    {
        uart.puts("ABC");
        wait_ms(200);
    }
}

Reference: http://www.st.com/content/ccc/resource/technical/document/reference_manual/02/35/09/0c/4f/f7/40/03/DM00083560.pdf/files/DM00083560.pdf/jcr:content/translations/en.DM00083560.pdf

See page 1308

E81 format = 8 bits (total) so 7 bits for DATA; Even parity = 8th bit; 1 stop bit. So use 7 Bit; Even Parity; 1 Stop bit in Teraterm to see "ABC"

To use 8 bits of data; Even parity; 1 stop bit -> you must use 9 bit mode for formatting

/media/uploads/juthi/mbed_9_bit.png

/media/uploads/juthi/mbed_8_bit.png

Really learned something new here about the STM USART - thanks for your question !!

I try that sample code, But compile error. "SerialParity" is incompatible parameter.

posted by Takashi Matsuoka 17 May 2017