Booting Arduino with rx active causes hang

I've got a GPS ttl tx hooked up to my arduino mini-stamp rx. Because I use the USB->serial adapter to program the mini, I disconnect the GPS, program the arduino, then after it boots, connect the GPS. I can display NMEA strings on the LCD attached to the arduino. Life is good.

However, if I power it up with the GPS running and connected, the arduino will hang - it doesn't even get to setup. I have a switch on the GPS line and if I have that off, it powers up to a simple message in setup and waits for serial input. I turn the GPS tx->rx line on and the arduino reads serial and writes to the display fine.

I'm wondering if on power up, if because the GPS is tied to the rx of the arduino, whether the arduino is in some kind of bootloader mode that is confused by the 4800bps GPS signal coming at it during the boot phase.

Any other ideas of why this behavior is occurring? Also, what are ideas for how to get around it - would be nice if the arduino could ignore rx if the baud rates weren't right, or it didn't recognize signals coming at it on rx. Would like to see it just boot into my program even if the rx line was full of GPS data coming at it on boot.

It sounds like the GPS serial stream is confuising the Arduino''s bootloader process.

If you put something like a line driver chip between the GPS and the RX line, you can use the driver chip's enable to connect/disconnect the GPS under software control...

I don't know if I'm explaining this very well: the basic idea is you use a digital pin to turn a switch on and off, and that switch hooks up/disonnects the GPS to the RX line. So your code, assuming the switch was on pin 3, would be something like:

void setup(){
int GPSlineEnable=3;
Serial.begin(4800);
}

void loop(){
digitalWrite(GPSlineEnable, HIGH);
//GPS is now connected

Note that you would need a pullup/pull-down resistor on the enable line to make sure the driver was disabled during bootloading.

Just to follow up on Daniel's comment:

I don't know how it's done on the official Arduino board, but on the do-it-yourself serial model they use a hex inverter (7404) chip to provide a pair of inverters, one used for serial transmit and one for serial receive. Perhaps you could replace one of the inverters with a 2-input NAND gate, and use the extra NAND input connected to a digital output on the Atmega8 to enable/disable the GPS serial input from software. You might need to add a manual switch to bypass this gate when you want to upload new firmware.

I added a note about this to the Arduino troubleshooting guide: http://www.arduino.cc/en/Guide/Troubleshooting#sketchstart

It's probably possible to modify the Arduino bootloader to be a bit more intelligent, but it would be very difficult to do and still keep the bootloader smaller than 1024 bytes. If it's any bigger, we need to devote 2048 bytes to it, which would be a significant portion of the 8 KB available on the ATmega8.

All your replies were informative and appreciated. Thanks...I'll let you know what I settle on.

maybe you can use a MOSFET to turn the GPS on after bootloader is done.