Test software for SatChat prototype hardware Platform - MAX32630FTHR
Dependencies: USBDevice max32630fthr
main.cpp
- Committer:
- koziniec
- Date:
- 2017-07-01
- Revision:
- 4:e996385ca6d9
- Parent:
- 3:1dff075c1c88
- Child:
- 5:703f61be6ee2
File content as of revision 4:e996385ca6d9:
#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') { char nmea_char = gps.getc(); if ((nmea_sentence[nmea_index-1] == ',')&&(nmea_char == ',')) { nmea_sentence[nmea_index++] = ' '; //Pad consecutive comma with a space } nmea_sentence[nmea_index] = nmea_char; if (nmea_index > 80) { nmea_index=80; //Don't overflow buffer } } // 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 ); while (token != NULL) { 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(); } }