开发环境:gd32f450开发板
嵌入式操作系统:rtthread
软件包:lwgps
gps定位模块:正点原子ATK-1218-BD
lwgps软件包的介绍:此项目是完成开源的lwgps与rt-thread的匹配。原工程地址:https://github.com/MaJerle/lwgps
许可证:lwgps移植包及lwgps遵循 MIT 许可。
硬件连接:gd32单片机的串口5和gps定位模块通信
软件包的使用步骤如下:
1.env工具使能并配置串口5,如下图
2.添加lwgps软件包,如下图:
3.保存,退出。使用指令pkgs --update下载软件包。
4.重新生成工程,并打开。
5.查看工程目录,包含了lwgps文件
6.直接编译,没有报错,下载到开发板。使用指令lwgps_example,查看打印信息,打印如下:
实际打印应该按照下面的格式才对。(分析应该是rt_kprintf未支持浮点打印)
仿真查看,符合预期,如下:
解析的数据,如下:
gps_rx_data[] = ""
"$GPRMC,183729,A,3907.356,N,12102.482,W,000.0,360.0,080301,015.5,E*6F\r\n"
"$GPRMB,A,,,,,,,,,,,,V*71\r\n"
"$GPGGA,183730,3907.356,N,12102.482,W,1,05,1.6,646.4,M,-24.1,M,,*75\r\n"
"$GPGSA,A,3,02,,,07,,09,24,26,,,,,1.6,1.6,1.0*3D\r\n"
"$GPGSV,2,1,08,02,43,088,38,04,42,145,00,05,11,291,00,07,60,043,35*71\r\n"
"$GPGSV,2,2,08,08,02,145,00,09,46,303,47,24,16,178,32,26,18,231,43*77\r\n"
"$PGRME,22.0,M,52.9,M,51.0,M*14\r\n"
"$GPGLL,3907.360,N,12102.481,W,183730,A*33\r\n"
"$PGRMZ,2062,f,3*2D\r\n"
"$PGRMM,WGS84*06\r\n"
"$GPBOD,,T,,M,,*47\r\n"
"$GPRTE,1,1,c,0*07\r\n"
"$GPRMC,183731,A,3907.482,N,12102.436,W,000.0,360.0,080301,015.5,E*67\r\n"
"$GPRMB,A,,,,,,,,,,,,V*71\r\n";
7.实际测试代码,main.c 如下:
#include <stdio.h>
#include <rtthread.h>
#include <rtdevice.h>
#include <board.h>
#include "lwgps.h"
static lwgps_t lwgps_temp;
/* defined the LED1 pin: PD4 */
#define LED1_PIN GET_PIN(D, 4)
int main(void)
{
int count = 1;
extern void lwgps2rtt_init(const char *uart_dev_name);
lwgps2rtt_init("uart5");//使用串口5通讯
/* set LED1 pin mode to output */
rt_pin_mode(LED1_PIN, PIN_MODE_OUTPUT);
while (count++)
{
rt_pin_write(LED1_PIN, PIN_HIGH);
rt_thread_mdelay(500);
rt_pin_write(LED1_PIN, PIN_LOW);
rt_thread_mdelay(500);
extern void lwgps2rtt_get_gps_info(lwgps_t *gps_info);
lwgps2rtt_get_gps_info(&lwgps_temp);//获取gps信息
// rt_kprintf("Valid status: %d\r\n", lwgps_temp.is_valid);
// rt_kprintf("Latitude: %f degrees\r\n", lwgps_temp.latitude);
// rt_kprintf("Longitude: %f degrees\r\n", lwgps_temp.longitude);
// rt_kprintf("Altitude: %f meters\r\n", lwgps_temp.altitude);
rt_kprintf("year: %d year\r\n", lwgps_temp.year);
rt_kprintf("month: %d month\r\n", lwgps_temp.month);
rt_kprintf("date: %d date\r\n", lwgps_temp.date);
rt_kprintf("hours: %d hours\r\n", lwgps_temp.hours);
rt_kprintf("minutes: %d minutes\r\n", lwgps_temp.minutes);
rt_kprintf("seconds: %d seconds\r\n", lwgps_temp.seconds);
}
return RT_EOK;
}
主要2个接口调用,lwgps2rtt_init("uart5");//使用串口5通讯和lwgps2rtt_get_gps_info(&lwgps_temp);//获取gps信息
编译,下载到开发板,看到打印出时间信息,如下:
系统运行一段时间报错,如图:
(rt_object_get_type(&timer->parent) == RT_Object_Class_Timer) assertion failed at function:rt_timer_stop, line number:542
解决办法:创建线程时增大线程栈即可,默认512改为了1024。如下:
个人公众号:嵌入式学习与实践