Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

SOLVED: EEPROM Restoring doesn't work

SilvioCro:

I work on my DIY project with Arduinos (Nano board). I have problem(s) with Serial communation between 1st and 2nd Arduino. 1st Arduino sends one character(letter r) to the 2nd, and that's how 2nd Arduino starts restoring bytes from EEPROM(bytes from 0-25). Only problem is that 2nd Arduino doesn't send bytes correctly, or maybe 1st Arduino doesn't store it correctly.

2nd Arduino has default values in EEPROM:


EEPROMWritelong(EEPROM_DISTANCE, 1500);
EEPROMWritelong(EEPROM_DISTANCE_B, 100);
EEPROMWritelong(EEPROM_DISTANCE_C, 1000);
EEPROMWritelong(EEPROM_DISTANCE_D, 400);
EEPROM.write(EEPROM_MAX_SPEED, 43);
EEPROM.write(EEPROM_TOP_SPEED, 38);
EEPROMWritelong(EEPROM_TRIP_TIME, 1800);
EEPROMWritelong(EEPROM_WOKR_HOURS, 3600);

Loop function on second Arduino:


> // RESTORE
if (Serial.available())
{
incoming = Serial.read();
if (incoming == 'r')
{
uint8_t bytes[5] = { 0, 0, 0, 0, 0 };
int32_t value = EEPROMReadlong(EEPROM_DISTANCE);
notSend = 255;
// DISTANCE
bytes[3] = (value & 0xFF);
bytes[2] = ((value >> 8) & 0xFF);
bytes[1] = ((value >> 16) & 0xFF);
bytes[0] = ((value >> 24) & 0xFF);
for(bytes[4] = 3; bytes[4] != 255; bytes[4]--) Serial.write(bytes[bytes[4]]);
// TRIP A
value = EEPROMReadlong(EEPROM_DISTANCE_B);
bytes[3] = (value & 0xFF);
bytes[2] = ((value >> 8) & 0xFF);
bytes[1] = ((value >> 16) & 0xFF);
bytes[0] = ((value >> 24) & 0xFF);
for(bytes[4] = 3; bytes[4] != 255; bytes[4]--) Serial.write(bytes[bytes[4]]);
// TRIP B
value = EEPROMReadlong(EEPROM_DISTANCE_C);
bytes[3] = (value & 0xFF);
bytes[2] = ((value >> 8) & 0xFF);
bytes[1] = ((value >> 16) & 0xFF);
bytes[0] = ((value >> 24) & 0xFF);
for(bytes[4] = 3; bytes[4] != 255; bytes[4]--) Serial.write(bytes[bytes[4]]);
// TRIP C
value = EEPROMReadlong(EEPROM_DISTANCE_D);
bytes[3] = (value & 0xFF);
bytes[2] = ((value >> 8) & 0xFF);
bytes[1] = ((value >> 16) & 0xFF);
bytes[0] = ((value >> 24) & 0xFF);
for(bytes[4] = 3; bytes[4] != 255; bytes[4]--) Serial.write(bytes[bytes[4]]);
// MAX SPEED AND TOP SPEED
Serial.write(EEPROM.read(EEPROM_MAX_SPEED));
Serial.write(EEPROM.read(EEPROM_TOP_SPEED));
// TRIP TIME
value = EEPROMReadlong(EEPROM_TRIP_TIME);
bytes[3] = (value & 0xFF);
bytes[2] = ((value >> 8) & 0xFF);
bytes[1] = ((value >> 16) & 0xFF);
bytes[0] = ((value >> 24) & 0xFF);
for(bytes[4] = 3; bytes[4] != 255; bytes[4]--) Serial.write(bytes[bytes[4]]);
// WORK HOURS
value = EEPROMReadlong(EEPROM_WOKR_HOURS);
bytes[3] = (value & 0xFF);
bytes[2] = ((value >> 8) & 0xFF);
bytes[1] = ((value >> 16) & 0xFF);
bytes[0] = ((value >> 24) & 0xFF);
for(bytes[4] = 3; bytes[4] != 255; bytes[4]--) Serial.write(bytes[bytes[4]]);
notSend = 0;
}
}

Code for restore on frist Arduino:


uint8_t byteCount = 0;
Serial.write('r'); // STARTS RESTORING

do
{
if (Serial.available())
{
if (byteCount >= 0 && byteCount else if (byteCount >= 18 && byteCount else EEPROM.write(byteCount + 16, Serial.read()); // WORK HOURS

byteCount++;
}
}
while (byteCount != 26);

I did print of all bytes during this process, and bytes don't match at all. Left side is seding bytes from 2nd Arduino to the frist, right side is reciving bytes on 1st Arduino from 2nd Arduino.



Posted in S.E.F
via StackOverflow & StackExchange Atomic Web Robots
This Question have been answered
HERE


This post first appeared on Stack Solved, please read the originial post: here

Share the post

SOLVED: EEPROM Restoring doesn't work

×

Subscribe to Stack Solved

Get updates delivered right to your inbox!

Thank you for your subscription

×