Hello!
I write this topic, because after of searching a lot, i couldn't find anything.
Okay... I have got a long code, with many functions in there. So I put a code there to control where my Arduino Mega 2560 loses memory, and the result is: When I call a VOID function, and Arduino enter in the function loses around 25 bytes, this memory I never recover, so, the Arduino is always losing RAM.
I use around a 40% of the RAM.
This is the caller:
void loop(){
lcd.clear();
//------------------RAM COMPROBATION---------------------------------------
Serial.print("\n\n SRAM FREE LOOP: "); Serial.println(freeRam());
//------------------RAM COMPROBATION---------------------------------------
[...]
if((pulsacion2 != 0)||(pulsacion != 0)){
lcd.clear();
into = true;
Serial.print("\n\n SRAM FREE LOOP TYPE: "); Serial.println(freeRam());
MenuPrincipal();
}
And the called function is this:
void MenuPrincipal(){
//------------------RAM COMPROBATION---------------------------------------
Serial.print("\n\n SRAM FREE IN MAIN MENU [INITIAL]: "); Serial.println(freeRam());
//------------------RAM COMPROBATION---------------------------------------
lcd.clear();
int level = 1;
int sel = 7;
bool banana = false;
DateTime now = rtc.now();
tiempo1 = 60*now.hour() + now.minute() + 5;
// Se imprime la pantalla de inicio:
lcd.setCursor(0, 0); lcd.print("---MENU PRINCIPAL---");
lcd.setCursor(2, 1); lcd.print("1. Cosas varias");//lcd.write(byte(5));
lcd.setCursor(2, 2); lcd.print("2. Otras cosas ");//lcd.write(byte(5));
lcd.setCursor(2, 3); lcd.print("3. Salir ");lcd.write(byte(4));
//------------------RAM COMPROBATION---------------------------------------
Serial.print("\n\n SRAM FREE IN MAIN MENU [INITIAL 2]: "); Serial.println(freeRam());
//------------------RAM COMPROBATION---------------------------------------
do{
[...]
As I said before, when I call this function I loss memory that I never recover, and there are the results of the Serial:
SRAM FREE INITIALLY: 4919
SRAM FREE LOOP: 4898
SRAM FREE LOOP TYPE: 4898
SRAM SRAM FREE IN MAIN MENU [INITIAL]: 4874
SRAM SRAM FREE IN MAIN MENU [INITIAL 2]: 4874
As you can see, I loses 20 bytes, or 25 bytes when i get into the woid Function, and i don't know how to fix it.
I hope your help!
Thanks for all:)