Hi Gang,
I've got a GPS module and a 1284P.
GPS is connected to Serial1, FTDI Basic Serial.
I'm trying to enter serial monitor commands via Serial, send them out Serial1, receive any response on Serial1 and send it out on Serial.
To start, I figured I'd just echo back what I typed on the serial monitor. I have the following, but I'm not seeing CR or LF or CR and LF come out. Anything I type in just comes back on the same time.
What do I have to do to recognize Enter coming from the Serial Monitor?
Or doesn't it ever send one?
byte inMonitor;
byte outMonitor;
byte inGPS;
byte outGPS;
byte endReached;
void setup(){
Serial.begin(9600); // for debug
Serial1.begin (9600); // for gps/gsm control
}
void loop(){
// GPS test code
if (Serial.available()>0){
inMonitor = Serial.read();
Serial.write(inMonitor);
if (inMonitor == 0x0A){ // tried 0x0D here also
endReached = 1;
Serial.println("end reached"); // never see this.
}
if (endReached == 1){
endReached = 0;
Serial.println(""); // Tried 0x0A, 0x0D here also, and Serial.write.
}
}
if (Serial1.available()>0){
inGPS = Serial1.read();
Serial.write(inGPS);
}
}
That code works for me, as is, on a Teensy 2, although I would combine these two if statements:
if (inMonitor == 0x0A){ // tried 0x0D here also
endReached = 1;
Serial.println("end reached"); // never see this.
}
if (endReached == 1){
endReached = 0;
Serial.println(""); // Tried 0x0A, 0x0D here also, and Serial.write.
}
into one:
if (inMonitor == 0x0A){ // tried 0x0D here also
Serial.println("end reached"); // never see this.
}
Pete
"works for me"
I type AT & press enter, multiple times, I get this:
ATATATAT
what I want is
AT
AT
AT
AT
Which are you seeing?
with your original code, I see this in the serial monitor:
AT
end reached
AT
end reached
AT
end reached
Pete
I don't get it. Why can't I detect the 0x0A? Something about the 1284P core code?
IDE version a factor perhaps? I have 1.0.6.
P.S. that's with the serial monitor set to newline.
The IDE version shouldn't have any effect but I'm using 1.6.8.
I've never used a 1284P but your code only reads from Serial and echoes back to Serial, and reads from Serial1 and echoes it to Serial. If Serial1 isn't generating characters, this is just a very basic example of using the Serial monitor.
Pete
Ah! I didn't even think about that. Yes, changing from "no line ending" fixes things.
Yes, it is basic serial monitor usage. I wasn't getting any response from the GPS, so I wanted to make sure it was getting AT CR or AT NL or AT CR NL or something.
Thanks Pete.
Rats - found a wiring error too. Net from TX1 from 1284P is UCTX1, but UXTX1 at the GPS end. Missed that when I did the schematic error check. Need to add a wire tomorrow. Well, at least it explains why the GPS wasn't responding to commands after fixing the serial monitor settings.