# Error interfacing GSM sim900 with atmega32 [closed]

Hi all I am trying to interface GSM SIM900 with atmega32. I have a written a code in which if a user press a push button, a call will be made to a pre defined number. If we want to change the pre defined number, we can send message like CHANGE1234567890 where 1234567890 is the new number so that if anyone presses the push button, call will be made to this new number.

In my code I have made serial_Tx function which send string serially. serial_Rx which receive data and uart_put which transmit single character.

CODE:

 //serial initialize
void serial_Init()
{
UCSRB = (1<<TXEN) | (1<<RXEN);
UCSRC = (1<<UCSZ1)|(1<<UCSZ0)|(1<<URSEL);
UBRRL = 51;

}
//serial transmission function
void serial_Tx(char *str)
{
for (unsigned int i=0;str[i]!=0;i++)
{
UDR=str[i];
while(!(UCSRA&(1<<UDRE)));

}

}
//serial transmission single char
void uart_put(char data)
{
while(!(UCSRA & (1<<UDRE)))
{

}
UDR=data;
}
char serial_Rx()
{

while(!(UCSRA & (1<<RXC)))
{

}
return UDR;
}

char newnum[10];

char smscontent[200];
int len=0; ;
unsigned char slot;
char smscmd[16];
char delcmd[16];
char cfmcall[16];
char call[20];
char smsindi[14];
char data[15];
char calldata[10];
char confirmdata[10];
char deldata[10];

int main(void)
{
DDRA = 0x00;
DDRC = 0xFF;
PORTA = 0xFF;
PORTC = 0x00;
serial_Init();
PORTA=0xFF;
while(1)
{
//********FUNCTION TO GET SLOT NUMBER of received msg***********//
if (serial_Rx() != NULL)
{
//serial_Tx("done\n");

PORTC = 0x01;
for (int i=0;i<=14;i++)
{
data[i] = serial_Rx();
if(isdigit(data[i]))
{
//serial_Tx("enter\n");
PORTC = 0x02;
slot = data[i];
}

}

}
else
{
}
//**************LOOP END***********************//

//************FUNCTION TO SEND SMS COMMAND**********************//
uart_put(slot); //printing the SMS slot number
sprintf(smscmd,"AT+CMGR=%c\r\n",slot);

serial_Tx(smscmd);
for(int k =0; k<=200;k++)
{
smscontent[k] = serial_Rx();
uart_put(smscontent[k]);
}
//*****************LOOP END*******************************//

//***************FUNCTION TO EXTRACT NEW NUMBER*************//
for(int k =0;smscontent[k]!=NULL;k++) //smscontent[k]!=NULL
{
if (smscontent[k] == 'C')
{
if (smscontent[k+1] == 'H')
{
if (smscontent[k+2] == 'A')
{
if (smscontent[k+3] == 'N')
{
if (smscontent[k+4] == 'G')
{
if (smscontent[k+5] == 'E')
{

if(isdigit(smscontent[k+6]))
{
k=k+6;
serial_Tx("MATCH\n");
for (int i=0;i<=9;i++,k++)
{

newnum[i] = smscontent[k];

}

serial_Tx(newnum); // new number is stored in newnum

}

}
}

}
}
}

}
}

//*****************LOOP END******************************//

//*******************CALL function **********************//
if(PINA==0xFE) // if switch pressed then:
{

sprintf(call,"ATD%s;\r\n",newnum);
serial_Tx(call);

for(int j=0;j<=9;j++)
{
calldata[j] = serial_Rx();

}

if(strstr(calldata,"OK") != NULL)
{

for (int i = 0;i<=20;i++)
{
PORTC = 0x01; // led blink
_delay_ms(150);
PORTC = 0x00;
_delay_ms(150);
}

}
else
{
PORTC = 0x02; // led 2 on

}

}

//*************************LOOP END***********************************//
}
}


I am able to get the slot number of received message and I have also extracted the number from my msg. The problem is that now I have to replace the old number with new number in call function but its not working properly and even when I press the push button it doesnt function. Please help.

## closed as unclear what you're asking by Chris Stratton, Daniel Grillo, Peter Smith, Voltage Spike, PeterJAug 23 '16 at 14:34

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

• Maybe start with this page and see if you are issuing the same commands in the same time frames: tronixstuff.com/2014/01/08/… – Secto Kia Aug 1 '15 at 4:54
• Thanks Secto for sharing the link. But that link is for arduino. In arduino there are many libraries pre build so that you can directly use them. But I'll definetly read it. – anna carolina Aug 1 '15 at 5:00
• Does your call function work for a predefined number? Also, I'm not sure PINA==0xFE is the proper way to check a button, you should check that as atleast something should've happened? – Paul Aug 17 '15 at 7:46
• The point isn't to use their code. My point is that their code clearly contains the details the information exchanged and the timing involved. You should compare its logical communication algorithm to yours. – Secto Kia Aug 25 '15 at 11:15
• Is the button a momentary switch? Configure the button press input to be an interrupt. The way the loop is currently written doesn't ensure that the press will even be seen unless it's held down. – DigitalNinja May 19 '16 at 18:40