Pages: [1]   Go Down
Author Topic: using Serialx (Serial1, Serial2, Serial3) connected to PC produces Garbage  (Read 1053 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I am attempting to communicate with my PC using one of the Serialx (Serial1, Serial2, Serial3) ports with very little success. The output on the PC is garbage.

I have tested both Serial1 and Serial3 with the same problems. I have atmega2560 and using a "USB to serial" cable converter. Following is my sketch:

void setup() {
  Serial1.begin(9600);
}
void loop(){
    // repeat writing "abc" 3 times
    for(int i=0;i<3;i++) {
      Serial1.write(61);
      Serial1.write(62);
      Serial1.write(63);
    }
   
     delay(200);
}

the output displayed in hex:

61 B0 60 61 B0 60 61 B0 60

Notice the only letter that is correct is the first one, the letter little 'a'.
I have also tried Serial1.print() which produces the same results.
I have tried various Windows Device Manager and Putty port configuration settings. Different settings create different results, all incorrect. The test above is using 9600/8/N/1 and Flow Control: NONE

I am creating the hex view by cut/paste from the Putty terminal/window into a binary editor (MS Visual Studio).


Questions:
1. Has anyone successfully communicated with the PC using the Serialx ports?
2. What should the Windows Device Manager and Putty port settings be?
3. Can you control/set the prort settings in the Arduino sketch, and if so, how?

thanks, JL







Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 290
Posts: 25753
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

How are you doing the serial level conversion and inversion before connecting to the USB device?
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

AWOL: don't understand what you mean by "...doing the serial level conversion and inversion before connecting to the USB device?..."

thanks for your quick response.
Logged

Offline Offline
Edison Member
*
Karma: 43
Posts: 1553
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
the output displayed in hex:
Which version of the IDE are you using V1.0?

61 (*decimal*) is not the lower case letter 'a'. It is the equals sign '='. 62 is > and 63 is ?
If you want lower case a, b and c you need to use 0x61, 0x62 and 0x63.

Pete
Logged

Where are the Nick Gammons of yesteryear?

Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I am using Arduino 1.0 IDE.

You are correct about the character values. I have tried the (decimal) values 97, 98 and 99 as well as 0x61, 0x62 and 0x63 which produce the following hex values on the PC:

4F A7 4E.....repeated forever

As you pointed out, when sending the (decimal) values 61, 62 and 62, I should have received =>?
which are the hex values: 0x3D, 0x3E and 0x3F, but as you can see, I did not get these values.
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 290
Posts: 25753
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You cannot simply connect TTL level serial lines to an RS232 serial converter and expect sensible results.
a) The signals are inverted
b) the signals are level-shifted.

You need something like a MAX232 to do the conversion for you.
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

thank you AWOL. if I am understanding you correctly, I will need the following:

1. from the atmega2560 board, I would connect the TX/TX/GND ports to a TTL converter (like the MAX232)
2. the MAX232 would be connected to my USB-to-RS232 cable converter
3. the USB-to-RS232 cable converter would plug into my PC in a USB port.

or, are there devices that convert the TTL signals to USB directly?
Logged

Offline Offline
God Member
*****
Karma: 1
Posts: 547
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

On the parallax site they have a schematic of a simple RX/TX adapter to go to /from TTL to RS232
I built one for programming my basic stamp.
Logged

New Jersey
Offline Offline
Faraday Member
**
Karma: 65
Posts: 3638
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

What is the spec on your "USB to serial" cable converter? It's likely that the cable already has the electronics for the level conversion built into it.
Logged

UK
Offline Offline
Shannon Member
****
Karma: 222
Posts: 12541
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

or, are there devices that convert the TTL signals to USB directly?

Arduino clones that don't include a USB port are usually programmed via the SPI, aren't they? There is a common interface you can get that connects to the SPI and provides a USB interface. Perhaps you could use one of these instead of going via RS232?
Logged

I only provide help via the forum - please do not contact me for private consultancy.

Pages: [1]   Go Up
Jump to: