Собственно есть плата SK-MLPC1768 на которой установлен микроконтроллер LPC1768
есть GPS приемник gl8088s
подключил следующим образом:
ENA -> P2.8
TXD1 -> P2.1 (RXD1)
RXD1 -> P2.0 (TXD1)
RST -> P4.28
не могу разобраться как правильно настроить UART и что еще требуется сделать. То идут 0х00, то вообще по uart1 ничего не идет. Если замкнуть Р2.1 и Р2.0 то сообщения зеркально вроде идут.
собственно код
Спойлер
Код: Выделить всё
void gl8088s_init()
{
// RST init
LPC_PINCON->PINSEL9 &= 0xFCFFFFFF; //P4.28
LPC_PINCON->PINMODE9 &= 0xFCFFFFFF;
LPC_GPIO4 -> FIODIR |= 1 << gl8088s_RST_pin;
LPC_GPIO4 -> FIOSET |= 1 << gl8088s_RST_pin;
//ENA init
LPC_PINCON->PINSEL4 &= 0xFFFCFFFF;//P2.8
LPC_PINCON->PINMODE4 |= 0x00030000; //P2.8 Pull_down Enabled
LPC_GPIO2 -> FIODIR |= 1 << gl8088s_ENA_pin;
LPC_GPIO2 -> FIOCLR |= 1 << gl8088s_ENA_pin;
}
void gl8088s_enable()
{
LPC_GPIO2 -> FIOSET |= 1<< gl8088s_ENA_pin;
}
void gl8088s_disable()
{
LPC_GPIO2 -> FIOCLR |= 1<< gl8088s_ENA_pin;
}
void gl8088s_reset()
{
int i;
LPC_GPIO4 -> FIOCLR |= 1 << gl8088s_RST_pin;
for (i=0; i<0x5660; i++);
LPC_GPIO4 -> FIOSET |= 1 << gl8088s_RST_pin;
}
uint32_t UARTInit( uint32_t PortNum, uint32_t baudrate )
{
uint32_t Fdiv;
SystemFrequency = 18000000;
if ( PortNum == 0 )
{
LPC_PINCON->PINSEL0 = 0x00000050; /* RxD0 is P0.3 and TxD0 is P0.2 */
LPC_UART0->LCR = 0x83; /* 8 bits, no Parity, 1 Stop bit */ /* DLAB = 1 */
/* By default, the PCLKSELx value is zero, thus, the PCLK for
all the peripherals is 1/4 of the SystemFrequency. */
Fdiv = SystemFrequency/(16 * baudrate) ; /*baud rate, Fpclk: 18MHz */
LPC_UART0->DLM = Fdiv / 256; //00
LPC_UART0->DLL = Fdiv % 256; //0x38
LPC_UART0->FDR = 0xB5;
LPC_UART0->LCR = 0x03; /* DLAB = 0 */
LPC_UART0->FCR = 0x07; /* Enable and reset TX and RX FIFO. */
NVIC_EnableIRQ(UART0_IRQn);
LPC_UART0->IER = IER_RBR | IER_THRE | IER_RLS; /* Enable UART0 interrupt */
return (TRUE);
}
else if ( PortNum == 1 )
{
LPC_PINCON->PINSEL4 |= 0x0000000A; /* Enable RxD1 P2.1, TxD1 P2.0 */
LPC_UART1->LCR = 0x83; /* 8 bits, no Parity, 1 Stop bit */
/* By default, the PCLKSELx value is zero, thus, the PCLK for
all the peripherals is 1/4 of the SystemFrequency. */
// Fdiv = SystemFrequency/(16 * baudrate); /*baud rate */ //SystemFrequency
//LPC_UART1->DLM = Fdiv / 256;
// LPC_UART1->DLL = Fdiv % 256;
//LPC_UART1->FDR = 0xB5;
LPC_UART1->DLL = 9;
LPC_UART1->FDR = 0x21;
LPC_UART1->DLM = 0;
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 );
}
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 == uartBUFSIZE )
{
UART1Count = 0; /* buffer overflow */
}
}
}
else if ( IIRValue == IIR_RDA ) /* Receive Data Available */
{
/* Receive Data Available */
UART1Buffer[UART1Count] = LPC_UART1->RBR;
if(UART1Buffer[UART1Count]==0x0A)// конец сообщения
GPS_ready = READY;
else
GPS_ready = NOT_READY;
UART1Count++;
if ( UART1Count == uartBUFSIZE )
{
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;
}
}
}
void UARTSend( uint32_t portNum, uint8_t *BufferPtr, uint32_t Length )
{
LPC_UART0->IER = IER_THRE | IER_RLS;
if ( portNum == 0 )
{
while ( Length != 0 )
{
/* THRE status, contain valid data */
while ( !(UART0TxEmpty & 0x01) );
if (*BufferPtr != 'X')
{
BufferPtr+=0;
}
LPC_UART0->THR = *BufferPtr;
UART0TxEmpty = 0; /* not empty in the THR until it shifts out */
BufferPtr++;
Length--;
}
}
else
{
while ( Length != 0 )
{
/* THRE status, contain valid data */
while ( !(UART1TxEmpty & 0x01) );
LPC_UART1->THR = *BufferPtr;
UART1TxEmpty = 0; /* not empty in the THR until it shifts out */
BufferPtr++;
Length--;
}
}
LPC_UART0->IER = IER_THRE | IER_RLS | IER_RBR;
return;
}
int main()
{
int i;
uint8_t c1=0x0D, c2=0x0A;
GPS_ready=NOT_READY;
UART0=0;
SystemInit();
UARTInit(0,115200);
UARTSend(0,"345",3);
UARTInit(1,115200);
LPC_PINCON -> PINMODE4 |= 0x0000000A;
gl8088s_init();
gl8088s_enable();
gl8088s_reset();
while (!0)
{
if (GPS_ready == READY)
{
UARTSend(0,UART1Buffer,UART1Count);
UART1Count = 0;
GPS_ready = 0;
}
if (UART0==1)
{
UART0=0;
UARTSend(1,UART0Buffer,UART0Count);
UART0Count=0;
}
}
}
В даташите сказано что перед ресетом надо ноги юарта модуля глонасс вывести в высокоимендансное состояние (Z состояние). Это я как понимаю No pull-up/down состояние?


