Test software for SatChat prototype hardware Platform - MAX32630FTHR
Dependencies: USBDevice max32630fthr
main.cpp
- Committer:
- koziniec
- Date:
- 2017-07-01
- Revision:
- 7:4218bb385ca4
- Parent:
- 6:af25f19eb4e6
- Child:
- 8:b4a6c632c809
File content as of revision 7:4218bb385ca4:
#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) { gps_power(on); while (1) { int checksum = 0; char nmea_sentence[82] = {0}; //Fill with NULL terminators //gps.format(8,Serial::None,1); while (gps.getc()!='$'); //wait for start of sentence int nmea_index = 0; nmea_sentence[nmea_index] = '$'; //Manually insert the '$' because we don't want it included in the checksum loop char nmea_char = gps.getc(); //get sentence first char from GPS while (nmea_char != '*') { // pc.putc(nmea_char); checksum ^= nmea_char; //Calc checksum as we read sentence if ((nmea_sentence[nmea_index] == ',')&&(nmea_char == ',')) { nmea_sentence[++nmea_index] = ' '; //Pad consecutive comma with a space } nmea_sentence[++nmea_index] = nmea_char; //build the sentence with the next character if (nmea_index > 80) { nmea_index=80; //Don't overflow buffer } nmea_char = gps.getc(); //get next char from GPS } //read two hex digits of CS from gps char msb_gps_checksum = gps.getc(); char lsb_gps_checksum = gps.getc(); // 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 ); } // pc.printf("GPS CS:"); pc.putc(msb_gps_checksum); pc.putc(lsb_gps_checksum); pc.printf("%d \n\r",checksum); } 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(2); while (1) { gps_update(); } }