GPS数据采集显示,实时更新(STM32F103RBT6)
2 E币
成为会员,免费下载资料
文件大小:858.52 KB
上传者:dancelectric
时间:2013-11-26 20:25:24
下载量:10
前几天在am这买的GPS,调个usart3都调了半天,想在主程序里加上临界区,即时禁止和开启接收中断
不知道怎么用
USART_ITConfig(USART3, USART_IT_RXNE, DISABLE);
DoSomthing();
USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);
这对函数
一用就少数据 - -!
后来投机取巧绕过了这个问题,直接在中断里面处理字符串,在外面显示,避开了这个疑点,现在可以正常工作了。
//=================== stm32f10x_it.c ===============================================================================
void USART3_IRQHandler(void)
{
unsigned int temp = 0;
unsigned char *p_data = 0;
unsigned char *p_data_temp = 0;
unsigned char *p_GPS_type = 0;
unsigned int com_cnt = 0; //number of the comment symbol
temp = temp;
//static unsigned int GPS_data_cnt = 0;
if(USART_GetITStatus(USART3, USART_IT_RXNE) != RESET)
{
USART_ClearITPendingBit(USART3, USART_IT_RXNE);
flag_usart3Rx = 1;
usart3_data_r = USART_ReceiveData(USART3);
// RXNE pending bit can be also cleared by a read to the USART_DR register (USART_ReceiveData())
*p_GPS_data_buff = usart3_data_r;
if( usart3_data_r == 0x0A )
{
//USART_ITConfig(USART3, USART_IT_RXNE, DISABLE);
LED3_ON();
flag_GPS_data_updated = 1;
*(p_GPS_data_buff + 1) = '\0';
p_GPS_data_buff = GPS_data_buff;
}
else
{
LED3_OFF();
flag_GPS_data_updated = 0;
p_GPS_data_buff++;
}
if( flag_GPS_data_updated )
{
p_data = &GPS_data_buff[1];
p_GPS_keyword = GPS_keyword;
while( p_GPS_keyword < &GPS_keyword[5] )
{
*p_GPS_keyword++ = *p_data++;
}
*p_GPS_keyword = '\0';
if( strcmp( GPS_keyword, "GPGGA" ) == 0 )
{
com_cnt = 0;
for( p_data = &GPS_data_buff[6]; *p_data != '\0'; p_data++ )
{
if( *p_data == ',' )
{
com_cnt += 1;
if( com_cnt == 2 )
{
p_GPS_type = GPS_data.latitude;
p_data_temp = p_data + 1;
while( *p_data_temp != ',' )
{
*p_GPS_type++ = *p_data_temp++;
}
//*p_GPS_type = '\0';
p_data = p_data_temp - 1;
}
else if( com_cnt == 3 )
{
p_GPS_type = &GPS_data.lat_ew;
p_data_temp = p_data + 1;
while( *p_data_temp != ',' )
{
*p_GPS_type++ = *p_data_temp++;
}
//*p_GPS_type = '\0';
p_data = p_data_temp - 1;
}
else if( com_cnt == 4 )
{
p_GPS_type = GPS_data.longitude;
p_data_temp = p_data + 1;
while( *p_data_temp != ',' )
{
*p_GPS_type++ = *p_data_temp++;
}
//*p_GPS_type = '\0';
p_data = p_data_temp - 1;
}
else if( com_cnt == 5 )
{
p_GPS_type = &GPS_data.long_ns;
p_data_temp = p_data + 1;
while( *p_data_temp != ',' )
{
*p_GPS_type++ = *p_data_temp++;
}
//*p_GPS_type = '\0';
p_data = p_data_temp - 1;
}
else if( com_cnt == 7 )
{
p_GPS_type = GPS_data.satellites;
p_data_temp = p_data + 1;
while( *p_data_temp != ',' )
{
*p_GPS_type++ = *p_data_temp++;
}
//*p_GPS_type = '\0';
p_data = p_data_temp - 1;
}
else if( com_cnt == 9 )
{
p_GPS_type = GPS_data.altitude;
p_data_temp = p_data + 1;
while( *p_data_temp != ',' )
{
*p_GPS_type++ = *p_data_temp++;
}
//*p_GPS_type = '\0';
p_data = p_data_temp - 1;
}
else
{
continue;
}
}
}
}
else if( strcmp( GPS_keyword, "GPGSA" ) == 0 )
{
}
else if( strcmp( GPS_keyword, "GPRMC" ) == 0 )
{
com_cnt = 0;
for( p_data = &GPS_data_buff[6]; *p_data != '\0'; p_data++ )
{
if( *p_data == ',' )
{
com_cnt += 1;
if( com_cnt == 1 )
{
p_GPS_type = GPS_data.time;
p_data_temp = p_data + 1;
while( *p_data_temp != ',' )
{
*p_GPS_type++ = *p_data_temp++;
}
p_data = p_data_temp - 1;
}
else if( com_cnt == 2 )
{
p_GPS_type = &GPS_data.status;
p_data_temp = p_data + 1;
while( *p_data_temp != ',' )
{
*p_GPS_type++ = *p_data_temp++;
}
p_data = p_data_temp - 1;
}
else if( com_cnt == 9 )
{
p_GPS_type = GPS_data.date;
p_data_temp = p_data + 1;
while( *p_data_temp != ',' )
{
*p_GPS_type++ = *p_data_temp++;
}
p_data = p_data_temp - 1;
}
else
{
continue;
}
}
}
}
else if( strcmp( GPS_keyword, "GPGSV" ) == 0 )
{
com_cnt = 0;
for( p_data = &GPS_data_buff[6]; *p_data != '\0'; p_data++ )
{
if( *p_data == ',' )
{
com_cnt += 1;
if( com_cnt == 3 )
{
p_GPS_type = GPS_data.satellites_inview;
p_data_temp = p_data + 1;
while( *p_data_temp != ',' )
{
*p_GPS_type++ = *p_data_temp++;
}
p_data = p_data_temp - 1;
}
else if( com_cnt == 4 )
{
p_GPS_type = GPS_data.satellites_id;
p_data_temp = p_data + 1;
while( *p_data_temp != ',' )
{
*p_GPS_type++ = *p_data_temp++;
}
p_data = p_data_temp - 1;
}
else
{
continue;
}
}
}
}
else
{
}
}
else
{
}
//printf( "%c", usart3_data_r );
//Wait_ms(1); //Why???????
}
}
//=================== gps.h ========================
/************************ (C) COPYLEFT 2010 Leafgrass *************************
* File Name : gps.h
* Author : Librae
* Last Modified Date : 08/19/2010
* Description : Provide GPS related functions and variables.
******************************************************************************/
/* Define to prevent recursive inclusion ----------------------------------- */
#ifndef __GPS_H__
#define __GPS_H__
/* Includes ---------------------------------------------------------------- */
/* Exported types ---------------------------------------------------------- */
typedef struct type_GPS_data
{
unsigned char status;
unsigned char lat_ew;
unsigned char latitude[11];
unsigned char long_ns;
unsigned char longitude[12];
unsigned char altitude[6];
unsigned char date[7];
unsigned char time[11];
unsigned char satellites[3];
unsigned char satellites_inview[3];
unsigned char satellites_id[3];
unsigned char speed;
//int direction;
float hdop;
}t_GPS_data;
/* Exported constants ------------------------------------------------------ */
/* Exported macro ---------------------------------------------------------- */
/* Exported variables ------------------------------------------------------ */
extern unsigned char GPS_keyword[5];
extern unsigned char GPS_data_buff[80];
extern unsigned char *p_GPS_data_buff;
extern unsigned char *p_GPS_keyword;
extern t_GPS_data GPS_data;
extern BOOLEAN flag_GPS_data_updated;
extern BOOLEAN flag_GPS_data_processed;
/* Exported functions ------------------------------------------------------ */
void GPS_Test(void);
#endif
/************************ (C) COPYLEFT 2010 Leafgrass ************************/
//=================== gps.c ===========================================================================
/************************ (C) COPYLEFT 2010 Leafgrass *************************
* File Name : gps.c
* Author : Librae
* Last Modified Date : 08/19/2010
* Description : This file provides the definition of
GPS related functions and variables.
******************************************************************************/
/* Includes -----------------------------------------------------------------*/
#include "includes.h"
/* Private typedef ----------------------------------------------------------*/
/* Private define -----------------------------------------------------------*/
/* Private macro ------------------------------------------------------------*/
/* Private variables --------------------------------------------------------*/
unsigned char GPS_keyword[5];
unsigned char GPS_data_buff[80];
unsigned char *p_GPS_data_buff = GPS_data_buff;
unsigned char *p_GPS_keyword = GPS_keyword;
t_GPS_data GPS_data;
BOOLEAN flag_GPS_data_updated = 1;
BOOLEAN flag_GPS_data_processed = 0;
/* Private function prototypes ----------------------------------------------*/
/* Private functions --------------------------------------------------------*/
void GPS_Test(void)
{
LCD_DispString( "GPS Test", YELLOW, BLACK, 11, 1 );
LCD_DispString( "Keyword: ", CYAN, BLACK, 0, 6 );
LCD_DispString( "Latitude: ", CYAN, BLACK, 0, 7 );
LCD_DispString( "Longitude: ", CYAN, BLACK, 0, 8 );
LCD_DispString( "Altitude: ", CYAN, BLACK, 0, 10 );
LCD_DispString( "Status: ", CYAN, BLACK, 0, 11 );
LCD_DispString( "UTC Time: ", CYAN, BLACK, 0, 12 );
LCD_DispString( "UTC Date: ", CYAN, BLACK, 0, 13 );
LCD_DispString( "Satellites used: ", CYAN, BLACK, 0, 15 );
LCD_DispString( "Satellites in view: ", CYAN, BLACK, 0, 16 );
LCD_DispString( "Satellites ID: ", CYAN, BLACK, 0, 17 );
for(;;)
{
if( flag_GPS_data_updated )
{
LCD_Clear_SelectArea( BLACK, 0, 48, 240, 48 );
LCD_DispString( GPS_data_buff, WHITE, BLACK, 0, 3 );
LCD_DispString( GPS_keyword, WHITE, BLACK, 9, 6 );
LCD_DispChar( GPS_data.lat_ew, WHITE, BLACK, 10, 7 );
LCD_DispString( GPS_data.latitude, WHITE, BLACK, 12, 7 );
LCD_DispChar( GPS_data.long_ns, WHITE, BLACK, 11, 8 );
LCD_DispString( GPS_data.longitude, WHITE, BLACK, 13, 8 );
LCD_DispString( GPS_data.altitude, WHITE, BLACK, 10, 10 );
LCD_DispChar( GPS_data.status, RED, BLACK, 8, 11 );
LCD_DispString( GPS_data.time, WHITE, BLACK, 10, 12 );
LCD_DispString( GPS_data.date, WHITE, BLACK, 10, 13 );
LCD_DispString( GPS_data.satellites, WHITE, BLACK, 17, 15 );
LCD_DispString( GPS_data.satellites_inview, WHITE, BLACK, 20, 16 );
LCD_DispString( GPS_data.satellites_id, WHITE, BLACK, 15, 17 );
flag_GPS_data_updated = 0;
//USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);
}
if( flag_usart3Rx )
{
flag_usart3Rx = 0;
}
}
}
/************************ (C) COPYLEFT 2010 Leafgrass ************************/
下面是keil工程
代码主要在gps.h gps.c 和 stm32f10x_it.c里
展开》
折叠》