sample for GPS (used by nucleo_STM-F303K8)

Dependencies:   mbed

Fork of Nucleo_GPS by Kosuke Furumoto

Committer:
mikawataru
Date:
Sat Jan 28 13:15:00 2017 +0000
Revision:
3:03e5370e74a3
Parent:
2:59b33f158822
Child:
4:ccc66c37d3f1
USB?????

Who changed what in which revision?

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