Arduino Uart Parity

For general Flowcode discussion that does not belong in the other sections.
Post Reply
Alan_37
Posts: 137
http://meble-kuchenne.info.pl
Joined: Thu Dec 03, 2020 7:23 pm
Has thanked: 41 times
Been thanked: 19 times

Arduino Uart Parity

Post by Alan_37 »

Hi

I need to to use the UART with even parity enabled on an Atmega328p
anyone know what C code I need to add please ?

Found the following on the web but don't know how to implement for flowcode
seems that register UCSR0C is responsible for parity but don't know how to .

void serial_init ( unsigned short ubrr ) {
UBRR0 = ubrr ; // Set baud rate
UCSR0B |= (1 << TXEN0 ); // Turn on transmitter
UCSR0B |= (1 << RXEN0 ); // Turn on receiver
UCSR0C = (3 << UCSZ00 ); // Set for async . operation , no parity ,
// one stop bit , 8 data bits
}

mnfisher
Valued Contributor
Posts: 988
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 106 times
Been thanked: 517 times

Re: Arduino Uart Parity

Post by mnfisher »

From the datasheet:
2023-11-22_21-12-56.jpg
2023-11-22_21-12-56.jpg (112.82 KiB) Viewed 3663 times
So you need to set bits 4 and 5 correctly,

UCSR0C |= 1 << UPM01; // Set UPM01 to 1
UCSR0C &= ~(1 << UPM00); // Clear UPM00


Martin

Alan_37
Posts: 137
Joined: Thu Dec 03, 2020 7:23 pm
Has thanked: 41 times
Been thanked: 19 times

Re: Arduino Uart Parity

Post by Alan_37 »

Hi Martin ,

Thanks for your fast reply , so I put the 2 lines in a c code
and put it after INIT uart is that right ?

I try it and let you know

Thanks again

mnfisher
Valued Contributor
Posts: 988
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 106 times
Been thanked: 517 times

Re: Arduino Uart Parity

Post by mnfisher »

Maybe - you'll probably need to check the UPE flag in UCSR0A to check for errors? If it works :-)

Alan_37
Posts: 137
Joined: Thu Dec 03, 2020 7:23 pm
Has thanked: 41 times
Been thanked: 19 times

Re: Arduino Uart Parity

Post by Alan_37 »

Hello Again ,

It works perfectly !! :)

Thanks so much for your help

mnfisher
Valued Contributor
Posts: 988
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 106 times
Been thanked: 517 times

Re: Arduino Uart Parity

Post by mnfisher »

That's great - thanks for the fast feedback too....

Post Reply