My doubt is about the way in which the baudrate value is written into UBRRn registers.
Lets say i want to write the value 25 into UBBRn registers to configure the microcontroller to communicate at a particular baud rate.
I use the following code to do that
unsigned int ubrr = 25; // 0000 0000 0001 1001 (16 bit binary representation) UBRR0H = (ubrr>>8); // Moving the lower Byte 0001 1001 to UBRR0H UBRR0L = (ubrr); // Moving 0000 0000 to UBRR0L
Why are we moving the lower byte to the high register UBRR0H and the higher byte to UBRR0L (after shifting).
Generally when we are moving a 16 bit value to two 8 bit registers,
- The Lower byte will be moved to the Lower register (UBRR0L) and
- Higher byte will be moved to the High register (UBRR0H)
Why is ATmega328p reversing this trend,
Is this a design issue,or there is any specific reason to do this ?
Also UBBR0H has only 4 bits and the upper nibble will be discarded ?
I would like to point out the default code in the datasheet is working perfectly for me,I am just curious why it is done like that?