Test software for SatChat prototype hardware Platform - MAX32630FTHR

Dependencies:   USBDevice max32630fthr

main.cpp

Committer:
koziniec
Date:
2017-07-01
Revision:
2:814706310a71
Parent:
1:b8cb82927f33
Child:
3:1dff075c1c88

File content as of revision 2:814706310a71:


#include "mbed.h"
#include "max32630fthr.h"
#include <stdbool.h>
#define on 1
#define off 0

Serial pc(USBTX, USBRX);
Serial gps(P5_3, P5_4, 9600);
I2C i2c(P5_7,P6_0); // SDA, SCL

DigitalOut red_led(LED1,1);
DigitalOut green_led(LED2,1);
DigitalOut blue_led(LED3,1);

void gps_power(bool state)
{
    char    data[2];
    data[0] = 0x16;     //MAX14690 LDO3cfg register
    data[1] = 0xE0;     //Disable LDO3
    if (state == on) {
        data[1] = 0xE2; //Enable LDO3
    }
    i2c.write( 0x50, data, 2 ); 
}

void gps_update(void)
{
    char nmea_descriptor[5] = {0};
    gps_power(on);
    while (1) {
        char nmea_sentence[82] = {0}; //Fill with NUL terminators
        gps.format(8,Serial::None,1);
        while (gps.getc()!='$');   //wait for start of sentence
        int nmea_index = 0;
        nmea_sentence[nmea_index] = '$';
        while (nmea_sentence[nmea_index++] != '\n') {
            blue_led = 1;
            nmea_sentence[nmea_index] = gps.getc();
            blue_led = 0;
            //pc.putc(nmea_sentence[nmea_index-1]);
            if (nmea_index > 80) {
                nmea_index=80;
            }
        }
   //     const char s[2] = ",";
        const char gprmc[7] = "$GPRMC";
        char *token;
        token = strtok(nmea_sentence, ",");
        if (strcmp(token,gprmc) == 0){
            pc.printf( " %s\n\r", token );
            token = strtok(NULL, ",");
            pc.printf( " %s\n\r", token );
            token = strtok(NULL, ",");
            pc.printf( " %s\n\r", token );
        }
    }

    while (gps.readable()) {
        char dummy = gps.getc();
    }
}


int main()
{
//
    char    data[2];
    data[0] = 0x1A;     //MAX14690 BootCfg register
    data[1] = 0x30;     //Always-On Mode, off state via PWR_OFF_CMD
    i2c.write( 0x50, data, 2 );

    data[0] = 0x17;     //MAX14690 LDO3Vset register
    data[1] = 0x19;     //3.3V
    i2c.write( 0x50, data, 2 );
    gps_power(off);
    wait(5);
    while (1) {
        gps_update();
    }
}