I'm using Atmel Studio with Atmega328P.
I'm trying to send the decimal number 876 continuously from the micro-controller. This was just to learn.
To send 876 I need two bytes which is:
0x036C = 00000011 01101100
So I manipulated a code and here is what I use now:
#include <avr/io.h>
#define F_CPU 16000000
#define USART_BAUDRATE 9600
#define UBRR_VALUE (((F_CPU / (USART_BAUDRATE * 16UL))) - 1)
void USART0Init(void)
{
// Set baud rate
UBRR0H = (uint8_t)(UBRR_VALUE>>8);
UBRR0L = (uint8_t)UBRR_VALUE;
// Set frame format to 8 data bits, no parity, 1 stop bit
UCSR0C |= (1<<UCSZ01)|(1<<UCSZ00);
//enable transmission and reception
UCSR0B |= (1<<TXEN0);
}
int main (void)
{
//Initialize USART0
USART0Init();
while(1)
{
UDR0 = 0b00000011;
UDR0 = 0b01101100;
}
}
The problem is at the receiving side the data comes as:
01101100 00000011 00000011 . . .
Here is the screen shot of the binary data at the receiving end:

However it should be received correctly as two byte chunks 00000011 01101100.
And here you can see the problem of the data being received as uint16(not only 876 as desired):

How can I fix this and receive the data properly as two bytes with correct order as 876?