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
}
Arduino Uart Parity
-
Alan_37
- Posts: 205
- http://meble-kuchenne.info.pl
- Joined: Thu Dec 03, 2020 7:23 pm
- Has thanked: 57 times
- Been thanked: 28 times
-
mnfisher
- Valued Contributor
- Posts: 2174
- Joined: Wed Dec 09, 2020 9:37 pm
- Has thanked: 177 times
- Been thanked: 1016 times
Re: Arduino Uart Parity
From the datasheet:
So you need to set bits 4 and 5 correctly,
UCSR0C |= 1 << UPM01; // Set UPM01 to 1
UCSR0C &= ~(1 << UPM00); // Clear UPM00
Martin
So you need to set bits 4 and 5 correctly,
UCSR0C |= 1 << UPM01; // Set UPM01 to 1
UCSR0C &= ~(1 << UPM00); // Clear UPM00
Martin
-
mnfisher
- Valued Contributor
- Posts: 2174
- Joined: Wed Dec 09, 2020 9:37 pm
- Has thanked: 177 times
- Been thanked: 1016 times
Re: Arduino Uart Parity
Maybe - you'll probably need to check the UPE flag in UCSR0A to check for errors? If it works 
-
mnfisher
- Valued Contributor
- Posts: 2174
- Joined: Wed Dec 09, 2020 9:37 pm
- Has thanked: 177 times
- Been thanked: 1016 times