Hello forum, I am trying to interface an Arduino Mega 2560 to another board (where an ELM232 chip lives) via serial.
To troubleshoot, I have connected as follows on a breadboard:
ELM232 board's Tx to:
- PC via USB to serial adaptor.
- Arduino's Rx3.
All share a common ground.
When powering up the ELM232, it sends the following string:
ELM323 v2.0
>
I see this perfectly well on the PC, using a terminal program at 9600 8N1.
The Mega, however, spits out complete garbage. The source code I use is here:
#define ELM_BAUD 9600
int buffer[50];
void setup() {
Serial.begin(9600);
Serial3.begin(ELM_BAUD);}
void loop() {
int c;
// We will let a long time pass between the incoming data burst to make 100% sure no timing problems occur
if (Serial3.available() > 0) {
delay(1000); // twiddle thumbs for a second to make sure burst is over
int index = 0; // this will count our incoming byteswhile ( (c = Serial3.read()) != -1) buffer[index++] = c; // fetch the received bytes
Serial.print("Read these ");
Serial.print(index, DEC);
Serial.println(" characters:");for (int i=0; i < index; i++) {
Serial.write(buffer*); // print as a byte*
_ Serial.print(":");_
_ Serial.println(buffer*, DEC); // print ASCII value*_
* }** }*
}
[/quote]
The result I 'm getting on the Arduino IDE's terminal is:
*_ <em>*Read these 18 characters: y:121 ½:189 ×:215 V:86 V:86 ¶:182 ?:150 ö:246 ?:155 ?:155 £:163 ?:159 å:229 ë:235 å:229 ë:235 ?:131 :0*</em> _*
I 'm completely stumped. I 've tried all the Mega's available UARTs but it's the same everywhere. Any idea what is happening here?
P.S. The characters are indeed 18 and in Hex they are these (copy pasted from the PC terminal shown in hex, including linefeeds and carriage returns):
*_ <em>*0d 0a 45 4c 4d 33 32 33 20 76 32 2e 30 0d 0a 0d 0a 3e*</em> _*
Out of desperation, I have tried other baud rates (by changing the #define ELM_BAUD ... in the code) but, unsurprisingly, only 9600 gets the correct number of bytes.