AnsweredAssumed Answered

LPC4337 locks when data is received into USART3

Question asked by Matthew Maslak on Sep 27, 2019
Latest reply on Oct 2, 2019 by jeremyzhou

I have a custom board using a LPC4337 (144 pins version). We have 4 UART devices, a serial port for status strings is USART0 (38400), UART1 (115200) is for the NTP Time Server, USART2 (38400) is for a GNSS module, and USART3 (57600) is for the serial port of an atomic clock that we are using. USART0, UART1, and USART2 all work fine, I can send and receive data with no issue. However on USART3 when I receive data, the micro locks up. All 4 ports use the exact same initialization function and Interrupt Handler functions modified for their unique UART number. I can sniff the Tx and Rx line and see the data is correct (correct command and response from the atomic clock). I looked in the manual to see if USART3 needed to be configured any differently than that other UARTs but I only saw that UART3 has an IdDA functionality that I'm not using. I cannot paste the whole, about 20 .c and additional .h files not including the LPC_chip_43XX adn LPC_board_nxp_LPCexpresso_4337 libraries but will post what I think is needed for this question:

 

 

Main Code:

initADC();

initSSPPins();

initFlashVars();
// initRamTest();

loadRamLocationsForDebugTest();

initUARTPins();

.

.

.

.

UARTFullInit(GPS_UART,DEFAULT_GPS_BAUDRATE);
UARTFullInit(STDIO_UART,settings.statBaudRate);
UARTFullInit(NB_UART,115200);
UARTFullInit(RB_UART,RB_BAUDRATE);

 

__________________________________________________________________________________________

 

UART.c

 

void initUARTPins(void)
{
/*UART 0*/
Chip_SCU_PinMuxSet(0x2, 0, (SCU_MODE_INACT | SCU_MODE_FUNC1)); /* P2.0 : UART0_TXD */
Chip_SCU_PinMuxSet(0x2, 1, (SCU_MODE_INACT | SCU_MODE_INBUFF_EN | SCU_MODE_ZIF_DIS | SCU_MODE_FUNC1)); /* P2.1 : UART0_RXD */

 

/*UART 2*/
Chip_SCU_PinMuxSet(0x2, 10, (SCU_MODE_INACT | SCU_MODE_FUNC2)); /* P1.15 : UART2_TXD */
Chip_SCU_PinMuxSet(0x2, 11, (SCU_MODE_INACT | SCU_MODE_INBUFF_EN | SCU_MODE_ZIF_DIS | SCU_MODE_FUNC2)); /* P1.16 : UART2_RXD */


/*UART 1*/
Chip_SCU_PinMuxSet(0x1, 14, (SCU_MODE_INACT | SCU_MODE_INBUFF_EN | SCU_MODE_ZIF_DIS | SCU_MODE_FUNC1)); /* P1.14 : UART1_RXD */
Chip_SCU_PinMuxSet(0x5, 6, (SCU_MODE_INACT | SCU_MODE_FUNC4)); /* P5.6 : UART1_TXD */

 

/*UART 3*/
Chip_SCU_PinMuxSet(0x2, 4, (SCU_MODE_INACT | SCU_MODE_INBUFF_EN | SCU_MODE_ZIF_DIS | SCU_MODE_FUNC2)); /* P2.4 : UART3_RXD */
Chip_SCU_PinMuxSet(0x2, 3, (SCU_MODE_INACT | SCU_MODE_FUNC2)); /* P2.3 : UART3_TXD */


}

 

 

