Created
January 19, 2014 12:26
-
-
Save jsleeio/8504181 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void GPS_Switch_Mode_To_NMEA(void) | |
{ | |
int checkSum; | |
const byte magicHead[] = { | |
0xA0, 0xA2, // start sequence | |
0x00, 0x18 // payload length 0x18 = 24 | |
}; | |
const byte magicPayload[] = { | |
0x81, // Message ID for "switch to NMEA" | |
0x02, // means "do not change NMEA debug message mode" | |
// the next bunch of fields work in pairs, first the time between messages, "period", then whether or | |
// not to send checksum on that message | |
// | |
// "period" is the number of seconds between times that the GPS repeats the message | |
// zero period is "do not send message | |
// then 0x00 for checksum off or 0x01 for checksum on | |
// | |
0x01, // GGA period | |
0x01, // checksum = on | |
0x01, // GLL period | |
0x01, // checksum = on | |
0x00, // GSA period | |
0x01, // checksum = on | |
0x05, // GSV period | |
0x01, // checksum = on | |
0x00, // RMC period | |
0x01, // checksum = on | |
0x00, // VTG period | |
0x01, // checksum = on | |
0x00, // MSS period | |
0x01, // checksum = on | |
0x00, // unused (future message) | |
0x01, // unused (checksum = on) | |
0x00, // ZDA period | |
0x01, // checksum = on | |
0x00, // unused (future message) | |
0x01, // unused (checksum = on) | |
// baud rate in 2 bytes (9600 = 0x2580; 19200 = 0x4B00; etc. ) | |
0x12, // baud rate high byte | |
0xC0 // baud rate low byte | |
}; | |
const byte magicTail[] = { | |
0xB0, 0xB3 // end sequence | |
}; | |
// send 4 byte header | |
for (int index = 0; index < 4; index++) { | |
Serial1.print(byte(magicHead[index])); | |
} | |
// send message body, calculating checksum as we go | |
checkSum = 0; | |
for (int index = 0; index < 24; index++) { | |
checkSum = checkSum + magicPayload[index]; | |
Serial1.print(byte(magicPayload[index])); | |
} | |
checkSum = checkSum & (0x7FFF); | |
// send the 2 byte checksum | |
Serial1.print(byte(checkSum >> 8)); | |
Serial1.print(byte(checkSum & 0xff)); | |
// send the 2 byte tail | |
for (int index = 0; index < 2; index++) { | |
Serial1.print(byte(magicTail[index])); | |
} | |
} | |
void setup() | |
{ | |
Serial.begin(9600); | |
delay(1000); | |
Serial.println("turning on GPS..."); | |
pinMode(4,OUTPUT); | |
digitalWrite(4,LOW); | |
Serial1.begin(4800); // set this to the baud rate that (you hope) your "stuck in binary" GPS is set for | |
// if your GPS is really wonked, you may need to repeat this trying different baud rates | |
Serial.println("attempting switch from SiRF->NMEA in 3 seconds..."); | |
delay(3000); | |
GPS_Switch_Mode_To_NMEA(); | |
delay(1000); | |
Serial.println("turning off GPS"); | |
digitalWrite(4,HIGH); | |
delay(1000); | |
Serial.println("reconfiguring for 4800 baud"); | |
Serial1.begin(4800); | |
delay(1000); | |
Serial.println("turning GPS back on"); | |
digitalWrite(4,LOW); | |
delay(1000); | |
Serial.println("dumping GPS data"); | |
} | |
void loop() { | |
while (Serial1.available()) | |
Serial.write(Serial1.read()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment