I'm new to Arduino and I'm having a problem with Arduino ... I have 2 plates. One is an Arduino UNO and another is an Arduino Mega. I run the following program in both, that the only thing it does is clean the EEPROM memory and show how it was. The idea is that the output should always be 0 because the memory is erasing. I put the code and the different outputs.
#include <EEPROM.h>
void EEPROMWriteInt(int address, int value); //2 Bytes, LE DIGO COMO GUARDAR
int EEPROMReadInt(int address);
int32_t numberSens = 0;
int32_t numberDESP = 0;
int32_t numberGI = 0;
int32_t numberGD = 0;
void setup() {
Serial.begin(9600);
for (int nL = 0; nL < EEPROM.length(); nL++) {
EEPROM.write(nL, 0);
}
numberSens = EEPROMReadInt(1);
numberDESP = EEPROMReadInt(3);
numberGI = EEPROMReadInt(5);
numberGD = EEPROMReadInt(7);
Serial.print("numberSens ");
Serial.println(numberSens);
Serial.print("numberDESP ");
Serial.println(numberDESP);
Serial.print("numberGI ");
Serial.println(numberGI);
Serial.print("numberGD ");
Serial.println(numberGD);
}
void loop() {
}
void EEPROMWriteInt(int address, int value) {
byte hiByte = highByte(value);
byte loByte = lowByte(value);
EEPROM.write(address, hiByte);
EEPROM.write(address + 1, loByte);
}
int EEPROMReadInt(int address)
{
byte hiByte = EEPROM.read(address);
byte loByte = EEPROM.read(address + 1);
return word(hiByte, loByte);
}
Then, the output in Arduino UNO is:
numberSens 0
numberDESP 0
numberGI 0
numberGD 0
The output in Arduino MEGA is:
numberSens 4353
numberDESP 1408
numberGI 0
numberGD 256
Does anyone have an idea or a clue because this may be happening? I thank you in advance.