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);
}