I am writing a C code for receiving battery using GSM modem SIM 800E. I am using AtMega16 uC. Here I have used AT commands to get battery info.
void uart_send(unsigned char ch) //Function to send via UART
{
while(!(UCSRA &(1<<UDRE)));
UDR=ch;
}
void bat() //Function to get battery info and send SMS via UART
{
int x;
char battery[16];
UCSRB &= ~(1<<UDRIE);
writecommand("AT+CBC"); //AT command to get battery status(My program stuck here)
for(int x = 0;x<20;x++) //Reading 20 characters by the response of AT+CBS
{
while(!(UCSRA & (1<<RXC)));
battery[x] = UDR;
}
UCSRB |= (1<<RXCIE);
for(int x=1;x<20;x++) //sending 20 characters to UART
{
uart_send(*battery);
}
}
int main()
{
DDRB=0xff; //PORT as output port for LCD
uart_init(); //initializing UART
_delay_ms(1000);
writecommand("AT");
writecommand("AT+CMGF=1"); //setting GSM to Text Mode
writecommand("AT+CNMI=2,0,2,0,0");
while(1)
{
bat();
transmit("AT+CMGS=\"+9195xxxxxxxx\"\r"); //Sending SMS with values in UART buffer
_delay_ms(10);
uart_send(26); // command to send SMS
}
When I run the code it stuck in the bat() function (at"AT+CBC") it displays the battery info on the LCD and terminal both but doesn't send it by sms and program doesn't proceed further. Please suggest me ways to get the info through SMS.
Edit
Regarding comments by Loongcat
I am receiving 20 characters after the comman "AT+CBC" then it should receive that. this is the loop for(int x = 0;x<20;x++)