code restarts to setup()

void loop() // run over and over
{//Serial.print("x");
if (flag == 1)
fill_buffer();
if (digitalRead(Call) == HIGH) // Call pin is low i.e. nothing is getting recived
{
// Serial.print("2freeMemory()=");
//Serial.println(freeMemory());
//empty_buffer();
// measure_pow();
}
}
void fill_buffer_flag()
{flag = 1;delay(10);}

void fill_buffer()
{ detachInterrupt(0);

Serial.print("3freeMemory()=");
Serial.println(freeMemory());

pinMode(Call, INPUT);
// time_interval = millis();
// Serial.println("fasdfgh");
// Serial.print("buffer Start =");
// Serial.println(buffer_start);
// Serial.print("buffer finish =");
// Serial.println(buffer_level);
// mySerial.begin(9600);
// delay(10);
int i =0;
byte buf;

while(digitalRead(Call) == LOW)
{ Serial.println("xxxxxxx");
while (buf != ')')
{
if ( mySerial.available() )//&& ( Buffer[i - 1] != ')' )) // if (serial avilable and buffer not full)
{
buf = mySerial.read();
// Buffer[i++] = buf;
Serial.println(buf);
// Serial.println(Buffer[i - 1][buffer_finish]);
}
}
while(1);
process_data();

}
// mySerial.begin(9600);

//while(digitalRead(Call) == LOW)
//{//if (mySerial.available())
//{Serial.println(mySerial.available() , DEC);}//mySerial.read());}
//}

attachInterrupt(0, fill_buffer_flag , FALLING);flag =0;
}

As soon as the code enters fill_buffer() , it gets reset.

If only we could see all the code {sigh}

#include <MemoryFree.h>
#include <SoftwareSerial.h>
#include <EEPROM.h>
#include <Wire.h>
SoftwareSerial mySerial(7 , 6); // RX, TX

byte Buffer[40] ;

byte Relay1_status = 0;
byte Relay2_status = 0;

//unsigned long time_interval;
int Call = 2;
int Relay1 = 8;
int Relay2 = 9;

unsigned char Tx_data[20];
unsigned char Rx_data[20];

byte Daughter_Table[4][2];
const int System_ID = 1;

void setup()
{
pinMode(Call, INPUT);
pinMode(Relay1, OUTPUT);
pinMode(Relay2, OUTPUT);
// Open serial communications and wait for port to open:
Serial.begin(115200);

mySerial.begin(9600);

Wire.begin();
Serial.println(“start”);delay(500);

Serial.println(“DTable”);delay(500);

Serial.print(“System Started”);
Serial.print(“1freeMemory()=”);
Serial.println(freeMemory());

}

int flag = 0;
void loop() // run over and over
{
if (digitalRead(Call) == LOW)
fill_b();

}

void fill_b()
{

Serial.print(“3freeMemory()=”);
Serial.println(freeMemory());

int i =0;
byte buf;

while(digitalRead(Call) == LOW)
{ Serial.println(“xxxxxxx”);
while (buf != ‘)’)
{
if ( mySerial.available() )//&& ( Buffer[i - 1] != ‘)’ )) // if (serial avilable and buffer not full)
{
buf = mySerial.read();
// Buffer[i++] = buf;
Serial.println(buf);
// Serial.println(Buffer[i - 1][buffer_finish]);
}
}
while(1);
// process_data();

}

}

if ( mySerial.available() )//&& ( Buffer[i - 1] != ')' )) // if (serial avilable and buffer not full)

Despite the comment, nothing here would check that the buffer isn't full.

If you happen to receive more than 40 characters then you'll overwrite your array and any number of things, including a reset, are bound to happen.

What's the purpose of the infinite loop at the end of this function? You're going to receive this data and then lock the program up without doing anything with it?

Delta_G:

if ( mySerial.available() )//&& ( Buffer[i - 1] != ')' )) // if (serial avilable and buffer not full)

Despite the comment, nothing here would check that the buffer isn't full.

If you happen to receive more than 40 characters then you'll overwrite your array and any number of things, including a reset, are bound to happen.

What's the purpose of the infinite loop at the end of this function? You're going to receive this data and then lock the program up without doing anything with it?

"nothing here would check that the buffer isn't full." - Except for the fact that all the code that references Buffer is commented out....

Regards,
Ray L.

#include <SoftwareSerial.h>

SoftwareSerial mySerial(7 , 6); // RX, TX

int Call = 2;

void setup()
{
pinMode(Call, INPUT);

Serial.begin(115200);

mySerial.begin(9600);

Serial.println(“start”);//delay(500);

}
byte buf;
//int flag = 0;
void loop() // run over and over
{

if ( mySerial.available() )//&& ( Buffer[i - 1] != ‘)’ )) // if (serial avilable and buffer not full)
{
buf = mySerial.read();
// Buffer[i++] = buf;
Serial.println(buf);
// Serial.println(Buffer[i - 1][buffer_finish]);
}
}

Even in this it keeps getting restarted and prints start on serial.

Perhaps the cause is a hardware issue? You've said nothing about what the SoftwareSerial
pins are talking to.