Serial Frame difference between Arduino IDE and AtmelStudio

Hello,

I have those two following codes, accordign to the datasheet of the Mega2560, both codes should do the same. However there are 2 additional Bits on the Serialframe with Arduino. At this point I'am not sure what Arduino is doing differently here and why i have those 2 extra bits in my frame.

The first one is my Atmelstudio code without those additional two bits:

#include <avr/io.h>
#include <avr/interrupt.h>

#include "myLibs/pwm.h"

#ifndef F_CPU
#define F_CPU 16000000UL
#endif
#include <avr/delay.h>


#define FOSC 16000000
#define BAUD 9600
#define MYUBRR FOSC/8/BAUD-1


int main( void )
{
	
	//setPWM(250,50);
	
	// Set Baudrate
	UBRR0 = MYUBRR;
	// Double the USART Transmission Speed
	UCSR0A = (1 << U2X0);
	// Enable Transmitter / Reciever
	UCSR0B = (1 << RXEN0) | (1 << TXEN0);
	// Set Frameformat (1 Stopbit / 8 Databits)
	UCSR0C = (0 << USBS0) | (1 << UPM01) | (1 << UPM00) |(0 << UCSZ02) | (1 << UCSZ01) | (1 << UCSZ00) ;
	
	DDRF = 0x00;
	
	while(1){
		
		 if((UCSR0A & 0b00100000) == 0b00100000)
			UDR0 = 5;
		
		_delay_ms(500);
	}
	
}

This is the arduino code with the two extra bits:

void setup() {
  Serial.begin(9600);
  }

void loop() {
Serial.print(5);
delay(500);
}

have you tried Serial.write(5); ?

The Arduino is sending the character '5' whereas the Atmel code is sending the byte value 5. Try Serial.write(5)

...R

KASSIMSAMJI:
have you tried Serial.write(5); ?

Ah yes, now those two bits are gone. Did not think about this. So Serial.write() is writing the acutal bits to the serial and Serial.print() is used for characters. So those two extra bits are for indication?

There is the next question:

How is this then handled when i want to send a number with more than 8 bits (greater than 256)?
Serial.print seems to chunk it up in more frames. But i quite do not understand how.

By the way there are no "additional bits" there is just a completely different value.

...R

Robin2:
By the way there are no "additional bits" there is just a completely different value.

...R

Yea, got it now.. the 5 in Ascii is the Binary of 53. Now I got it! Thank you.