void UARTFullInit(LPC_USART_T *pUART, uint32_t baudRate)
{
if(pUART == LPC_USART3)
{
NVIC_DisableIRQ(USART3_IRQn);
NVIC_ClearPendingIRQ(USART3_IRQn);
}
else if(pUART == LPC_USART0)
{
NVIC_DisableIRQ(USART0_IRQn);
NVIC_ClearPendingIRQ(USART0_IRQn);
}
else if(pUART == LPC_UART1)
{
NVIC_DisableIRQ(UART1_IRQn);
NVIC_ClearPendingIRQ(UART1_IRQn);
}
else if(pUART == LPC_USART2)
{
NVIC_DisableIRQ(USART2_IRQn);
NVIC_ClearPendingIRQ(USART2_IRQn);
}

Chip_UART_Init(pUART);
Chip_UART_SetBaudFDR(pUART, baudRate);
Chip_UART_ConfigData(pUART, UART_LCR_WLEN8 | UART_LCR_SBS_1BIT); /* Default 8-N-1 */
Chip_UART_SetupFIFOS(pUART, (UART_FCR_FIFO_EN));
Chip_UART_SetupFIFOS(pUART, (UART_FCR_FIFO_EN | UART_FCR_RX_RS | UART_FCR_TX_RS));

/* Enable UART Transmit */
Chip_UART_TXEnable(pUART);

/* Enable receive data and line status interrupt */
Chip_UART_IntEnable(pUART, (UART_IER_RBRINT | UART_IER_RLSINT));

if(pUART == LPC_USART3)
{
NVIC_ClearPendingIRQ(USART3_IRQn);
NVIC_EnableIRQ(USART3_IRQn);
}
else if(pUART == LPC_USART0)
{
NVIC_ClearPendingIRQ(USART0_IRQn);
NVIC_EnableIRQ(USART0_IRQn);
}
else if(pUART == LPC_UART1)
{
NVIC_ClearPendingIRQ(UART1_IRQn);
NVIC_EnableIRQ(UART1_IRQn);
}
else if(pUART == LPC_USART2)
{
NVIC_ClearPendingIRQ(USART2_IRQn);
NVIC_EnableIRQ(USART2_IRQn);
}

}

 

* Rb */
void UART3_IRQHandler(void){

/*Rx Handler*/


uint32_t status = RB_UART->IIR;

if( status & 0x2<<1 )
{
while (RB_UART->LSR & 0x1)
{

uint8_t temp = (LPC_UART1->RBR & 0xff);

if(temp == '\n')
{
/*Reset Buffer count*/
ComRxBuffCount_Rb = 0;
return;
}

/*Set buffer to incoming value*/
ComRxBuff_Rb[ComRxBuffCount_Rb] = temp;

if( temp == '\r' )
{

// if(ComRxBuff_Rb[0] == '0' || ComRxBuff_Rb[0] == '1')
{

CommandReady_Rb[ComRxIndex_Rb] = 1;
memcpy((void*)&ComVerBuff_Rb[ComRxIndex_Rb][0],(void*)&ComRxBuff_Rb[0],ComRxBuffCount_Rb + 1);
memcpy((void*)&ComVerBuff_Rb[ComRxIndex_Rb][0] + ComRxBuffCount_Rb + 1,"\0",1);
ComVerBuffCount_Rb[ComRxIndex_Rb] = ComRxBuffCount_Rb + 1;

/*Increment Received index count*/
if(++ComRxIndex_Rb >= MAXRBCOMSTRINGS) ComRxIndex_Rb = 0;

}

ComRxBuffCount_Rb = 0;
return;

}

 

/*Increment buffer index*/
ComRxBuffCount_Rb++;

/*Reset if over character limit*/
if(ComRxBuffCount_Rb > RB_COMBUFFSIZE - 1)
{
ComRxBuffCount_Rb = 0;
}

 

}
}

 

} //UART3_IRQHandler closing brace

_____________________________________________________________________________________________

 

 

As an experiment, I have ran the NMEA string from the GNSS into the Rx of USART (correcting the baud rate so both USARTs are 57600) and the micro locks up. I took off a buffer between the Tx of the atomic clock and the Rx of USART3 and the code runs without interruptions. So is there any special configuration needed for the USART3 especially with the Rx buffer/Interrupt?

 

Thanks in advance,

Matt

Outcomes