Atmega 328p -hangs

i have a problem with my Atmega328 interface with gsm Sim800c.
It works fine for 2 or 3 days after , microcontroller hangs and not come out of watch dog event.
. physically it needs to reset.

Please guide me to solve this problem. it is most needed solution because it is used in a product development

Thanks

"My car wouldn't start this morning.
I have a white car.
Can you tell me what is wrong?"

See the problem?

1 Like

Hmmm. Maybe something is wrong with the code you haven't posted.

Program for interface of GSM

I am Getting serial input data

void serialEvent()
{
inchar = Serial.read();
if(inchar!='\n'){ inputstring += inchar;}
else {input_stringcomplete = true;}
}

in main loop

if (input_stringcomplete)
{
Serialstringsep();
inputstring = "";
input_stringcomplete = false;
}

void Serialstringsep()
{

if (inputstring.indexOf("+CPBR:")>=0) //inputstring.startsWith("+CPBR: ")
{
int Index1=inputstring.indexOf(' ');
int Index2=inputstring.indexOf(',');
int Index3=inputstring.indexOf('"');
int Index4=inputstring.indexOf('"',Index3+1);
String sim1=inputstring.substring(Index1+1,Index2);
String simmnum=inputstring.substring(Index3+1,Index4);
int simc = sim1.toInt();

    if(simc==5){eewrite(552,String(simmnum));}
    if(simc==4){eewrite(539,String(simmnum));}
    if(simc==3){eewrite(526,String(simmnum));}
    if(simc==2){eewrite(513,String(simmnum));}
    if(simc==1){eewrite(500,String(simmnum));usetsms=true;}
  }

/*********************************SIM Contact Number *************************/
if (inputstring.indexOf("+CPBS:")>=0) //(inputstring.startsWith("+CPBS: "))
{
int Index1=inputstring.indexOf(',');
int Index2=inputstring.indexOf(',', Index1+1);
String simcontact = inputstring.substring(Index1+1,Index2);
int simc = simcontact.toInt();
eewrite(649,String(simc)); // Store Total Number from SIM card
eeread(649); simnum=UID;
phonenum=true;
}
/********************************Sim Insert **********************************/

if (inputstring.indexOf("+CSMINS:")>=0) //(inputstring.startsWith("+CSMINS: "))
{
int Index1=inputstring.indexOf(',');
String simvalue = inputstring.substring(Index1+1);//+CSMINS: 0,1
int simp =simvalue.toInt();

   if(simp==1){ simpresent=true;  usersetsimcard();} 
   if(simp==0){ simpresent=false; }
 }

/*******SMS UNREAD/

if (inputstring.indexOf("+CMTI:")>=0)//(inputstring.startsWith("+CMTI: "))
{
int Index1=inputstring.indexOf('"');
int Index2 = inputstring.indexOf('"', Index1+1);
int Index3 = inputstring.indexOf(',');
String smvalue = inputstring.substring(Index3+1);
gsm_smsread(smvalue);

}

/*****SMS READ/

if (inputstring.indexOf("+CMGR:")>=0) //(inputstring.startsWith("+CMGR: "))
{
int Index1 = inputstring.indexOf('"');
int Index2 = inputstring.indexOf('"', Index1+1);
int Index3 = inputstring.indexOf('"', Index2+1);
int Index4 = inputstring.indexOf('"', Index3+1);
int Index5 = inputstring.indexOf('"', Index4+1);
int Index6 = inputstring.indexOf('"', Index5+1);
int Index7 = inputstring.indexOf('"', Index6+1);
int Index8 = inputstring.indexOf('"', Index7+1);
int Index9 = inputstring.indexOf('"', Index7+1);

  rxnumstr     =  inputstring.substring(Index3+4, Index4);
  smsdate   =  inputstring.substring(Index7+1, Index8);
 
  int Index10=smsdate.indexOf("/");
  int Index11=smsdate.indexOf("/", Index10+1);
  int Index12=smsdate.indexOf(",");
  int Index13=smsdate.indexOf("+");
  syear    =  smsdate.substring(0, Index10);
  smonth   =  smsdate.substring(Index10+1, Index11);
  sdate    =  smsdate.substring(Index11+1, Index12);
  stime    =  smsdate.substring(Index12+1, Index13);
  
  n1=1;
}

/***************************************Message *****************************************************/
if(n1==2)
{
mess=inputstring; n1=0;
char msg[8];
mess.toCharArray(msg,8);

   /*******************************UNIT ON *********************************************/
    
    if((msg[0]=='U' || msg[0]=='u')&&(msg[1]=='O' || msg[1]=='o')&&(msg[2]=='N' || msg[2]=='n'))
      
      {  
        // relay on when i send the UON message
       
      }
   /*************************************************************************************/

Your using Sting functions on a ATmega328 on a commercial product ??

please tell any other method to get data from serial input

Start here

1 Like

Thanks so much sir. For ur valuable reply and information

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.