Offline
Newbie
Karma: 0
Posts: 5
|
 |
« on: February 04, 2012, 04:20:13 pm » |
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
Online
Brattain Member
Karma: 143
Posts: 19366
I don't think you connected the grounds, Dave.
|
 |
« Reply #1 on: February 04, 2012, 04:25:04 pm » |
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.
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 5
|
 |
« Reply #2 on: February 04, 2012, 04:38:12 pm » |
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
God Member
Karma: 15
Posts: 965
|
 |
« Reply #3 on: February 04, 2012, 05:00:21 pm » |
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
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 5
|
 |
« Reply #4 on: February 04, 2012, 05:09:56 pm » |
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
Online
Brattain Member
Karma: 143
Posts: 19366
I don't think you connected the grounds, Dave.
|
 |
« Reply #5 on: February 04, 2012, 05:19:39 pm » |
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.
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 5
|
 |
« Reply #6 on: February 04, 2012, 06:03:36 pm » |
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
God Member
Karma: 0
Posts: 503
|
 |
« Reply #7 on: February 04, 2012, 06:13:02 pm » |
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
Edison Member
Karma: 26
Posts: 2450
|
 |
« Reply #8 on: February 05, 2012, 08:04:55 am » |
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
Tesla Member
Karma: 100
Posts: 6784
-
|
 |
« Reply #9 on: February 05, 2012, 08:43:28 am » |
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
|
|
|
|
|
|