{"id":758,"date":"2022-02-08T16:23:36","date_gmt":"2022-02-08T16:23:36","guid":{"rendered":"https:\/\/blog.embeddedexpert.io\/?p=758"},"modified":"2022-02-08T16:23:39","modified_gmt":"2022-02-08T16:23:39","slug":"working-with-stm32-and-sensors-gps-neo-6m-uart-based-sensor","status":"publish","type":"post","link":"https:\/\/blog.embeddedexpert.io\/?p=758","title":{"rendered":"Working with STM32 and sensors: GPS NEO-6M UART based sensor"},"content":{"rendered":"\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img decoding=\"async\" src=\"https:\/\/storage.googleapis.com\/geotab_wfm_production_cms_storage\/CMS-Images-production\/Blog\/NA\/_2020\/May\/GPS-update\/blog-what-is-gps-hero@2x.png\" alt=\"\" \/><\/figure><\/div>\n\n\n\n<p>In this guide, we shall investigate the GPS and how it works and use NEO-6M GPS module to locate our location in any part of world.<\/p>\n\n\n\n<p>In this guide, we shall cover the following:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>What is GPS<\/li><li>NEO-6M GPS sensor<\/li><li>Connection with STM32<\/li><li>Code<\/li><li>Result<\/li><\/ul>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">1. What is GPS:<\/h2>\n\n\n\n<p>Humans have looked to the skies to find their way since ancient times. Ancient sailors used the constellations in the night sky to figure out where they were and where they were going.<\/p>\n\n\n\n<p>Today, all we need is a simple hand-held GPS (short for Global Positioning System) receiver to figure out exactly where we are anywhere in the world. But we still need objects high in the sky to figure out where we are and how we get to other places.<\/p>\n\n\n\n<p>Instead of stars, we use satellites. Over 30 navigation satellites are zipping around high above Earth. These satellites can tell us exactly where we are.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What is GPS?<\/h2>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img decoding=\"async\" src=\"https:\/\/spaceplace.nasa.gov\/review\/gps\/system.en.png\" alt=\"\" \/><\/figure><\/div>\n\n\n\n<p>The Global Positioning System (GPS) is made up of satellites, ground stations, and receivers.<\/p>\n\n\n\n<p>GPS is a system. It\u2019s made up of three parts: satellites, ground stations, and receivers.<\/p>\n\n\n\n<p>Satellites act like the stars in constellations\u2014we know where they are supposed to be at any given time.<\/p>\n\n\n\n<p>The ground stations use radar to make sure they are actually where we think they are.<\/p>\n\n\n\n<p>A receiver, like you might find in your phone or in your parents car, is constantly listening for a signal from these satellites. The receiver figures out how far away they are from some of them.<\/p>\n\n\n\n<p>Once the receiver calculates its distance from four or more satellites, it knows exactly where you are. Presto! From miles up in space your location on the ground can be determined with incredible precision! They can usually determine where you are within a few yards of your actual location. More high-tech receivers, though, can figure out where you are to within a few inches!<\/p>\n\n\n\n<p>The ancient sailors of history would be flabbergasted by the speed and ease of pinpointing your location today.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">GPS in everyday life<\/h2>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/spaceplace.nasa.gov\/review\/gps\/in-a-snap.en.png\"><img decoding=\"async\" src=\"https:\/\/spaceplace.nasa.gov\/review\/gps\/in-a-snap.en.png\" alt=\"Space Place in a Snap logo\" \/><\/a><\/figure>\n\n\n\n<p>There\u2019s a whole lot of important things GPS is used for\u2014but perhaps nothing is more important than finding the quickest slice of pizza!<\/p>\n\n\n\n<p>Source: NASA website : <a href=\"https:\/\/spaceplace.nasa.gov\/gps\/en\/\" data-type=\"URL\" data-id=\"https:\/\/spaceplace.nasa.gov\/gps\/en\/\" target=\"_blank\" rel=\"noreferrer noopener\">here<\/a><\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">2. NEO-6M GPS module:<\/h2>\n\n\n\n<p>The NEO-6M GPS module is shown in the figure below. It comes with an external antenna, and does\u2019t come with header pins. So, you\u2019ll need to get and solder some.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img decoding=\"async\" src=\"https:\/\/i2.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/10\/NEO-GPS-1.jpg?resize=670%2C526&amp;quality=100&amp;strip=all&amp;ssl=1\" alt=\"\" class=\"wp-image-45439\" \/><\/figure><\/div>\n\n\n\n<ul class=\"wp-block-list\"><li>This module has an external antenna and built-in EEPROM.<\/li><li>Interface: RS232 TTL<\/li><li>Power supply: 3V to 5V<\/li><li>Default baudrate: 9600 bps<\/li><li>Works with standard NMEA sentences2<\/li><\/ul>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>The NEO-6M GPS module has four pins:&nbsp;VCC,&nbsp;RX,&nbsp;TX, and&nbsp;GND. The module communicates with the Arduino via serial communication using the TX and RX pins, so the wiring couldn\u2019t be simpler:<\/p>\n\n\n\n<figure class=\"wp-block-table is-style-stripes\"><table><tbody><tr><td><strong>NEO-6M GPS Module<\/strong><\/td><td><strong>Wiring to Arduino UNO<\/strong><\/td><\/tr><tr><td>VCC<\/td><td>5V<\/td><\/tr><tr><td>RX<\/td><td>Not used in this guide<\/td><\/tr><tr><td>TX<\/td><td>PA10 of STM32F4<\/td><\/tr><tr><td>GND<\/td><td>GND<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Understanding NMEA Sentences<\/h3>\n\n\n\n<p>NMEA sentences start with the $ character, and each data field is separated by a comma.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>$GPGGA<\/strong>,110617.00,41XX.XXXXX,N,00831.54761,W,1,05,2.68,129.0,M,50.1,M,,*42\n<strong>$GPGSA<\/strong>,A,3,06,09,30,07,23,,,,,,,,4.43,2.68,3.53*02\n<strong>$GPGSV<\/strong>,3,1,11,02,48,298,24,03,05,101,24,05,17,292,20,06,71,227,30*7C\n<strong>$GPGSV<\/strong>,3,2,11,07,47,138,33,09,64,044,28,17,01,199,,19,13,214,*7C\n<strong>$GPGSV<\/strong>,3,3,11,23,29,054,29,29,01,335,,30,29,167,33*4E\n<strong>$GPGLL<\/strong>,41XX.XXXXX,N,00831.54761,W,110617.00,A,A*70\n<strong>$GPRMC<\/strong>,110618.00,A,41XX.XXXXX,N,00831.54753,W,0.078,,030118,,,A*6A \n<strong>$GPVTG<\/strong>,,T,,M,0.043,N,0.080,K,A*2C<\/code><\/pre>\n\n\n\n<p>There are different types of NMEA sentences. The type of message is indicated by the characters before the first comma.<\/p>\n\n\n\n<p>The GP after the $ indicates it is a GPS position.&nbsp; The $GPGGA is the basic GPS NMEA message, that provides 3D location and accuracy data. In the following sentence:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>$GPGGA<\/strong>,110617.00,41XX.XXXXX,N,00831.54761,W,1,05,2.68,129.0,M,50.1,M,,*42<\/pre>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>110617<\/strong>&nbsp;\u2013 represents the time at which the fix location was taken, 11:06:17 UTC<\/li><li><strong>41XX.XXXXX,N<\/strong>&nbsp;\u2013 latitude 41 deg XX.XXXXX\u2019 N<\/li><li><strong>00831.54761,W<\/strong>&nbsp;\u2013 Longitude 008 deg 31.54761\u2032 W<\/li><li><strong>1<\/strong>&nbsp;\u2013 fix quality (0 = invalid; 1= GPS fix; 2 = DGPS fix; 3 = PPS fix; 4 = Real Time Kinematic; 5 = Float RTK; 6 = estimated (dead reckoning); 7 = Manual input mode; 8 = Simulation mode)<\/li><li><strong>05<\/strong>&nbsp;\u2013 number of satellites being tracked<\/li><li><strong>2.68<\/strong>&nbsp;\u2013 Horizontal dilution of position<\/li><li><strong>129.0, M<\/strong>&nbsp;\u2013 Altitude, in meters above the sea level<\/li><li><strong>50.1, M<\/strong>&nbsp;\u2013&nbsp;Height of geoid (mean sea level) above WGS84 ellipsoid<\/li><li>empty field \u2013&nbsp;time in seconds since last DGPS update<\/li><li>empty field \u2013&nbsp;DGPS station ID number<\/li><li><strong>*42<\/strong>&nbsp;\u2013 the checksum data, always begins with *<\/li><\/ul>\n\n\n\n<p>The other NMEA sentences provide additional information:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>$GPGSA<\/strong>&nbsp;\u2013&nbsp;GPS DOP and active satellites<\/li><li><strong>$GPGSV<\/strong>&nbsp;\u2013&nbsp;Detailed GPS satellite information<\/li><li><strong>$GPGLL<\/strong>&nbsp;\u2013&nbsp;Geographic Latitude and Longitude<\/li><li><strong>$GPRMC<\/strong>&nbsp;\u2013&nbsp;Essential GPS pvt (position, velocity, time) data<\/li><li><strong>$GPVTG<\/strong>&nbsp;\u2013&nbsp;Velocity made good<\/li><\/ul>\n\n\n\n<p>To know what each data field means in each of these sentences, you can consult\u00a0<a rel=\"noreferrer noopener\" href=\"http:\/\/www.gpsinformation.org\/dale\/nmea.htm\" target=\"_blank\">NMEA data here<\/a>.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">3. Connection with STM32F4<\/h2>\n\n\n\n<p><\/p>\n\n\n\n<p>In this guide, we need the following<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>STM32F411RE Nucelo-64<\/li><li>LCD2004 I2C<\/li><li>NEO-6M GPS module<\/li><\/ul>\n\n\n\n<p><\/p>\n\n\n\n<p>The connection should be as following:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"805\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/02\/Screen-Shot-2022-02-08-at-7.14.53-PM-1024x805.png\" alt=\"\" class=\"wp-image-759\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/02\/Screen-Shot-2022-02-08-at-7.14.53-PM-1024x805.png 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/02\/Screen-Shot-2022-02-08-at-7.14.53-PM-300x236.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/02\/Screen-Shot-2022-02-08-at-7.14.53-PM-768x604.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/02\/Screen-Shot-2022-02-08-at-7.14.53-PM-1536x1207.png 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/02\/Screen-Shot-2022-02-08-at-7.14.53-PM-2048x1610.png 2048w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/02\/Screen-Shot-2022-02-08-at-7.14.53-PM-1150x904.png 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/02\/Screen-Shot-2022-02-08-at-7.14.53-PM-750x590.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/02\/Screen-Shot-2022-02-08-at-7.14.53-PM-400x314.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/02\/Screen-Shot-2022-02-08-at-7.14.53-PM-250x197.png 250w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">4. Code:<\/h2>\n\n\n\n<p><\/p>\n\n\n\n<p>We start of by initializing UART1 in interrupt mode for the receiver as following:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">void uart_gps_init()\n\t{\n\t#define AF07 0x07\n\tRCC-&gt;APB2ENR|=RCC_APB2ENR_USART1EN;\n\tRCC-&gt;AHB1ENR|=RCC_AHB1ENR_GPIOAEN;\n\t\t\n\tGPIOA-&gt;MODER|=GPIO_MODER_MODE10_1;\n\tGPIOA-&gt;MODER&amp;=~GPIO_MODER_MODE10_0;\n\t\t\n\tGPIOA-&gt;MODER|=GPIO_MODER_MODE9_1;\n\tGPIOA-&gt;MODER&amp;=~GPIO_MODER_MODE9_0;\n\n\tGPIOA-&gt;AFR[1]|=(AF07&lt;&lt;4)|(AF07&lt;&lt;8); \/\/ALT7 for UART2 (PA2 and PA3)\n\tUSART1-&gt;BRR  = 0x0681;    \/\/9600 @16MHz\n\tUSART1-&gt;CR1 |= (1&lt;&lt;2)|(1&lt;&lt;3)|(1&lt;&lt;5)|(1&lt;&lt;13);\n\tNVIC_EnableIRQ(USART1_IRQn);\n\t\n\t}\n<\/pre><\/div>\n\n\n\n<p>then we declare some required variables as following:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">\nvolatile unsigned char Gpsdata;             \/\/ for incoming serial data\nunsigned int finish =0;            \/\/ indicate end of message\nunsigned int pos_cnt=0;            \/\/ position counter\nunsigned int lat_cnt=0;            \/\/ latitude data counter\nunsigned int log_cnt=0;            \/\/ longitude data counter\nunsigned int flg    =0;            \/\/ GPS flag\nunsigned int com_cnt=0;            \/\/ comma counter\nunsigned char lat[20];             \/\/ latitude array\nunsigned char lg[20];              \/\/ longitude array\nint i=0;\nunsigned char dir,dir1;<\/pre><\/div>\n\n\n\n<p>Within the interrupt handler, we shall construct the location as following:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">\nvoid USART1_IRQHandler(void){\n\nif(USART1-&gt;SR&amp;USART_SR_RXNE) \/\/check if the read data register is not empty\n{\nGpsdata=USART1-&gt;DR;\t\nITM_SendChar(Gpsdata);\nflg = 1;\n\nif(finish == 0){\nif( Gpsdata=='$' &amp;&amp; pos_cnt == 0)  \/\/ finding GPRMC header\n         pos_cnt=1;\n       if( Gpsdata=='G' &amp;&amp; pos_cnt == 1)\n         pos_cnt=2;\n       if( Gpsdata=='P' &amp;&amp; pos_cnt == 2)\n         pos_cnt=3;\n       if( Gpsdata=='R' &amp;&amp; pos_cnt == 3)\n         pos_cnt=4;\n       if( Gpsdata=='M' &amp;&amp; pos_cnt == 4)\n         pos_cnt=5;\n       if(Gpsdata=='C'  &amp;&amp;  pos_cnt == 5 )\n\t\t\t\t \/\/data[i]=Gpsdata;i++;\n         pos_cnt=6;\n       if(pos_cnt==6    &amp;&amp;  Gpsdata ==','){  \/\/ count commas in message\n         com_cnt++;\n         flg=0;\n       }\n\t\t\t\tif(Gpsdata=='N'||Gpsdata=='S'){dir=Gpsdata;}\n\t\t\t\tif(Gpsdata=='E'||Gpsdata=='W'){dir1=Gpsdata;}\n       if(com_cnt==3 &amp;&amp; flg==1){\n        lat[lat_cnt++] =  Gpsdata;        \/\/ latitude\n        flg=0;\n       }\n \n       if(com_cnt==5 &amp;&amp; flg==1){\n         lg[log_cnt++] =  Gpsdata;        \/\/ longitude\n         flg=0;\n       }\n \n       if( Gpsdata == '*' &amp;&amp; com_cnt &gt;= 5 &amp;&amp; flg == 1){\n        \n\t\t\t\t lat[lat_cnt]=dir;\n\t\t\t\t lat[lat_cnt+1] ='\\0';\t\t\t\t \/\/ end of GPRMC message\n\t\t\t\t lg[log_cnt]  =dir1;\n         lg[log_cnt+1]  ='\\0';\n         lat_cnt = 0;\n         log_cnt = 0;\n         flg     = 0;\n         finish  = 1;\n         com_cnt = 0;\n\t\t\t\t\ti=0;\n      }\n     }\n}\n}<\/pre><\/div>\n\n\n\n<p>for the lcd part, you can download the code from <a rel=\"noreferrer noopener\" href=\"https:\/\/blog.embeddedexpert.io\/?p=655\" data-type=\"URL\" data-id=\"https:\/\/blog.embeddedexpert.io\/?p=655\" target=\"_blank\">here<\/a>.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>Hence, the entire code is as following:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">#include &quot;LiquidCrystal_PCF8574.h&quot;\n\nvolatile unsigned char Gpsdata;             \/\/ for incoming serial data\nunsigned int finish =0;            \/\/ indicate end of message\nunsigned int pos_cnt=0;            \/\/ position counter\nunsigned int lat_cnt=0;            \/\/ latitude data counter\nunsigned int log_cnt=0;            \/\/ longitude data counter\nunsigned int flg    =0;            \/\/ GPS flag\nunsigned int com_cnt=0;            \/\/ comma counter\nunsigned char lat[20];             \/\/ latitude array\nunsigned char lg[20];              \/\/ longitude array\nint i=0;\nunsigned char dir,dir1;\n\nvoid uart_gps_init()\n\t{\n\t#define AF07 0x07\n\tRCC-&gt;APB2ENR|=RCC_APB2ENR_USART1EN;\n\tRCC-&gt;AHB1ENR|=RCC_AHB1ENR_GPIOAEN;\n\t\t\n\tGPIOA-&gt;MODER|=GPIO_MODER_MODE10_1;\n\tGPIOA-&gt;MODER&amp;=~GPIO_MODER_MODE10_0;\n\t\t\n\tGPIOA-&gt;MODER|=GPIO_MODER_MODE9_1;\n\tGPIOA-&gt;MODER&amp;=~GPIO_MODER_MODE9_0;\n\n\tGPIOA-&gt;AFR[1]|=(AF07&lt;&lt;4)|(AF07&lt;&lt;8); \/\/ALT7 for UART2 (PA2 and PA3)\n\tUSART1-&gt;BRR  = 0x0681;    \/\/9600 @16MHz\n\tUSART1-&gt;CR1 |= (1&lt;&lt;2)|(1&lt;&lt;3)|(1&lt;&lt;5)|(1&lt;&lt;13);\n\tNVIC_EnableIRQ(USART1_IRQn);\n\t\n\t}\n\n\n\nint main(void)\n\t{\n\t__disable_irq();\n\tuart_gps_init();\n\t__enable_irq();\n\tlcd_init();\n\tsetCursor(0,0);\n\tlcd_send_string(&quot;GPS NEO with STM32&quot;);\n\tsetCursor(0,1);\n\tlcd_send_string(&quot;EmbeddedExpertIO&quot;);\n\tfor(volatile int i=0;i&lt;3000000;i++);\n\tlcd_clear();\n\t\t\n\twhile(1)\n\t\t\n\t\t{\n\t\t{\nsetCursor(0,0);\nlcd_send_string(&quot;Latitude: &quot;);\nsetCursor(0,1);\nlcd_send_string((char *)lat);\nsetCursor(0,2);\nlcd_send_string(&quot;Longitude: &quot;);\nsetCursor(0,3);\nlcd_send_string((char *)lg);\t\n\t\t}\n\t\n\t}\n\t\n\t}\n\t\nvoid USART1_IRQHandler(void){\n\nif(USART1-&gt;SR&amp;USART_SR_RXNE) \/\/check if the read data register is not empty\n{\nGpsdata=USART1-&gt;DR;\t\nflg = 1;\n\nif(finish == 0){\nif( Gpsdata=='$' &amp;&amp; pos_cnt == 0)  \/\/ finding GPRMC header\n         pos_cnt=1;\n       if( Gpsdata=='G' &amp;&amp; pos_cnt == 1)\n         pos_cnt=2;\n       if( Gpsdata=='P' &amp;&amp; pos_cnt == 2)\n         pos_cnt=3;\n       if( Gpsdata=='R' &amp;&amp; pos_cnt == 3)\n         pos_cnt=4;\n       if( Gpsdata=='M' &amp;&amp; pos_cnt == 4)\n         pos_cnt=5;\n       if(Gpsdata=='C'  &amp;&amp;  pos_cnt == 5 )\n\t\t\t\t \/\/data[i]=Gpsdata;i++;\n         pos_cnt=6;\n       if(pos_cnt==6    &amp;&amp;  Gpsdata ==','){  \/\/ count commas in message\n         com_cnt++;\n         flg=0;\n       }\n\t\t\t\tif(Gpsdata=='N'||Gpsdata=='S'){dir=Gpsdata;}\n\t\t\t\tif(Gpsdata=='E'||Gpsdata=='W'){dir1=Gpsdata;}\n       if(com_cnt==3 &amp;&amp; flg==1){\n        lat[lat_cnt++] =  Gpsdata;        \/\/ latitude\n        flg=0;\n       }\n \n       if(com_cnt==5 &amp;&amp; flg==1){\n         lg[log_cnt++] =  Gpsdata;        \/\/ longitude\n         flg=0;\n       }\n \n       if( Gpsdata == '*' &amp;&amp; com_cnt &gt;= 5 &amp;&amp; flg == 1){\n        \n\t\t\t\t lat[lat_cnt]=dir;\n\t\t\t\t lat[lat_cnt+1] ='\\0';\t\t\t\t \/\/ end of GPRMC message\n\t\t\t\t lg[log_cnt]  =dir1;\n         lg[log_cnt+1]  ='\\0';\n         lat_cnt = 0;\n         log_cnt = 0;\n         flg     = 0;\n         finish  = 1;\n         com_cnt = 0;\n\t\t\t\t\ti=0;\n      }\n     }\n}\n}<\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">5. Result:<\/h2>\n\n\n\n<p><\/p>\n\n\n\n<p>When you run the code, you should get something like this<\/p>\n\n\n\n<p>Note: you need to be outside of the home for the GPS to work properly since this module designed for automotive industry <\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"768\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/02\/IMG_7862-1024x768.jpg\" alt=\"\" class=\"wp-image-760\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/02\/IMG_7862-1024x768.jpg 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/02\/IMG_7862-300x225.jpg 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/02\/IMG_7862-768x576.jpg 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/02\/IMG_7862-1536x1152.jpg 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/02\/IMG_7862-2048x1536.jpg 2048w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/02\/IMG_7862-1150x863.jpg 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/02\/IMG_7862-750x563.jpg 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/02\/IMG_7862-400x300.jpg 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/02\/IMG_7862-250x188.jpg 250w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Happy coding \ud83d\ude42 <\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this guide, we shall investigate the GPS and how it works and use NEO-6M GPS module to locate our location in any part of world. In this guide, we shall cover the following: What is GPS NEO-6M GPS sensor Connection with STM32 Code Result 1. What is GPS: Humans have looked to the skies [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,19,11,12],"tags":[],"class_list":["post-758","post","type-post","status-publish","format-standard","hentry","category-embedded-systems","category-lcd","category-peripheral-drivers","category-stm32"],"_links":{"self":[{"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/posts\/758"}],"collection":[{"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=758"}],"version-history":[{"count":1,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/posts\/758\/revisions"}],"predecessor-version":[{"id":761,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/posts\/758\/revisions\/761"}],"wp:attachment":[{"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=758"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=758"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=758"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}