A driver for the MAX8U GPS by uBlox. Provides core functionality. Communicates through I2C.

MAX8U Driver

This driver supports a wide range of functions provided by the MAX8U chip. Most of the essential features are supported. It lays a framework to add more commands easily, with only a little extra work.

Driver was originally made for the USC Rocket Propulsion Lab by Adhyyan Sekhsaria and Jamie Smith

Features

Currently supports:

  • Getting coordinates in latitude, longitude, accuracy...
  • Velocity measurements in each axis
  • Individual satellite information
  • Time of last message
  • Antenna Power Status
  • GPS Fix Quality
  • Save configuration in memory

Documentation

Full documentation is available here

Usage

Code Structure:

In factory settings, the module is not configured to send any messages. For the GPS to give updates, we need to configure it by sending messages using setMessageEnabled() which internally calls sendMessage() and waitForAck().

calling configure() once will enable a few useful messages, and save this configuration in the MAX8U non-volatile memory.

update() to be called periodically by the user. Processes and reads all the messages currently stored in the GPS. Calls processMessage() on every message. processMessage(): processes the message currently in the buffer by calling the respective functions. Each message is read, and its relevant information is then stored in the public variables.

By default, the GPS sends messages in NMEA format (but we reconfigure it to UBX format), so readNextMessage() has to determine which format the message is.

define the macro MAX8U_DEBUG to enable printing out to message information to the debug port. If not defined, will only print error messages to the debug port.

Example

Outputting Coordinates, Velocity and Time from GPS

#include "MAX8U.h"

int main(){
    MAX8U gps(&pc, PIN_I2C_SDA, PIN_I2C_SCL, p25);
    bool booted = gps.begin();

    if(!booted){
        //handle error
    }
    booted = gps.configure();
    if(!booted){
        //handle error
    }

    while(true){
        bool newMessageRcvd = gps.update();
        pc.printf(">Position: %.06f %c, %.06f %c, Height %.02f m\r\n",
                  std::abs(gps.latitude), gps.latitude > 0 ? 'N' : 'S',
                  std::abs(gps.longitude), gps.longitude > 0 ? 'E' : 'W',
                  gps.height);

        // velocity
        pc.printf(">Velocity: %.02f m/s N, %.02f m/s E, %.02f m/s Down\r\n",
                  gps.northVel * .02f,
                  gps.eastVel * .02f,
                  gps.downVel * .02f);

        // accuracy
        pc.printf(">Fix: Quality: %" PRIu8 ", Num Satellites: %" PRIu8 ", Position Accuracy: %.02f m\r\n",
                static_cast<uint8_t>(gps.fixQuality), gps.numSatellites, gps.posAccuracy);

        // time
        pc.printf(">Time: %" PRIu8 "/%" PRIu8"/%" PRIu16" %" PRIu8":%" PRIu8 ":%" PRIu8 "\r\n",
                gps.month,
                gps.day,
                gps.year,
                gps.hour,
                gps.minute,
                gps.second);
    }
}

Committer:
adhyyan
Date:
Tue Jan 07 10:49:40 2020 +0000
Revision:
3:b51460af3259
Parent:
0:7f603f221713
Added Example Code

Who changed what in which revision?

UserRevisionLine numberNew contents of line
adhyyan 0:7f603f221713 1 //
adhyyan 0:7f603f221713 2 // Constants for the MAX-8U
adhyyan 0:7f603f221713 3 //
adhyyan 0:7f603f221713 4
adhyyan 0:7f603f221713 5 #ifndef HAMSTER_MAX8UCONSTANTS_H
adhyyan 0:7f603f221713 6 #define HAMSTER_MAX8UCONSTANTS_H
adhyyan 0:7f603f221713 7
adhyyan 0:7f603f221713 8 // Characters at the start of every UBX message
adhyyan 0:7f603f221713 9 #define UBX_SYNC_CHAR_1 0xB5
adhyyan 0:7f603f221713 10 #define UBX_SYNC_CHAR_2 0x62
adhyyan 0:7f603f221713 11
adhyyan 0:7f603f221713 12 // indicies into UBX messages
adhyyan 0:7f603f221713 13 #define UBX_BYTE_CLASS 2
adhyyan 0:7f603f221713 14 #define UBX_BYTE_ID 3
adhyyan 0:7f603f221713 15
adhyyan 0:7f603f221713 16 #define UBX_DATA_OFFSET 6 // start byte of message data
adhyyan 0:7f603f221713 17 #define UBX_HEADER_FOOTER_LENGTH 8 // length of message header and footer
adhyyan 0:7f603f221713 18
adhyyan 0:7f603f221713 19 // class ACK
adhyyan 0:7f603f221713 20 #define UBX_CLASS_ACK 0x5
adhyyan 0:7f603f221713 21 #define UBX_ACK_NACK 0x0
adhyyan 0:7f603f221713 22 #define UBX_ACK_ACK 0x1
adhyyan 0:7f603f221713 23
adhyyan 0:7f603f221713 24 // class CFG
adhyyan 0:7f603f221713 25 #define UBX_CLASS_CFG 0x6
adhyyan 0:7f603f221713 26 #define UBX_CFG_PRT 0x0
adhyyan 0:7f603f221713 27 #define UBX_CFG_MSG 0x1
adhyyan 0:7f603f221713 28 #define UBX_CFG_RATE 0x8
adhyyan 0:7f603f221713 29 #define UBX_CFG_CFG 0x9
adhyyan 0:7f603f221713 30 #define UBX_CFG_GNSS 0x3E
adhyyan 0:7f603f221713 31
adhyyan 0:7f603f221713 32 // class NAV
adhyyan 0:7f603f221713 33 #define UBX_CLASS_NAV 0x1
adhyyan 0:7f603f221713 34 #define UBX_NAV_POSLLH 0x2 // LLH stands for Latitude-Longitude-Height
adhyyan 0:7f603f221713 35 #define UBX_NAV_SOL 0x06
adhyyan 0:7f603f221713 36 #define UBX_NAV_TIMEUTC 0x21
adhyyan 0:7f603f221713 37 #define UBX_NAV_SAT 0x35
adhyyan 0:7f603f221713 38 #define UBX_NAV_VELNED 0x12
adhyyan 0:7f603f221713 39
adhyyan 0:7f603f221713 40 // class MON
adhyyan 0:7f603f221713 41 #define UBX_CLASS_MON 0xA
adhyyan 0:7f603f221713 42 #define UBX_MON_VER 0x4
adhyyan 0:7f603f221713 43 #define UBX_MON_HW 0x9
adhyyan 0:7f603f221713 44
adhyyan 0:7f603f221713 45 #define UBX_MESSAGE_START_CHAR 0xB5
adhyyan 0:7f603f221713 46 #define NMEA_MESSAGE_START_CHAR '$'
adhyyan 0:7f603f221713 47
adhyyan 0:7f603f221713 48 #endif //HAMSTER_MAX8UCONSTANTS_H