Hi all,
I have 3 very simple lines of code that when compiled uses 7% of SRAM. The funny thing is that those same 3 lines of code exist else where in the program, but don't use up any memory.
Here's the problem spot:
// get RSSI values
int rssiValue = 0; // RSSI value from FONA
int dBmValue = 0; // decibel milliwatts value, calculated from RSSI
getRssi(&rssiValue, &dBmValue); // pass variables by reference - this function will change them
char RssiMsg[140] = " RSSI = "; // store the result here to build upon and print
char strRssiValue[5] = "";
itoa(rssiValue, strRssiValue, 10);
char strDecibValue[7] = "";
itoa(dBmValue, strDecibValue, 10);
// this code hogs memory, not sure why....
strcat(RssiMsg, strRssiValue); strcat(RssiMsg, ": ");
strcat(RssiMsg, strDecibValue); strcat(RssiMsg, " dBm");
Serial.print(F(" signal strength - ")); Serial.println(RssiMsg); Serial.println();
As is, the sketch compiles at 63% of dynamic memory. if I comment out the last three lines of code, it compiles at 56% dynamic memory. The above code is at line 875 of my program.
At around line 505 of the program, I have this bit of code:
// get RSSI values
int rssiValue = 0; // RSSI value from FONA
int dBmValue = 0; // decibel milliwatts value, calculated from RSSI
getRssi(&rssiValue, &dBmValue); // pass variables by reference - this function will change them
char strRssiValue[5] = "";
itoa(rssiValue, strRssiValue, 10);
char strDecibValue[7] = "";
itoa(dBmValue, strDecibValue, 10);
strcat(response, "\nRSSI = "); strcat(response, strRssiValue); strcat(response, ": ");
strcat(response, strDecibValue); strcat(response, " dBm");
Serial.print(F("response - ")); Serial.println(response); Serial.println();
The last 3 lines of this code are preforming the same action as the last 3 lines of the other code, building a character array. These last 3 lines of code don't use any dynamic memory.
Any idea what's going on?
If anyone wants to see the entire code to help me, I'll post it, but it's ~950 lines...
Thanks for any help
Randy