我遇到了与创建GPS跟踪器(RX和UART2)相关的问题,我可以通过UART1将第一个1024字节的数据包发送到PC。但是当我再次尝试回忆相同的功能时,我遇到了数据无法正确出现的问题。
我猜这是启用中断的事情,但不确定UART。
由于
PS。使用PIC32MX440256H微控制器,MPLAB写入,GPS模块到PIC UART2 RX和UART1在PC上显示。
输出到串行(PC):
<CL>GPS DATA TRACKER V.1
<CL>next is GPS1
<CL>$GPGGA,164445.792,3753.2311,S,14440.0408,E,1,04,1.8,21.6,M,2.9,M,,0000*42
<CL>$GPGSA,A,3,13,20,10,16,,,,,,,,,4.2,1.8,3.8*30
<CL>$GPGSV,2,1,07,13,71,181,39,16,43,125,41,10,38,238,34,20,22,006,32*79
<CL>$GPGSV,2,2,07,19,05,053,34,27,00,000,38,30,00,000,28*45
<CL>$GPRMC,164445.792,A,3753.2311,S,14440.0408,E,000.0,000.0,180314,,,A*7C
<CL>$GPVTG,000.0,T,,M,000.0,N,000.0,K,A*0D
<CL>$GPGGA,164446.792,3753.2311,S,14440.0408,E,1,04,1.8,21.6,M,2.9,M,,0000*41
<CL>$GPGSA,A,3,13,20,10,16,,,,,,,,,4.2,1.8,3.8*30
<CL>$GPGSV,2,1,07,13,71,181,40,16,43,125,41,10,38,238,34,20,22,006,32*77
<CL>$GPGSV,2,2,07,19,05,053,35,27,00,000,38,30,00,000,28*44
<CL>$GPRMC,164446.792,A,3753.2311,S,14440.0408,E,000.0,000.0,180314,,,A*7F
<CL>$GPVTG,000.0,T,,M,000.0,N,000.0,K,A*0D
<CL>$GPGGA,164447.792,3753.2311,S,14440.0408,E,1,04,1.8,21.6,M,2.9,M,,0000*40
<CL>$GPGSA,A,3,13,20,10,16,,,,,,,,,4.2,1.8,3.8*30
<CL>$GPGSV,2,1,07,13,71,181,39,16,43,125,41,10,38,238,34,20,22,006,32*79
<CL>$GPGSV,2,2,07,19,05,053,34,27,00,000,38,30,00,000,28*45
<CL>$GPRMC,164447.792,A,3753.2311,S,14440.0408,E,000.0,00
<CL>next is GPS2
<CL>0.0,1111111111111111111111111111111111111111111111111111111111111111111111111111111
111111111111111111111111111111111111111111111111111111111111111111111111111111111111111
11111111111111111111111111111111111111111111111111111111111111111111111111111
代码:
int main (void)
{
TRISEbits.TRISE0 = 0; // for breadboard LED
LATEbits.LATE0 = OFF;
TRISDbits.TRISD1 = 0; // PINGUINO LED2
LATDbits.LATD1 = OFF;
mJTAGPortEnable(0); // Disable JTAG
// Turn on the interrupts
INTEnableSystemMultiVectoredInt();
SYSTEMConfigPerformance(GetSystemClock());
mOSCSetPBDIV(OSC_PB_DIV_2);
//UINT32 UART1DataReceived;
//UINT32 UART2DataReceived;
UARTConfigure(UART1, UART_ENABLE_PINS_TX_RX_ONLY);
UARTSetFifoMode(UART1, UART_INTERRUPT_ON_TX_NOT_FULL | UART_INTERRUPT_ON_RX_NOT_EMPTY);
UARTSetLineControl(UART1, UART_DATA_SIZE_8_BITS | UART_PARITY_NONE | UART_STOP_BITS_1);
UARTSetDataRate(UART1, GetPeripheralClock(), 9600);
UARTEnable(UART1, UART_ENABLE_FLAGS(UART_PERIPHERAL | UART_RX | UART_TX));
UARTConfigure(UART2, UART_ENABLE_PINS_TX_RX_ONLY);
UARTSetFifoMode(UART2, UART_INTERRUPT_ON_TX_NOT_FULL | UART_INTERRUPT_ON_RX_NOT_EMPTY);
UARTSetLineControl(UART2, UART_DATA_SIZE_8_BITS | UART_PARITY_NONE | UART_STOP_BITS_1);
UARTSetDataRate(UART2, GetPeripheralClock(), 9600);
UARTEnable(UART2, UART_ENABLE_FLAGS(UART_PERIPHERAL | UART_RX | UART_TX));
SendDataUART1("\r\n", strlen("\r\n"));
SendDataUART1("GPS DATA TRACKER V.1",strlen("GPS DATA TRACKER V.1"));
SendDataUART1("\r\n", strlen("\r\n"));
GetDataGPS(gps1, 1024);
SendDataUART1("next is GPS1", strlen("next is GPS1"));
SendDataUART1("\r\n", strlen("\r\n"));
Delay_ms(1000) ;
SendDataUART1(gps1, strlen(gps1));
SendDataUART1("\r\n", strlen("\r\n"));
Delay_ms(1000) ;
SendDataUART1("next is GPS2", strlen("next is GPS2"));
SendDataUART1("\r\n", strlen("\r\n"));
Delay_ms(1000) ;
GetDataGPS(gps2, 1024);
Delay_ms(1000) ;
SendDataUART1(gps2, strlen(gps2));
SendDataUART1("\r\n", strlen("\r\n"));
Delay_ms(1000) ;
while(1);
}
void SendDataUART1(const char *buffer, UINT32 size)
{
while(size)
{
while(!UARTTransmitterIsReady(UART1))
;
UARTSendDataByte(UART1, *buffer);
buffer++;
size--;
}
while(!UARTTransmissionHasCompleted(UART1))
;
}
UINT32 GetDataUART1(char *buffer, UINT32 max_size)
{
UINT32 num_char;
num_char = 0;
while(num_char < max_size)
{
UINT8 character;
while(!UARTReceivedDataIsAvailable(UART1))
;
character = UARTGetDataByte(UART1);
if(character == '\r')
break;
*buffer = character;
buffer++;
num_char++;
}
return num_char;
}
void SendDataUART2(const char *buffer, UINT32 size)
{
while(size)
{
while(!UARTTransmitterIsReady(UART2))
;
UARTSendDataByte(UART2, *buffer);
buffer++;
size--;
}
while(!UARTTransmissionHasCompleted(UART2))
;
}
UINT32 GetDataGPS(char *buffer, UINT32 max_size)
{
UINT32 num_char;
num_char = 0;
while(num_char < max_size)
{
UINT8 character;
while(!DataRdyUART2())
;
character = ReadUART2();
// if(character == '\r')
// break;
*buffer = character;
buffer++;
num_char++;
}
return num_char;
}