AnsweredAssumed Answered

Uart issue in receiving check condition

Question asked by ramana madishetty on Oct 2, 2017
Latest reply on Oct 12, 2017 by Carlos_Mendoza

Hi, Am working on LPC1768 with SIM900A GSM.GPRS module for sending the dynamic data to the server.

 

Initially am trying to send some AT commands through UART1 and receives back (activated the UART1 interrupt for receiving the response). the response of SIM900 module and display it through UART0.

 

Issue in the code, it perfectly works when i use while loop to send the buffer of UART1 to UART0. But when i use if condition it doesn't work as expected. 

 

Below code works fine and receive the buffer and send it to UART0

 

int main()
{
SystemInit(); //Clock and PLL configuration

/* Initialize All the Four UARTs with different Baud rate */
UART0_Init(9600);
NVIC_EnableIRQ(UART0_IRQn);
LPC_UART0->IER = IER_RBR | IER_THRE | IER_RLS; /* Enable UART0 interrupt */

UART1_Init(9600); // Intialize uart1
NVIC_EnableIRQ(UART1_IRQn);
LPC_UART1->IER = IER_RBR | IER_THRE | IER_RLS; /* Enable UART1 interrupt */

UART0_TxString("Testing the GPRS\n\r");
UART1Count=0;

gsm_get_operator(); // Get and show operator

DELAY_ms(500);


while (1)
{ /* Loop forever */

if( UART1Count != 0 )
{
LPC_UART1->IER = IER_THRE | IER_RLS; /* Disable RBR */

UARTSend( 0, (uint8_t *)UART1Buffer, UART1Count );
UART1Count = 0;
LPC_UART1->IER = IER_THRE | IER_RLS | IER_RBR; /* Re-enable RBR */
}

}

 

// Function that get the preferred operator, and show it on the LCD
void gsm_get_operator(void)
{
UART0_TxString("AT+CPOL?\r\n"); // printing it in terminal 
UART1_TxString("AT+CPOL?\r\n");
}

 

Same if condition inside a while loop replaced with function. But it doesn't work so.. See below code..

 

 


int main()
{
SystemInit(); //Clock and PLL configuration

/* Initialize All the Four UARTs with different Baud rate */
UART0_Init(9600);
NVIC_EnableIRQ(UART0_IRQn);
LPC_UART0->IER = IER_RBR | IER_THRE | IER_RLS; /* Enable UART0 interrupt */

UART1_Init(9600); // Intialize uart1
NVIC_EnableIRQ(UART1_IRQn);
LPC_UART1->IER = IER_RBR | IER_THRE | IER_RLS; /* Enable UART1 interrupt */

UART0_TxString("Testing the GPRS\n\r");
UART1Count=0;

gsm_get_operator(); // Get and show operator

check_Uart1Receiver(void)

DELAY_ms(500);


while (1)


}

void check_Uart1Receiver(void)
{
if( UART1Count != 0 )
{
LPC_UART1->IER = IER_THRE | IER_RLS; /* Disable RBR */
UARTSend( 0, (uint8_t *)UART1Buffer, UART1Count );
UART1Count = 0;
LPC_UART1->IER = IER_THRE | IER_RLS | IER_RBR; /* Re-enable RBR */
}
}

// Function that get the preferred operator, and show it on the LCD
void gsm_get_operator(void)
{
UART0_TxString("AT+CPOL?\r\n");  // printing it in terminal 
UART1_TxString("AT+CPOL?\r\n");
}

 

Thanks

Outcomes