The system is now up and running. It is capable of communicating with the GPS receiver to get it into a known protocol (NMEA) and baud rate from an arbitrary starting configuration. I had to determine the pinout for the receiver as it was a USB GPS receiver. A check with the multimeter quickly identified the pinout of the four wires, TX was easy to spot as it was a constantly changing voltage whereas RX only changed when a command was sent. Once the prototyping is finished the USB receiver will be restored to its former glory. A few challenges were involved in figuring out the receivers startup configuration. It looks like at reset it outputs NMEA at 4800 baud but expects to receive NMEA configuration commands at 9600. This ‘interesting’ configuration was overcome by sending NMEA and SiRF configuration commands to the receiver at all supported baud rates.
Damn its good when things just work the first time. So far everything has been tested at 5v. I’m going to have to check that it operates at 3.3v to easily interface with the SDCard.
On a side note, the BusPirate is excellent for development and debugging work. So far I use it to program FPGAs, debug serial strings (as above), peek at JTAG on wireless routers and frequency measurement and generation. It’s the best $30 I spent.
Initialisation Code
The initialisation code initially started out trying to determine the baud rate the device was operating on and then send it the appropriate configuration commands. Testing this method on a PC resulted in alot of confusion until I figured out what was happening. Afterwards the rest of the configuration became relatively easy.
////////////////////////////////////////////////////////////////////////////// // // Function: gps_init() // Description: Configures the GPS // Parameters: void // Returns: void // void gps_init(void) { uint32 baud = 1200; //starting baud rate //EUSART should have already been configured //however need to set interrupts for the EUSART IPR1bits.RCIP = 1; //High priority for the receive interrupt PIE1bits.RCIE = 1; //enable the interrupt INTCONbits.GIE = 1; //enable high priority interrupts, if not already enabled //Need to initalize the GPS, it can be on one of the following baud rates //1200,2400,4800,9600,19200,38400 //in either NMEA or SiRF mode and by default xmits NMEA at 4800 and listens and 9600. //easy way of initilization: step through each baud rate sending the NMEA then SiRF init strings. //by the time we get to the desired baud rate we should be good. for(baud = 1200; baud <= 38400; baud = baud << 1) { //toggle the red led LED_Red = ~ LED_Red; //set the baud rate serial_baud(baud); serial_send(nmea_config, sizeof(nmea_config)); serial_send(sirf_config, sizeof(sirf_config)); while(TXSTAbits.TRMT == 0); //wait for all of the data to be sent } //the GPS module should now be operating in NMEA mode at 38400 baud. serial_baud(38400); //should already be at 38400 but just in case LED_Red = 1; inbuffer_head = 0; //configure the buffer inbuffer_tail = 0; GPSState = GPS_NOLOCK; //set the operating state }
The code above sucessfully configures the GPS, as shown in the photo. I guess this is just another case of brute force winning over elegant design. The code for the system initilisation and serial communication is in gpslogger-0.01a.zip.