STM32F0 Discovery with the GY-GPS6MV2

Well! On another of my eBay whims, I decided to get a GPS receiver module. They’re normally relatively cheap (<£10 from the far lands! – Link will expire!) and are surprisingly easy to use. I’d found a fair few Arduino versions but couldn’t really find anything on how they’re interfaced. My module literally has 4 pins: VCC, Gnd, Tx and Rx. I knew that these modules communicated over USART but I wasn’t too sure on what needed to be sent or anything like that. Regardless, as per, I jumped right in and had a go! It turns out that the module sends data to the host through USART continuously, not actually requiring me to send anything to it. This simplified things quite a lot as half duplex communication is much easier.

The module uses the standard NMEA method ( of sending data as characters so parsing is relatively easy and its useful that all sentences start with $ and end in ‘\n’ so separating out sentences from the data stream is relatively easy. Data is sent from the module every second or so in bursts at a baud rate of 9600 so capturing the messages is actually quite straightforward and easy.

In my setup, the module uses the 5v provided by the STM32F0 board as the module has an onboard 3.3v regulator. It didn’t seem to work properly running off the 3v supply so I’ll just leave it running in this configuration. As the GPS module has an onboard regulator, the output voltage of the USART is from 0v to 3.3v, therefore no voltage divider is required to make it in the range of the STM32F0.

Hopefully as per, my example code is well documented but I’ll give a brief explanation regardless. Sentences are received using the USART RX Interrupt. This is to make sure I don’t miss any characters, potentially giving erroneous data. The sentences start being stored from the $ character and stop being stored at the ‘\n’ character. As every sentence is terminated by “\r\n”, as I’m stopping the sentence reading at \n, \r will be the end of the sentence, as stored in the temporary buffer. Talking of which, the whole sentence is stored in the temporary buffer. A string compare is then done between the temporary buffer and 6 constant preset strings, namely: “$GPGLL”, “$GPGSA”, “$GPGSV, “$GPRMC” and “$GPVTG”. The string compare time could be cut in half by only comparing the 3 letters after “$GP” as these are the real sentence definitions.

Once these sentences have been read into the temporary buffer and compared, they are then copied from the temporary buffer to the corresponding sentence buffer. The strings are copied up to the ‘\r’ character as done by my function StrCpyCh. This allows the strings to be copied entirely up to the end of the sentence without having to copy more than is required.

The example program also includes two sets of flags. These flags are the “xxxGot” flags, corresponding to that sentence being received, and the “xxxWrite” flags. If the “xxxWrite” flags are set, this allows the sentence buffers to be written to. Otherwise, the sentece buffers can’t be written to and data in the sentence buffer will not change.

The GPS module is actually really interesting and I’m currently designing a wrist sized smart “watch” (its not really a watch when its this large!) with inspiration from the PipBoy in Fallout 3. This smart watch will hopefully include IrDA, Bluetooth, GPS and potentially a dedicated GSM modem! The ultimate survival (pointless) wrist computational package!

Anyway, for those interested in the code, its available on my Github!


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s