//配置UBLOX NEO-6的更新速率 //measrate:测量时间间隔,单位为ms,最少不能小于200ms(5Hz) //reftime:参考时间,0=UTC Time;1=GPS Time(一般设置为1) void Ublox_Cfg_Rate(u16 measrate, u8 reftime) { _ublox_cfg_rate* cfg_rate = (_ublox_cfg_rate*)USART_TX_BUF; if (measrate < 200)return; //小于200ms,直接退出 cfg_rate->header = 0X62B5; //cfg header cfg_rate->id = 0X0806; //cfg rate id cfg_rate->dlength = 6; //数据区长度为6个字节. cfg_rate->measrate = measrate; //脉冲间隔,us cfg_rate->navrate = 1; //导航速率(周期),固定为1 cfg_rate->timeref = reftime; //参考时间为GPS时间 Ublox_CheckSum((u8*)(&cfg_rate->id), sizeof(_ublox_cfg_rate) - 4, &cfg_rate->cka, &cfg_rate->ckb); //while (DMA1_Channel7->CNDTR != 0); //等待通道7传输完成 //UART_DMA_Enable(DMA1_Channel7, sizeof(_ublox_cfg_rate)); //通过dma发送出去 }
//配置UBLOX NEO-6的更新速率 //measrate:测量时间间隔,单位为ms,最少不能小于200ms(5Hz) //reftime:参考时间,0=UTC Time;1=GPS Time(一般设置为1) void Ublox_Cfg_Rate(u16 measrate, u8 reftime) { u8 USART_TX_BUF[0xff]; _ublox_cfg_rate *cfg_rate = (_ublox_cfg_rate *)USART_TX_BUF; if (measrate < 200)return; //小于200ms,直接退出 cfg_rate->header = 0X62B5; //cfg header cfg_rate->id = 0X0806; //cfg rate id cfg_rate->dlength = 6; //数据区长度为6个字节. cfg_rate->measrate = measrate; //脉冲间隔,us cfg_rate->navrate = 1; //导航速率(周期),固定为1 cfg_rate->timeref = reftime; //参考时间为GPS时间 Ublox_CheckSum((u8 *)(&cfg_rate->id), sizeof(_ublox_cfg_rate) - 4, &cfg_rate->cka, &cfg_rate->ckb); Sys_sPrintf(GPS_USART, USART_TX_BUF, sizeof(_ublox_cfg_tp)); USART_DMA_Enable(GPS_USART, sizeof(_ublox_cfg_rate)); //通过dma发送出去 }
//配置保存 //将当前配置保存在外部EEPROM里面 //返回值:0,执行成功;1,执行失败. u8 Ublox_Cfg_Cfg_Save(void) { u8 i; _ublox_cfg_cfg *cfg_cfg=(_ublox_cfg_cfg *)USART2_TX_BUF; cfg_cfg->header=0X62B5; //cfg header cfg_cfg->id=0X0906; //cfg cfg id cfg_cfg->dlength=13; //数据区长度为13个字节. cfg_cfg->clearmask=0; //清除掩码为0 cfg_cfg->savemask=0XFFFF; //保存掩码为0XFFFF cfg_cfg->loadmask=0; //加载掩码为0 cfg_cfg->devicemask=4; //保存在EEPROM里面 Ublox_CheckSum((u8*)(&cfg_cfg->id),sizeof(_ublox_cfg_cfg)-4,&cfg_cfg->cka,&cfg_cfg->ckb); while(DMA1_Channel7->CNDTR!=0); //等待通道7传输完成 UART_DMA_Enable(DMA1_Channel7,sizeof(_ublox_cfg_cfg)); //通过dma发送出去 for(i=0;i<6;i++)if(Ublox_Cfg_Ack_Check()==0)break; //EEPROM写入需要比较久时间,所以连续判断多次 return i==6?1:0; }
//配置NMEA输出信息格式 //msgid:要操作的NMEA消息条目,具体见下面的参数表 // 00,GPGGA;01,GPGLL;02,GPGSA; // 03,GPGSV;04,GPRMC;05,GPVTG; // 06,GPGRS;07,GPGST;08,GPZDA; // 09,GPGBS;0A,GPDTM;0D,GPGNS; //uart1set:0,输出关闭;1,输出开启. //返回值:0,执行成功;其他,执行失败. u8 Ublox_Cfg_Msg(u8 msgid,u8 uart1set) { _ublox_cfg_msg *cfg_msg=(_ublox_cfg_msg *)USART2_TX_BUF; cfg_msg->header=0X62B5; //cfg header cfg_msg->id=0X0106; //cfg msg id cfg_msg->dlength=8; //数据区长度为8个字节. cfg_msg->msgclass=0XF0; //NMEA消息 cfg_msg->msgid=msgid; //要操作的NMEA消息条目 cfg_msg->iicset=1; //默认开启 cfg_msg->uart1set=uart1set; //开关设置 cfg_msg->uart2set=1; //默认开启 cfg_msg->usbset=1; //默认开启 cfg_msg->spiset=1; //默认开启 cfg_msg->ncset=1; //默认开启 Ublox_CheckSum((u8*)(&cfg_msg->id),sizeof(_ublox_cfg_msg)-4,&cfg_msg->cka,&cfg_msg->ckb); while(DMA1_Channel7->CNDTR!=0); //等待通道7传输完成 UART_DMA_Enable(DMA1_Channel7,sizeof(_ublox_cfg_msg)); //通过dma发送出去 return Ublox_Cfg_Ack_Check(); }
//配置UBLOX NEO-6的时钟脉冲输出 //interval:脉冲间隔 //length:脉冲宽度 //status:脉冲配置:1,高电平有效;0,关闭;-1,低电平有效. void Ublox_Cfg_Tp(u32 interval, u32 length, signed char status) { _ublox_cfg_tp* cfg_tp = (_ublox_cfg_tp*)USART_TX_BUF; cfg_tp->header = 0X62B5; //cfg header cfg_tp->id = 0X0706; //cfg tp id cfg_tp->dlength = 20; //数据区长度为20个字节. cfg_tp->interval = interval;//脉冲间隔,us cfg_tp->length = length; //脉冲宽度,us cfg_tp->status = status; //时钟脉冲配置 cfg_tp->timeref = 0; //参考UTC 时间 cfg_tp->flags = 0; //flags为0 cfg_tp->reserved = 0; //保留位为0 cfg_tp->antdelay = 820; //天线延时为820ns cfg_tp->rfdelay = 0; //RF延时为0ns cfg_tp->userdelay = 0; //用户延时为0ns Ublox_CheckSum((u8*)(&cfg_tp->id), sizeof(_ublox_cfg_tp) - 4, &cfg_tp->cka, &cfg_tp->ckb); //while (DMA1_Channel7->CNDTR != 0); //等待通道7传输完成 //UART_DMA_Enable(DMA1_Channel7, sizeof(_ublox_cfg_tp)); //通过dma发送出去 }
//配置UBLOX NEO-6的时钟脉冲输出 //interval:脉冲间隔 //length:脉冲宽度 //status:脉冲配置:1,高电平有效;0,关闭;-1,低电平有效. void Ublox_Cfg_Tp(u32 interval, u32 length, signed char status) { u8 USART_TX_BUF[0xff]; _ublox_cfg_tp *cfg_tp = (_ublox_cfg_tp *)USART_TX_BUF; cfg_tp->header = 0X62B5; //cfg header cfg_tp->id = 0X0706; //cfg tp id cfg_tp->dlength = 20; //数据区长度为20个字节. cfg_tp->interval = interval;//脉冲间隔,us cfg_tp->length = length; //脉冲宽度,us cfg_tp->status = status; //时钟脉冲配置 cfg_tp->timeref = 0; //参考UTC 时间 cfg_tp->flags = 0; //flags为0 cfg_tp->reserved = 0; //保留位为0 cfg_tp->antdelay = 820; //天线延时为820ns cfg_tp->rfdelay = 0; //RF延时为0ns cfg_tp->userdelay = 0; //用户延时为0ns Ublox_CheckSum((u8 *)(&cfg_tp->id), sizeof(_ublox_cfg_tp) - 4, &cfg_tp->cka, &cfg_tp->ckb); Sys_sPrintf(GPS_USART, USART_TX_BUF, sizeof(_ublox_cfg_tp)); USART_DMA_Enable(GPS_USART, sizeof(_ublox_cfg_tp)); //通过dma发送出去 }
//配置NMEA输出信息格式 //baudrate:波特率,4800/9600/19200/38400/57600/115200/230400 //返回值:0,执行成功;其他,执行失败(这里不会返回0了) u8 Ublox_Cfg_Prt(u32 baudrate) { _ublox_cfg_prt *cfg_prt=(_ublox_cfg_prt *)USART2_TX_BUF; cfg_prt->header=0X62B5; //cfg header cfg_prt->id=0X0006; //cfg prt id cfg_prt->dlength=20; //数据区长度为20个字节. cfg_prt->portid=1; //操作串口1 cfg_prt->reserved=0; //保留字节,设置为0 cfg_prt->txready=0; //TX Ready设置为0 cfg_prt->mode=0X08D0; //8位,1个停止位,无校验位 cfg_prt->baudrate=baudrate; //波特率设置 cfg_prt->inprotomask=0X0007;//0+1+2 cfg_prt->outprotomask=0X0007;//0+1+2 cfg_prt->reserved4=0; //保留字节,设置为0 cfg_prt->reserved5=0; //保留字节,设置为0 Ublox_CheckSum((u8*)(&cfg_prt->id),sizeof(_ublox_cfg_prt)-4,&cfg_prt->cka,&cfg_prt->ckb); while(DMA1_Channel7->CNDTR!=0); //等待通道7传输完成 UART_DMA_Enable(DMA1_Channel7,sizeof(_ublox_cfg_prt)); //通过dma发送出去 delay_ms(200); //等待发送完成 USART2_Init( baudrate); //重新初始化串口2 return Ublox_Cfg_Ack_Check();//这里不会反回0,因为UBLOX发回来的应答在串口重新初始化的时候已经被丢弃了. }