Dear All, good evening!
I have an issue and apparentley is due to the memory. May program run but after a short time it stop or it creash/restart from the stup() function.
I fund that function to test the memory. I do not remember where I found it but it has been useful.
static void freeRAM (){
extern int __heap_start, *__brkval;
int v;
int free = (int) &v - (__brkval == 0 ? (int) &__heap_start : (int) __brkval);
Serial.print(F("Free RAM : "));
Serial.println(free); // Which is the unit?
}
At the startup() I added freeRAM() and it display 581.
When the GPS position are collected, feeRAM display 193.
Then the sendGPRS() will send to a remote server the coord. At the begining of the sendGPRS, freeRAM display 33.
Then it stop or crash.
I suppose I do not have enough RAM, it the reason why it crashes.
How can I manage my RAM?
Can we free it?
Here is my setup
void setup()
{
//Initialize serial ports for communication with computer
Serial.begin(TERMBAUD);
cell.begin(GPRSBAUD);
pinMode(13, OUTPUT);
pinMode(12, OUTPUT);
pinMode(11, OUTPUT);
pinMode(10, OUTPUT);
#ifdef DEBUG
Serial.println(F(" "));
Serial.println(F("*************************************"));
Serial.println(F("* Communication... *"));
Serial.println(F("*************************************"));
Serial.println(F(" "));
#endif
}
This happen since I change
//while (uart_gps.available()) OLD
while(Serial.available()) // NEW
The GPS coord are collected like this:
void checkGPS(void)
{
// uart_gps.begin(GPSBAUD);
#ifdef DEBUG
Serial.println("");
Serial.println(F("GPS gathering data... (processGps)"));
#endif
// Parse GPS data for 2 second
for (unsigned long start = millis(); millis() - start < 2000;){
//while (uart_gps.available())
while(Serial.available())
{
char c = Serial.read();
//char c = uart_gps.read();
// New valid NMEA data available
if (gps.encode(c))
{
newGpsData = true;
}
}
}
}
Finally, my sendGPRS function
void sendGPRS(){
//cell.println("AT+SBAND=6");
freeRAM();
#ifdef DEBUG
Serial.println(F(""));
Serial.println(F("Attaching GPRS..."));
#endif
cell.println("AT+CGATT=1");
// IT CRASHes HERE!!!!
freeRAM();
waitFor("OK");
freeRAM();
//#ifdef DEBUG
Serial.println(F("Setting up PDP Context..."));
//#endif
cell.println("AT+CGDCONT=1,\"IP\",\""+apn+"\"");
waitFor("OK");
//#ifdef DEBUG
Serial.println(F("Activating PDP Context..."));
//#endif
cell.println("AT+CGACT=1,1");
waitFor("OK");
//#ifdef DEBUG
Serial.println(F("Configuring TCP connection to TCP Server..."));
//#endif
cell.println("AT+SDATACONF=1,\"TCP\",\""+ip+"\",80");
waitFor("OK");
//#ifdef DEBUG
Serial.println(F("Starting TCP Connection..."));
//#endif
cell.println("AT+SDATASTART=1,1");
waitFor("OK");
[... code ...]
}
Any idea to solve my problems???
Many thank to all.
Cheers