First time making a post on a forum, so, guess I'll try my best.
Now, this is a story all about how
My Baud rate got flipped-turned upside down
And I'd like to take a minute just sit right there
I'll tell you how serial communication became my worst Night-mare.
In west California I was born and raised
In my bedroom is where I spend most of my days
Chillin' out maxin' relaxin' all cool
And all bootin' some 'duinos outside of my room (bluetooth)
When an couple of chips
They were so cool!
Started making errors in my serial network
I got one little error and my phone got scared
And said "#$U*(A*%! @*&ÄRD!" (due to baud rate errors, I assume)
I begged and tweaked with her day after day
But she compiled my script and sent me an error, no way!
She gave me a " #@$(Å(! " and then she gave me a " ä^&ö# "
I put my headphones on and said "Well, fuck it"
My first class, yo' this is bad
Sippin' Java out of my coffee glass
Is this what the people of Comcast Living like?
Hmmmm I should make a forum post... (and one that rhymes too)
But wait I hear there're prissy, bourgeois and all that (Sorry forum guys, but it had to rhyme)
Is this the type I should send my script at? (Don't end a sentence with a preposition)
I don't think so
I'll see when it gets there
I hope there prepared for my worst night-mare!
#include <avr/io.h> #define F_CPU 16000000 #define BAUD 9600 #define BRC ((F_CPU/16/BAUD) - 1) int main(void) { char ReceivedByte; DDRB |= (1<<PINB0); //Turn the pin on UBRR0H = (BRC >> 8)); UBRR0L = BRC); UCSR0B = (1 << RXEN0) | (1 << TXEN0); //Turn on the transmission and reception circuitry UCSR0C = (1 << UCSZ00) | (1 << UCSZ01); // Set Frame format: 8data, 1stop bit while(1) { while ((UCSR0A & (1 << RXC0)) == 0 ) {};// Do nothing until data have been received and is ready to be read from UDR ReceivedByte = UDR0; if (ReceivedByte != 0) { //blink LED if it receives a packet that is not '0' PORTB |= (1 << PINB0); } else { //turn LED off if the packet is '0' PORTB &= ~(1 << PINB0); } while ((UCSR0A & (1 << UDRE0)) == 0) {}; UDR0 = ReceivedByte; //bounce the signal back to the sender (my phone) } return 0; }
For some reason, when I send packets of any character to the atmega328p, it returns them in random characters my phone doesn't support
pls halp