Professional Documents
Culture Documents
017
Lab 4 Worksheet – Serial Communications and the GPS Receiver
Goals:
Understand and implement serial communications on the TT8.
Parse strings from a GPS receiver into numerical data.
Make quantitative calculations on GPS data.
1. Hook up the GPS to the mobile board 12-pin ribbon cable, and a 9V battery to the
appropriate plug. Attach the GPS serial output line to one of your PC’s ports, and
view the GPS output in Crosscut. You see that
a. there is about one update per second,
b. the satellite readings (ending with N for north, and E for east) are bogus
because you are inside a building, and
c. the strings always have the same number of characters, in exactly the same
places.
(You don’t need to use the serial output again to do the rest of the lab, but it is
always available to help.)
2. Using the oscilloscope on the output of the LM324N op-amp, confirm that the
digital signal is normally high, and that the two states are about 5V and 0.5V. Do
not proceed to Step 2 until you have verified this! – The TT8 serial port takes the
opposite polarity as is provided by the GPS’s NEMA output, and this is the
purpose of the op-amp circuit. Also, in this lab you should check the battery
voltage several times per hour, because the GPS is a power hog, and you will
start getting get strange symptoms if the voltage sags.
3. Hook up the TT8 to the mobile power supply plug, and attach the output line of
the op-amp to TPU0/B10. You can communicate with the TT8 when it is
connected to the mobile board, through the regular serial port plug.
4. Now write code to read in ten GPS strings. The first code fragment on the next
page is a model (for the hhmmss string).
5. Now extract the hhmmss as an integer number of seconds, and the latitude and
longitude numbers as decimal-degree doubles from the string. The second code
fragment is a model (for the hhmmss string).
6. Now set up your program so that it logs the seconds, the latitude, and the
longitude to a file. You can afford to write to the card every time step, since the
GPS updates only once per second; so you don’t need to use big number arrays.
7. Set up your system to go for a walk – this means attaching the antenna to the
GPS, starting logging, and pulling the serial plug to the PC. Go out to the Charles
River and stand still for five minutes (to make sure initialization is done), walk
toward the Science Museum for five minutes, stand still for a few minutes, and
then come back.
8. Process your data. Make an annotated plot of your latitude versus your longitude.
About how far did you go? What is the approximate heading of the sidewalk you
surveyed? What is the scatter in the data from the periods when you were
standing still?
for (i=0;i<TSBUFSIZ;i++) // get the chars from buffer as fast as you can!
c[i] = TSerGetByte(SERCHAN) ;
// now turn d[] into a real number; it is known to be a positive integer in this case
ic = 0 ;
ic += (long int) (d[0]-‘0’)*3600*10 ; // tens of hours
ic += (d[1]-‘0’)*3600 ; // hours
ic += (d[2]-‘0’)*60*10 ; // tens of minutes
ic += (d[3]-‘0’)*60 ; // minutes
ic += (d[4]-‘0’)*10 ; // tens of seconds
ic += (d[5]-‘0’) ; // seconds
printf("Target value: %ld seconds.\n", ic) ;