Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of Nucleo_GPS by
Revision 2:ee6862d07ae9, committed 2016-09-04
- Comitter:
- mikawataru
- Date:
- Sun Sep 04 14:51:04 2016 +0000
- Parent:
- 1:aec45e847ec3
- Commit message:
- nucleo&GPS
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r aec45e847ec3 -r ee6862d07ae9 main.cpp --- a/main.cpp Tue Aug 16 15:57:35 2016 +0000 +++ b/main.cpp Sun Sep 04 14:51:04 2016 +0000 @@ -1,68 +1,75 @@ +/* +説明 +Nucleo-F303K8とGPSmモジュールを使ったサンプルプログラム + +参考 +http://www.hiramine.com/physicalcomputing/general/gps_nmeaformat.html + + +以下ピン配置 +Nucleo GPSモジュール +GND-----GND-----------0V +5v------VIN +D0------TX +D1------RX +*/ #include "mbed.h" DigitalOut myled(LED1); -Serial gps(D1, D0); // tx, rx -Serial pc(USBTX, USBRX); // tx, rx - -void pc_rx() { - - unsigned char c; - int i,rlock; - char gps_data[256],gps2_data[256]; - char ns,ew; - float time,hokui,tokei; - float g_hokui,g_tokei; - float d_hokui,m_hokui,d_tokei,m_tokei; - - gps.baud(9600); - pc.printf("*** GPS GT-720F ***"); +Serial gps(D1, D0); // tx, rx +Serial pc(PA_2, PA_3); // tx, rx +int i,rlock,mode; +char gps_data[256],gps2_data[256]; +char ns,ew; +float w_time,hokui,tokei; +float g_hokui,g_tokei; +float d_hokui,m_hokui,d_tokei,m_tokei; - while (1) { - i=0; - while(gps.getc()!='$'){ - } - - while((gps_data[i]=gps.getc()) != '\r'){ - i++; - if(i==256){ - pc.printf("*** Div Error! ***\n"); - i=255; - break; - } - } +void getGPS() { + unsigned char c = gps.getc(); + if( c=='$' || i == 256){ + mode = 0; + i = 0; + } + if(mode==0){ + if((gps_data[i]=c) != '\r'){ + i++; + }else{ gps_data[i]='\0'; - - if( sscanf(gps_data, "GPGGA,%f,%f,%c,%f,%c,%d",&time,&hokui,&ns,&tokei,&ew,&rlock) >= 1){ + // pc.printf("%s\r\n",gps_data); + + if( sscanf(gps_data, "$GPGGA,%f,%f,%c,%f,%c,%d",&w_time,&hokui,&ns,&tokei,&ew,&rlock) >= 1){ if(rlock==1){ - pc.printf("Status:Lock(%d)\n\r",rlock); - //logitude + pc.printf("Status:Lock(%d)\n\r",rlock); + //logitude d_tokei= int(tokei/100); m_tokei= (tokei-d_tokei*100)/60; - g_tokei= d_tokei+m_tokei; + g_tokei= d_tokei+m_tokei; pc.printf("Log:%4.5f,",g_tokei); - //Latitude + //Latitude d_hokui=int(hokui/100); m_hokui=(hokui-d_hokui*100)/60; g_hokui=d_hokui+m_hokui; pc.printf("Lat:%4.5f\n\r",g_hokui); - } else{ pc.printf("\n\rStatus:unLock(%d)\n\r",rlock); - for(i=0;i<40;i++){ - pc.printf("%c",gps_data[i]); - } + pc.printf("%s",gps_data); } }//if - }//while + } + } } int main(){ - gps.attach(pc_rx,Serial::RxIrq); - while(1) { - myled = 1; - wait(0.2); - myled = 0; - wait(0.2); - } -} \ No newline at end of file + pc.printf("*** GPS GT-720F ***"); + gps.baud(9600); + pc.baud(115200); + gps.attach(getGPS,Serial::RxIrq); + while(1) { + myled = 1; + wait(0.2); + myled = 0; + wait(0.2); + } +}