移远L76K模组实现GPS定位

移远L76K模组简介

L76K 是一款支持多卫星系统(GPS、BeiDou、GLONASS、QZSS)、可多系统联合定位和单系统独立定位、支持AGNSS 功能、内置低噪声放大器和声表面滤波器、可向用户提供快速、精准、高性能定位体验的 GNSS 模块。
多卫星系统相比于单一的 GPS 系统,使得可见和可用卫星数目大幅度增加,提高定位精度,即使是在复杂城市环境中也能实现稳定的高精度定位。支持 AGNSS 功能,能够大大的减少首次定位的时间。
在这里插入图片描述

编写程序测试功能

在Arduino环境下编写一个L76K_GNSS的程序,主要实现通过串口读取并解析L76K的GPS数据

#include <TinyGPSPlus.h>
#include <SoftwareSerial.h>

#define RXD2 16
#define TXD2 17
#define GPSRXD 14
#define GPSTXD 4

HardwareSerial SerialPort(2);
SoftwareSerial GPSSerial(GPSTXD, GPSRXD);
TinyGPSPlus gps;

void CommandtoNBIOT (String cmd, char *res)
{
  while (1)
  {
    SerialPort.println(cmd);
    delay(300);
    while (SerialPort.available() > 0)
    {
      if (SerialPort.find(res))
      {
        Serial.println(res);
        return;
      }
      else
      {
        Serial.print(cmd);
        Serial.println("Return ERROR!");
      }
    }
    delay(200);
  }
}

void BC260Y_init(void)//初始化BC260Y
{
  Serial.println("1");
  // prints title with ending line break
  CommandtoNBIOT("AT", "OK");
  //SerialPort.println("ATE0&W");//关闭回显
  delay(300);
  CommandtoNBIOT("ATI", "OK");//返回制造商信息
  delay(300);

  CommandtoNBIOT("AT+CPIN?", "+CPIN: READY"); //返+CPIN:READY,表明识别到卡
  Serial.println("2");
  CommandtoNBIOT("AT+CGATT?", "+CGATT: 1"); //返+CGACT: 1,就能正常工作
  Serial.println("3");
  SerialPort.println("AT+QMTCLOSE=0");//关闭上一次socekt连接
  delay(300);
}

void displayInfo()
{
  Serial.print(F("Location: ")); 
  if (gps.location.isValid())
  {
    Serial.print(gps.location.lat(), 6);
    Serial.print(F(","));
    Serial.print(gps.location.lng(), 6);
  }
  else
  {
    Serial.print(F("INVALID"));
  }

  Serial.print(F("  Date/Time: "));
  if (gps.date.isValid())
  {
    Serial.print(gps.date.month());
    Serial.print(F("/"));
    Serial.print(gps.date.day());
    Serial.print(F("/"));
    Serial.print(gps.date.year());
  }
  else
  {
    Serial.print(F("INVALID"));
  }

  Serial.print(F(" "));
  if (gps.time.isValid())
  {
    if (gps.time.hour() < 10) Serial.print(F("0"));
    Serial.print(gps.time.hour());
    Serial.print(F(":"));
    if (gps.time.minute() < 10) Serial.print(F("0"));
    Serial.print(gps.time.minute());
    Serial.print(F(":"));
    if (gps.time.second() < 10) Serial.print(F("0"));
    Serial.print(gps.time.second());
    Serial.print(F("."));
    if (gps.time.centisecond() < 10) Serial.print(F("0"));
    Serial.print(gps.time.centisecond());
  }
  else
  {
    Serial.print(F("INVALID"));
  }

  Serial.println();
}

void setup(){
    Serial.begin(9600);
    SerialPort.begin(9600, SERIAL_8N1, RXD2, TXD2);
    GPSSerial.begin(9600);
    BC260Y_init();
    delay(2000);
}

void loop(){
    while (GPSSerial.available() > 0){
          int c = GPSSerial.read();
          if(gps.encode(c)){
              displayInfo();
            }
            if (millis() > 5000 && gps.charsProcessed() < 10)
            {
              Serial.println(F("No GPS detected: check wiring."));
              while(true);
            }
      }
}

编译程序后上传到板卡,执行结果如下
在这里插入图片描述
可正常采集到经纬度数据,可以到百度地图上查看一下获取到的位置
在这里插入图片描述
这个定位位置有一定偏差,需要进一步的处理,至此已经可以正常采集到GPS数据。

### L76K GPS 模组与 STM32 的开发教程 #### 硬件连接 对于L76K GPS模组与STM32的连接,主要涉及UART通信接口。通常情况下,GPS模块的数据输出引脚(TX)应连接到STM32微控制器的一个可用USART接收引脚(RX),而GPS模块的RX则不需要连接除非计划向其发送命令[^1]。 #### 初始化配置 为了使能GPS功能,在初始化阶段需设置相应的GPIO端口以及开启USART外设时钟。接着配置USART参数如波特率、字长等以匹配L76K的要求。一般推荐使用9600bps作为默认通讯速率[^4]。 ```c void UART_Configuration(void){ GPIO_InitTypeDef GPIO_InitStructure; USART_InitTypeDef USART_InitStructure; RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_USART1, ENABLE); // 配置PA9为USART1_TX, PA10为USART1_RX GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9|GPIO_Pin_10; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOA,&GPIO_InitStructure); USART_InitStructure.USART_BaudRate = 9600; USART_InitStructure.USART_WordLength = USART_WordLength_8b; USART_InitStructure.USART_StopBits = USART_StopBits_1; USART_InitStructure.USART_Parity = USART_Parity_No; USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; USART_Init(USART1,&USART_InitStructure); } ``` #### 数据解析 接收到的位置数据遵循NMEA协议标准格式,其中最重要的是GPGGA语句,它包含了时间戳、纬度经度坐标以及其他重要地理信息。可以通过字符串处理函数提取这些字段并转换成易于理解的形式显示出来或用于进一步计算. ```c char buffer[256]; int index=0; while (USART_GetFlagStatus(USART1, USART_FLAG_RXNE)!=RESET){ char ch = USART_ReceiveData(USART1); if(ch=='\n'){ parse_NMEA(buffer,index); memset(buffer,'\0',sizeof(buffer)); index=0; }else{ buffer[index++]=ch; } } void parse_NMEA(char* str,int length){ /* 解析逻辑 */ } ```
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值