Changing serial port baud rate.

Is it possible to change the baud rate of a serial port after it's been initialized?

I'm reading a GPS module from a Mega, and I have had to change the data rate from it's default to something faster. When I first got the GPS unit of the box, I wrote a very very short sketch to talk to the GPS (at it's default speed) to change the configuration to it's new, faster rate. Then I can reload the mega with my actual sketch and it will happily communicate at a higher speed.

So far so good.

Since then the internal battery on the GPS seems to have failed. This appears to mean that even after a momentary break in the power it looses it's configuration and returns to it's defaults.

What I'd like to do is write a sketch that will talk to the GPS at 9600, send the commands to change the speed to 57600, and then reconfigure the mega's port to change it's own bit rate to 57600. I need to be able to do this in a single sketch, is this possible?

Before anyone asks, I don't know the make/model of the GPS module, and can't spot anything that looks like a battery - so replacing it might be problematic!

What I'd like to do is write a sketch that will talk to the GPS at 9600, send the commands to change the speed to 57600, and then reconfigure the mega's port to change it's own bit rate to 57600.

You have my permission to try it.

There is a Serial.end() function as well as a Serial.begin() function So, how about

Serial.begin(9600);
//send setup commands
Serial.end();
Serial.begin(57600);
//other stuff

Hi, A picture of your GPS would help too, I haven't come across one with a memory battery before.

Tom... :)

There is a Serial.end()

Thanks - hadn't spotted this before. Previous attempts have focused around using serial.begin() with different baud rates. I'll try the end() command and see if it makes a difference.

I haven't come across one with a memory battery before.

Check out the SR-92 GPS or the LS20031 these both have tiny button cells built in. Unlike the one I have, the cell is visible and changeable in both these.

Thanks