Microcontroller › AVR › ATMEGA16A : Unable to receive OK response from SIM900 gsm module
- This topic has 0 replies, 1 voice, and was last updated 11 years ago by
Narendra Saini.
-
AuthorPosts
-
April 13, 2014 at 9:58 am #3040
Narendra Saini
ParticipantI have been trying to interface Atmega16 and GSM Modem Sim900 through USART to send and receive sms. I am able to send SMS from Atmega16 using Sim900.
But I am not able to receive the ‘received SMS’s from sim900. I have tried it through (a) polling the RXC flag and (b) RXC interrupt. But none of the approaches is working.
So, to see if anything is being received by the RX pin (of Atmega16) at all, I have written a code to check if an OK response is being received after initialising the GSM modem by sending “AT” from Atmega16. I have used LEDs to know if OK response is received or not.
When executed, LEDs indicate that OK response is not being received by Atmega16. But when the GSM modem is connected to Hyperterminal using serial port and the Atmega16 is disconnected, I am getting OK response when “AT” is sent in Hyperterminal.
Please provide any suggestion and solution to this problem.
Thank you.Code :
#define RECEIVE_BUFF_SIZE 64
volatile uint8_t UQFront;
volatile int8_t UQEnd;
volatile char URBuff[RECEIVE_BUFF_SIZE];
int main(void)
{
char *response;
USARTInit(5); // Baud rate = 9600
DDRB=0xFF;
// Initialize GSM Modem
UWriteString(“ATr”);
_delay_ms(1500);
UWriteString(“ATE0r”);
_delay_ms(1500);
UWriteString(“AT+CMGF=1r”);
_delay_ms(1500);
//
UQFront=UQEnd=-1;
UWriteString(“ATr”); // Sending AT again to check if OK response is received
_delay_ms(7000);
UReadBuffer(response,6);
SIM300CheckResponse(response,”OK”,6);
}
void USARTInit(uint16_t ubrrvalue)
{
//Setup queque
UQFront=UQEnd=-1;
//Set Baud rate
UBRRH=(unsigned char)(ubrrvalue>>;
UBRRL=(unsigned char)ubrrvalue;
/*Set Frame Format
Asynchronous mode
No Parity
1 StopBit
char size 8
*/
UCSRC=(1<<URSEL)|(3<<UCSZ0);
UCSRB=(1<<RXCIE)|(1<<RXEN)|(1<<TXEN);
sei();
}
//The USART ISR
ISR(USART_RXC_vect)
{
//Read the data
char data=UDR;
//Now add it to queque
if(((UQEnd==RECEIVE_BUFF_SIZE-1) && UQFront==0) || ((UQEnd+1)==UQFront))
{
//Q Full
UQFront++;
if(UQFront==RECEIVE_BUFF_SIZE) UQFront=0;
}
if(UQEnd==RECEIVE_BUFF_SIZE-1)
UQEnd=0;
else
UQEnd++;
URBuff[UQEnd]=data;
if(UQFront==-1) UQFront=0;
}
char UReadData()
{
char data;
//Check if queque is empty
if(UQFront==-1)
return 0;
data=URBuff[UQFront];
if(UQFront==UQEnd)
{
//If single data is left
//So empty queque
UQFront=UQEnd=-1;
}
else
{
UQFront++;
if(UQFront==RECEIVE_BUFF_SIZE)
UQFront=0;
}
return data;
}
void UWriteData(char data)
{
//Wait For Transmitter to become ready
while(!(UCSRA & (1<<UDRE)));
//Now write
UDR=data;
}
void UWriteString(char *str)
{
while((*str)!=’