Go Down

Topic: Problem outputing to RS-232 (Read 597 times) previous topic - next topic

carlkesselman

Oct 09, 2012, 04:59 pm Last Edit: Oct 09, 2012, 05:55 pm by carlkesselman Reason: 1
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: [Select]

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);
}

PaulS

Code: [Select]
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.

carlkesselman

#2
Oct 09, 2012, 05:17 pm Last Edit: Oct 09, 2012, 05:25 pm by carlkesselman Reason: 1
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: [Select]


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


Carl

pylon

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

Go Up