Go Down

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

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.

#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
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy