sample for GPS (used by nucleo_STM-F303K8)

Dependencies:   mbed

Fork of Nucleo_GPS by Kosuke Furumoto

Committer:
mikawataru
Date:
Mon Oct 24 16:22:38 2016 +0000
Revision:
1:91f4ae33e6ac
Parent:
0:8889ed33c550
Child:
2:59b33f158822
sample for GPS

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mikawataru 1:91f4ae33e6ac 1 /*
mikawataru 1:91f4ae33e6ac 2 説明
mikawataru 1:91f4ae33e6ac 3 Nucleo-F303K8とGPSモジュールを使ったサンプルプログラム
mikawataru 1:91f4ae33e6ac 4
mikawataru 1:91f4ae33e6ac 5 参考
mikawataru 1:91f4ae33e6ac 6 http://www.hiramine.com/physicalcomputing/general/gps_nmeaformat.html
mikawataru 1:91f4ae33e6ac 7
mikawataru 1:91f4ae33e6ac 8
mikawataru 1:91f4ae33e6ac 9 以下ピン配置
mikawataru 1:91f4ae33e6ac 10 Nucleo GPSモジュール
mikawataru 1:91f4ae33e6ac 11 GND-----GND-----------0V
mikawataru 1:91f4ae33e6ac 12 5v------VIN
mikawataru 1:91f4ae33e6ac 13 D0------TX
mikawataru 1:91f4ae33e6ac 14 D1------RX
mikawataru 1:91f4ae33e6ac 15 */
Koob 0:8889ed33c550 16 #include "mbed.h"
mikawataru 1:91f4ae33e6ac 17
Koob 0:8889ed33c550 18 Serial gps(D1, D0); // tx, rx
mikawataru 1:91f4ae33e6ac 19 Serial pc(PA_2, PA_3); // tx, rx
mikawataru 1:91f4ae33e6ac 20
Koob 0:8889ed33c550 21 int main() {
Koob 0:8889ed33c550 22 unsigned char c;
Koob 0:8889ed33c550 23 int i,rlock;
Koob 0:8889ed33c550 24 char gps_data[256],gps2_data[256];
Koob 0:8889ed33c550 25 char ns,ew;
mikawataru 1:91f4ae33e6ac 26 float world_time,hokui,tokei;
Koob 0:8889ed33c550 27 float g_hokui,g_tokei;
Koob 0:8889ed33c550 28 float d_hokui,m_hokui,d_tokei,m_tokei;
mikawataru 1:91f4ae33e6ac 29 pc.baud(115200);
Koob 0:8889ed33c550 30 gps.baud(9600);
mikawataru 1:91f4ae33e6ac 31 pc.printf("*** GPS GT-720F ***");
Koob 0:8889ed33c550 32
Koob 0:8889ed33c550 33 while (1) {
Koob 0:8889ed33c550 34 i=0;
Koob 0:8889ed33c550 35 while(gps.getc()!='$'){
Koob 0:8889ed33c550 36 }
mikawataru 1:91f4ae33e6ac 37
Koob 0:8889ed33c550 38 while((gps_data[i]=gps.getc()) != '\r'){
Koob 0:8889ed33c550 39 i++;
Koob 0:8889ed33c550 40 if(i==256){
Koob 0:8889ed33c550 41 pc.printf("*** Div Error! ***\n");
Koob 0:8889ed33c550 42 i=255;
Koob 0:8889ed33c550 43 break;
Koob 0:8889ed33c550 44 }
Koob 0:8889ed33c550 45 }
Koob 0:8889ed33c550 46 gps_data[i]='\0';
mikawataru 1:91f4ae33e6ac 47 // pc.printf("%s",gps_data);
mikawataru 1:91f4ae33e6ac 48 if( sscanf(gps_data, "$GPGGA,%f,%f,%c,%f,%c,%d",&world_time,&hokui,&ns,&tokei,&ew,&rlock) >= 1){
Koob 0:8889ed33c550 49 if(rlock==1){
mikawataru 1:91f4ae33e6ac 50 pc.printf("Status:Lock(%d)\n\r",rlock);
Koob 0:8889ed33c550 51 //logitude
Koob 0:8889ed33c550 52 d_tokei= int(tokei/100);
Koob 0:8889ed33c550 53 m_tokei= (tokei-d_tokei*100)/60;
mikawataru 1:91f4ae33e6ac 54 g_tokei= d_tokei+m_tokei;
Koob 0:8889ed33c550 55 pc.printf("Log:%4.5f,",g_tokei);
Koob 0:8889ed33c550 56 //Latitude
Koob 0:8889ed33c550 57 d_hokui=int(hokui/100);
Koob 0:8889ed33c550 58 m_hokui=(hokui-d_hokui*100)/60;
Koob 0:8889ed33c550 59 g_hokui=d_hokui+m_hokui;
Koob 0:8889ed33c550 60 pc.printf("Lat:%4.5f\n\r",g_hokui);
mikawataru 1:91f4ae33e6ac 61
Koob 0:8889ed33c550 62 }
Koob 0:8889ed33c550 63 else{
Koob 0:8889ed33c550 64 pc.printf("\n\rStatus:unLock(%d)\n\r",rlock);
Koob 0:8889ed33c550 65 for(i=0;i<40;i++){
Koob 0:8889ed33c550 66 pc.printf("%c",gps_data[i]);
Koob 0:8889ed33c550 67 }
Koob 0:8889ed33c550 68 }
Koob 0:8889ed33c550 69 }//if
Koob 0:8889ed33c550 70 }//while
mikawataru 1:91f4ae33e6ac 71 }//main