I'm using this code on an ATMEGA168PA@3.3V 8Mhz external cristal:
void setup() {
Serial.begin(115200);
}
void loop() {
int i = 0;
int rx = 0;
delay(100);
int r = Serial.available();
if (r > 0)
{
while (i < r)
{
rx = Serial.read();
Serial.println((int) rx);
i++;
}
}
}
The ASCII code of the first character is correct, ex:
A
<65
For two character it's mostly garbage:
AA
<65
<200
AA
<65
65
And for more it's always garbage, but the first character is always correct.
ALOA
<65
<192
<210
<187
<255
Everything was working fine on a ATTINY85 with serial software.
<
I see "3.3V" and "8MHz" and "115200". There is something going on with those numbers.
With 8MHz you get slightly different baudrates due to the calculation. I think 38400 baudrate was the magical number that was best.
I have seen a table with the differences between 8MHz and 16MHz baudrates, but I can't find it right now.
The 3.3V might result in a weaker signal.