strange return

This forum is for all topics related to Simulator for Arduino v0.98. Please include sample code where possible.

Moderator: Adrian

ghost59160
Posts: 2
Joined: Tue May 21, 2013 5:41 am

strange return

Postby ghost59160 » Tue May 21, 2013 6:25 am

hello I have something strange with this code :
the function eeprom_check_cks() return false when i check in the simulator

but the ret var = 1 and the message is : cks ok

anybody have an idea or is it a bug ?

best regards
Laurent


#include <EEPROM.h> // utilisation de EEPROM
const int len_eeprom = 16;
int eeprom_addr = 0;
int eeprom_crc = 0;
byte eeprom_value = 0;
byte eeprom_cks = 0;
int eeprom_get_cks(){
for (int eeprom_address = 0; eeprom_address < len_eeprom-1; eeprom_address++){
eeprom_value = EEPROM.read(eeprom_address);
eeprom_crc = eeprom_crc + eeprom_value;
eeprom_crc = eeprom_crc & 0xFF;
}
return eeprom_crc;
}
boolean eeprom_check_cks(){
eeprom_cks = eeprom_get_cks();
Serial.println(eeprom_cks);
eeprom_value = EEPROM.read(len_eeprom-1);
Serial.println(eeprom_value);
if(eeprom_cks == eeprom_value)
{
return true;
}
else
{
return false;
}
}
void setup() {
// Debugging output
Serial.begin(9600);
boolean ret = 0;
ret = eeprom_check_cks();
Serial.println(ret);

if(ret == true){
Serial.println("cks ok");
}else{
Serial.println("Erreur CKS");
}
}
void loop() {
}

Simulator_admin
Site Admin
Posts: 239
Joined: Thu Feb 02, 2012 6:07 pm

Re: strange return

Postby Simulator_admin » Fri May 24, 2013 11:58 am

Hi Laurent

We just ran this through the Simulator and it seemed OK with the latest version 0.98E. Which version are you using - click Help > About to see the version.

With this sketch, the Simulator read the first 15 EEPROM values, find the crc or checksum and compares to the EEPROM value at address 15. Usually the sketch will return false since the crc value will be 255 by default instead of the 241. Changing the EEPROM value at address 15 to 241 gives the return value as true. We did a major upgrade on the subroutines returns recently so any version older than 0.98D will probably have issues. Select View > EEPROM to view and change the EEPROM values. Thanks

Here is the typical result
241
255
0
Erreur CKS

Here is the result with EEPROM(15)=241
241
241
1
cks ok


Return to “Version 0.98”

Who is online

Users browsing this forum: No registered users and 1 guest