Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Problem in reading data from GPS

Status
Not open for further replies.

kulks

Newbie level 6
Newbie level 6
Joined
Apr 25, 2013
Messages
14
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Visit site
Activity points
1,427
Hi,
I'm interfacing a skynav skm53 GPS with an ARM cortex LPC1768 microcontroller on board MCB1700. Here's the small code snippet for initialization of UART
and reading GPS data. I can see the characters coming in but I don't get them in desired sequence i.e NMEA format (starting $GPGGA).

Please let me know if there is anything wrong in my code.

uint32_t UARTInit( uint32_t PortNum, uint32_t baudrate )
{
uint32_t Fdiv;
uint32_t pclkdiv, pclk;

LPC_PINCON->PINSEL4 &= ~0x0000000F;
LPC_PINCON->PINSEL4 |= 0x0000000A; /* Enable RxD1 P2.1, TxD1 P2.0 */


if(PortNum == 1 )
/* By default, the PCLKSELx value is zero, thus, the PCLK for
all the peripherals is 1/4 of the SystemFrequency. */
/* Bit 8,9 are for UART1 */
pclkdiv = (LPC_SC->PCLKSEL0 >> 8) & 0x03;
switch ( pclkdiv )
{
case 0x00:
default:
pclk = SystemFrequency/4;
break;
case 0x01:
pclk = SystemFrequency;
break;
case 0x02:
pclk = SystemFrequency/2;
break;
case 0x03:
pclk = SystemFrequency/8;
break;
}

LPC_UART1->LCR = 0x83; /* 8 bits, no Parity, 1 Stop bit */
Fdiv = ( pclk / 16 ) / baudrate ; /*baud rate */
LPC_UART1->DLM = Fdiv / 256;
LPC_UART1->DLL = Fdiv % 256;
LPC_UART1->LCR = 0x03; /* DLAB = 0 */
LPC_UART1->FCR = 0x07; /* Enable and reset TX and RX FIFO. */

NVIC_EnableIRQ(UART1_IRQn);

LPC_UART1->IER = IER_RBR | IER_THRE | IER_RLS; /* Enable UART1 interrupt */
return (TRUE);
}
return( FALSE );



main.c

int main (void){

/* SystemClockUpdate() updates the SystemFrequency variable */
SystemClockUpdate();
UARTInit(1, 9600); /* baud rate setting */

GLCD_Init(); /* Initialize graphical LCD */

GLCD_Clear(White); /* Clear graphical LCD display */
GLCD_SetBackColor(White);
GLCD_SetTextColor(Blue);

while (1)
{


for(UART1Count=0;UART1Count<200;UART1Count++)
{
if((LPC_UART1->RBR) != '\0')
{
UART1Buffer[UART1Count] = LPC_UART1->RBR ; // IRQ handler is not getting invoked, that's why tried to read characters from RBR
// and found some characters too though not in NMEA format
}
}
for(UART1Count=0;UART1Count<200;UART1Count++)
{
if(UART1Buffer[UART1Count] == '$')
{
UART1Count = UART1Count + 1;
if(UART1Buffer[UART1Count] == 'G')
{
UART1Count = UART1Count + 1;
if(UART1Buffer[UART1Count] == 'P')
{
UART1Count = UART1Count + 1;
if(UART1Buffer[UART1Count] == 'G')
{
UART1Count = UART1Count + 1;
if(UART1Buffer[UART1Count] == 'G')
{
UART1Count = UART1Count + 1;
if(UART1Buffer[UART1Count] == 'A')
{
GLCD_DisplayString(Line2,"Hello World!"); // didn't reach here
}
else continue
}
else continue;
}
else continue;
}
else continue;
}
else continue;
}
}

}
}

IRQ_Handler (Not getting Invoked)

void UART1_IRQHandler (void)
{
uint8_t IIRValue, LSRValue;
uint8_t Dummy = Dummy;

IIRValue = LPC_UART1->IIR;

IIRValue >>= 1; /* skip pending bit in IIR */
IIRValue &= 0x07; /* check bit 1~3, interrupt identification */
if ( IIRValue == IIR_RLS ) /* Receive Line Status */
{
LSRValue = LPC_UART1->LSR;
/* Receive Line Status */
if ( LSRValue & (LSR_OE|LSR_PE|LSR_FE|LSR_RXFE|LSR_BI) )
{
/* There are errors or break interrupt */
/* Read LSR will clear the interrupt */
UART1Status = LSRValue;
Dummy = LPC_UART1->RBR; /* Dummy read on RX to clear
interrupt, then bail out */
return;
}
if ( LSRValue & LSR_RDR ) /* Receive Data Ready */
{
/* If no error on RLS, normal ready, save into the data buffer. */
/* Note: read RBR will clear the interrupt */
UART1Buffer[UART1Count] = LPC_UART1->RBR;
UART1Count++;
if ( UART1Count == BUFSIZE )
{
UART1Count = 0; /* buffer overflow */
}
}
}
else if ( IIRValue == IIR_RDA ) /* Receive Data Available */
{
/* Receive Data Available */
UART1Buffer[UART1Count] = LPC_UART1->RBR;
UART1Count++;
if ( UART1Count == BUFSIZE )
{
UART1Count = 0; /* buffer overflow */
}
}
else if ( IIRValue == IIR_CTI ) /* Character timeout indicator */
{
/* Character Time-out indicator */
UART1Status |= 0x100; /* Bit 9 as the CTI error */
}
else if ( IIRValue == IIR_THRE ) /* THRE, transmit holding register empty */
{
/* THRE interrupt */
LSRValue = LPC_UART1->LSR; /* Check status in the LSR to see if
valid data in U0THR or not */
if ( LSRValue & LSR_THRE )
{
UART1TxEmpty = 1;
}
else
{
UART1TxEmpty = 0;
}
}

}

Please help.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top