Arduino does a self reset

hy

I got a GSM Module hooked up to the arduino. I do parse the SMS
that get in from the Module and do some things afterwards.

Sometimes it can happen that a message does come in and the
Arduino does self reset and starts again in the void Setup().

Why does this happen? It can't be a buffer overflow I got a big
buffer and a routine to determine when a buffer does overflow...

Thx
Andy

It can't be a buffer overflow I got a big buffer

It could be for precisely that reason.
But we can't see your code, so we're just guessing.

If its an Arduino Uno/Duemilanove you only have 1K of RAM

If its an Arduino Uno/Duemilanove you only have 1K of RAM

Give or take 1K...
From: http://arduino.cc/en/Main/ArduinoBoardUno

SRAM 2 KB (ATmega328)

and a routine to determine when a buffer does overflow...

Or you could have lots of strings consuming RAM.
But we're still simply speculating.

thx for the advice,

I will post some code as soon as possible.
I use a Arduino Mega 1280 so should have some more RAM.
Can I determine how much RAM is used during a sketch is running?

Thx
Andy

I do parse the SMS
that get in from the Module and do some things afterwards.

Sometimes it can happen that a message does come in and the
Arduino does self reset and starts again in the void Setup().

I always thought of the Swiss as a very precise people.

I use a Arduino Mega 1280 so should have some more RAM.

Some more RAM?
If you've got enough for "The hunting of the Snark" I'd be surprised, much less "War and Peace".

It is all kind of relative,you see.

I would like to be more precise of course but my research shows that I can't force the reset by sending a huge message or with lots of special characters so it's kinda random....

while(Serial1.available() > 0){
  if(unlock_sms==0){
    bufferReadGSM[0]=Serial1.read();
    if(debug > 1)
      Serial.print(bufferReadGSM[0]);

    if(bufferReadGSM[0]=='\n' || bufferReadGSM[0]=='*' || bufferReadGSM[0] == '+'){
      unlock_sms=1;
    }
  }
  else{
    bufferReadGSM[counter]=Serial1.read();
    if(debug > 1)
      Serial.print(bufferReadGSM[counter]);
    if(bufferReadGSM[counter] == '\r'){
      unlock_sms=0;


      if (strncmp(bufferReadGSM, "*121*",5) == 0){
        char *parseptr_read = bufferReadGSM+5;
        int cou = 0;
        int value = int(parseptr_read[0])-48;    

        switch (value){
        case 1:
          sms_senden = 1;
          break;
        case 2:
          SmsMeldungOff = 1;
          if(debug > 0)
            Serial.println("-> SMS senden werden abgestellt");
          break;
        case 3:
          GSMoffStart = 1;
          if(debug > 0)
            Serial.println("-> GSM wird abgestllt, vor dem Start");
          break;
        case 4:
          wichtigeVariablen = 1;
          sms_senden = 1;
          if(debug > 0)
            Serial.println("-> Wichtige variablen werden gesendet");
          break;
        }
      }
      if (strncmp(bufferReadGSM, "Call Ready",10) == 0) {
        Serial.println("-> GSM Ready!");
      } 

      if (strncmp(bufferReadGSM, "0",1) == 0){
        if(debug > 0)
          Serial.println("-> OK");
      }
      if (strncmp(bufferReadGSM, "+CRING:",7) == 0 && calling < 1){
        if(debug > 0)
          Serial.println("-> ding dong");
      }

      if (strncmp(bufferReadGSM, "3",1) == 0){
        Serial.println("-> NO CARRIER");
        calling = 0;
      }
      if (strncmp(bufferReadGSM, "4",1) == 0){
        Serial.println("-> ERROR");
      }
      if (strncmp(bufferReadGSM, "6",1) == 0){
        Serial.println("-> NO DIALTONE");
      }
      if (strncmp(bufferReadGSM, "7",1) == 0){
        Serial.println("-> BUSY");
      }
      if (strncmp(bufferReadGSM, "8",1) == 0){
        Serial.println("-> CONNECT OK / NO ANSWER");
      }

      for(int a=0; a<=counter; a++){
        bufferReadGSM[a]=0;
      }
      counter=0;
    }
    else{
      counter++;
      if (counter == bufferSize){
        counter = 0;
        if (debug > 1)
          Serial.println("-> Buffer uerblauf");
        Serial1.flush();
      }
    }
  }
}

A lot of strings should go into the EEPROM or an external memory chip.
An array of chars like foo = "bar" will take RAM.

A lot of strings should go into the EEPROM

Compared to PROGMEM, EEPROM is tiny.
PROGMEM is where it should go, unless things are really tight.
But we're still speculating.

Dave, I mixed them both.. you're right.
:stuck_out_tongue:

I was thinking about the 168... Sorry

hmm tryed to use the sketch from

/*
 PROGMEM string demo
 How to store a table of strings in program memory (flash),
 and retrieve them.

 Information summarized from:
 http://www.nongnu.org/avr-libc/user-manual/pgmspace.html

 Setting up a table (array) of strings in program memory is slightly complicated, but
 here is a good template to follow. Setting up the strings is  a two-step process.
 First define the strings.

 */

#include <avr/pgmspace.h>

char string_0[] PROGMEM = "String 0";   // "String 0" etc are the strings to store - change them to your text.
char string_1[] PROGMEM = "String 1";
char string_2[] PROGMEM = "String 2";
char string_3[] PROGMEM = "String 3";
char string_4[] PROGMEM = "String 4";
char string_5[] PROGMEM = "String 5";


// Then set up a table to refer to your strings.

PGM_P PROGMEM string_table[] =	   // change string_table to anything you wish
{
  string_0,
  string_1,
  string_2,
  string_3,
  string_4,
  string_5 };

char buffer[30];    // make sure this is large enough for the largest string it must hold

void setup()
{
  Serial.begin(19200);
      Serial.println( "Test" );
}


void loop()
{
  /* Using the string table in program memory requires the use of special functions to retreive the data.
   The strcpy_P function copies a string from program space to a string in RAM. Make sure your receiving string
   in RAM is large enough to hold whatever you are retreiving from Program space.
   There is some neccessary casts and dereferencing going on, just follow the template.  */

  for (int i = 0; i < 6; i++)
  {
    strcpy_P(buffer, (char*)pgm_read_word(&(string_table[i])));
    Serial.println( buffer );
    delay( 500 );
  }
}

but when I look into the Serial Monitor it does always reset after the Setup routine has called.
So I just see my "Test" in the serial monitor....

I do use Arduino 0022 and an Arduino Mega 1280...
What's wrong with the code?

thx