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
Hi Ramana,
If you want your application to loop in the check_Uart1Receiver you need to use something like this:
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)
{
check_Uart1Receiver(void);
}
}
Hope it helps!
Best Regards,
Carlos Mendoza
Technical Support Engineer
Thanks for your reply Carlos.
I don't want to loop. Just i have to check the response of GSM module through uart0 receiver buffer and send tp back to uart1. I mean, want to execute only once for each AT command.
Thanks
Hi Ramana,
What code are you using in your interrupt handlers? I would recommend that you use the LPCOpen periph_uart_rb example as reference, this example shows how to use the UART in interrupt mode with transmit and receive ring buffers.
Best regards,
Carlos Mendoza