Electronic – UART communication issue

avrcommunicationembeddedterminaluart

I am trying to send something from an atmega to my pc.

The setup is: Ubuntu 14.04, atmega644P-20PU, USBASP v2, TTL-to-USB pl2303

Firstly I tried to write the code in C and used this code and then this one and I got the same result: '�' or random characters (in minicom or screen)

Then I gave up the C and uploaded a simple Arduino program:

void setup()
{
   Serial.begin(9600);
}
void loop()
{
   delay(500);
   Serial.write('t');
}

(when running arduino I put a 16MHz crystal. in other cases I used a 20Mhz one. Also setting F_CPU accordingly in the code.)

In all the cases the R(receive) LED of the pl2303 is blinking at the right moments (depending on the delay set in code).

Also I used CuteCom to view what I am getting from the serial port and instead of '�', depending on the code used I get "\0x00\0x80\0x80" (for Arduino code) or in other cases "\0x80\0x00\0x80".

I use RX0 and TX0 (pin 14 and 15).
RX0 connected to TX of pl2303 and RX of pl2303 to TX0 of the mcu.

I also shorted RX and TX of pl2303 and tried to send data across it and I receive back what I send.

Baud rate of pl2303 is 9600

$stty -F /dev/ttyUSB1

speed 9600 baud; line = 0;

min = 60; time = 1;

ignbrk -brkint -icrnl -imaxbel

-opost -onlcr

-isig -icanon -iexten -echo -echoe -echok -echoctl -echoke

In all cases I used 8N1.

I hope I was specific enough and coherent.

(normally I try to find myself answers and solutions, but now I'm lost)

Best Answer

't' looks like 000101110 on the line 0x80 like 000000001 and 0x00 like 000000000 (including the start bit an ignoring the stop bit) almost certainly you have the baud rate too fast at the receiving end.

given that you're seeing 0 zeros and a 1 it's probably set 8 times too fast, so try 1200 baud in cutecom and look for a possible cause for the baud rate divider in the arduino to be set 8 times too high.