Pages: [1]   Go Down
Author Topic: Problem outputing to RS-232  (Read 496 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,

I am having a problem with a very simple piece of code.  I have a Leonardo and a CuteDigi RS232 shield.  For debugging, I've attached the serial port to my mac and I'm looking at the output in CoolTerm.  

When I write to the SerialConsole (Serial), everything is fine.  However, when I write to the UART (Serial1), two bytes are written, both of which make no sense.  In this example the output showing up in CoolTerm is: 01 1F.  For the life of me I cannot figure out what is going on.

Any ideas?

Thanks,

Carl


Code:
void setup() {
    Serial.begin(9600);
    Serial1.begin(9600);
}

void loop() {
    char char_a = 'a';

    Serial.write(char_a); delay(100);
 
    Serial1.write(char_a); delay(100);
}
« Last Edit: October 09, 2012, 10:55:46 am by carlkesselman » Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 553
Posts: 46267
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
void setup() {
    Serial.begin(9600);
    Serial.begin(9600);
}

void loop() {
    char char_a = 'a';

    Serial.write(char_a); delay(100);
 
    Serial1.write(char_a); delay(100);
}
Generally, before you can use Serial1.write(), you need to use Serial1.begin(). On the Leonardo, you need to wait for the instance to actually start.
Logged

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

Sorry, mistype on entering the code (didn't copy and paste as I am working across two computers).  I did initialize Serial1.  The correct code is:

Code:

void setup() {
   Serial.begin(9600);
   Serial1.begin(9600);
}

Carl
« Last Edit: October 09, 2012, 10:25:17 am by carlkesselman » Logged

Switzerland
Offline Offline
Faraday Member
**
Karma: 96
Posts: 4758
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Is your CoolTerm (or whatever you're using) set to 9600 baud, 8 data bits, no parity, 1 stop bit, no handshake?
Logged

Pages: [1]   Go Up
Jump to: