I want to establish an USART communication between my Atmega32a chip and my computer but there's something I don't understand. As I read the datasheet the UBRR register is a 12 bit register but is split into two 8 bit registers:UBRRH which cointains the four most significant bits and the UBRRL which contains the eight least significant bits of the USART baud rate; My question is:Why I have to shift BAUD_PRESCALLER with 8 at right? I don't understand how this all works :( The example if BAUD_PRESCALLER is 120,in binary it would be:0b01111000 so 0b01111000>>8 = 0b00000000; => Am I wrong somewhere?
void USART_init(void)
{
UBRRH = (uint8_t)(BAUD_PRESCALLER>>8); <--- this line
UBRRL = (uint8_t)(BAUD_PRESCALLER); <-- and this line
UCSRB = (1<<RXEN)|(1<<TXEN);
UCSRC = (1<<UCSZ0)|(1<<UCSZ1)|(1<<URSEL);
}
UBBRL=(uint8_t)BAUD_PRESCALER
andUBBRH=(uint8_t)BAUD_PRESCALER>>4
since UBBRL should take 8 least significant bits, and UBBRH takes 4 most significant bits. \$\endgroup\$