Slippery little critters those bugs are....

Just posting a general programming/arduino problem.

My project is too vast to post code so will post a very simple psudo breakdown of the issue concerning the EEPROM

setup(){

initialise whole bunch of stuff, including EEPROM.reads

functionpointer = mainmenu

}

loop(){

while (functionpointer points to function (x) ){
}

functionpointer=mainmenu

}

Onto the problem. EEPROM.read has been giving me grief in that I CAN read and write in the setup period to and from EEPROM no problem. Have verified it by selecting option z from main menu and checking values read from EEPROM are correct.

Issue # 1 - reading and saving a float value using a particular variable name EG. classX.varName constantly crashed the arduino when going setting functionpointer to run mode in main menu.

Solution - Change the variable name... seriously.. WTF?? Program works fine now.

Issue # 2 (well after solving issue # 1) reading and saving from EEPROM in general crashed the arduino. Solution was to simply comment out the read and write code and do without EEPROM. Not very practical as I need to use EEPROM. So I tried tracking down the cause. Was my function pointer going a bit skwiffy, or was it just the floats causing the problem (it wasn't, even a simple byte read/save crashed the board), was it a program flow error? Answer, don't know as it has now started working perfectly well off it's own accord....

I should also point out I am experiencing ISR issues WRT simply incrementing a counter variable causing a runtime crash/lockup and for now am using millis() to time events.

I even used the freeRam() function to check how much ram I have left during program execution, and while a little on the low side, it's still above 1.4 / 1.5K which should still be plenty of room for the stack to play right?

Sooo, has anyone had issues similar to this with the EEPROM and what could be the underlying issue? Im starting to become a little suspect about power from the USB, but that wouldn't explain how it could read and write without corruption only to cause a crash once the main program got underway.

As reqards the ISR causing lockups/crashes, I'm a little stumped on that one. :roll_eyes:

Solution - Change the variable name... seriously.. WTF?

I doubt that.

Issue # 2 (well after solving issue # 1) reading and saving from EEPROM in general crashed the arduino.

Again, I doubt that. Reading 4 bytes into a 3 byte array can do that. Just reading from, or writing to, EEPROM can't.

I should also point out I am experiencing ISR issues WRT simply incrementing a counter variable causing a runtime crash/lockup and for now am using millis() to time events.

Really, it's time to stop whining and post some code.

How to use this forum

Post your code, not some pseudo code.

You can do attachments.

EG. classX.varName constantly crashed the arduino when going setting functionpointer to run mode in main menu.

Really? What is setting function pointer to run mode?

PaulS:
Really, it's time to stop whining and post some code.

Lol, I'm not whining.. just posted a description of some weird symptoms that I haven't got my head round yet.

The function pointer is set in a menu, using keyed input. As follows.

setup(){
// After initialising functions set up variables and peripherals/pins....
StatePointer=MainMenu;
}


loop(){
 while((running=StatePointer())){
    
    }  
    StatePointer=MainMenu;
}

In the MainMenu.h file

bool (*StatePointer)();

bool MainMenu();
bool Run();
bool ChangeUnits();
bool ChangeTimeDate();
bool ChangeLogMode();
bool ChangeTempPressure();
bool ChangeLanguage();


bool MainMenu(){

  option = 2; 
  Display.ClearScreen();
  delay(500);
  Display.SetAddress(0, 40);
  Display.DisplayString("MAIN MENU", User.Language, 0);
  GPX.DrawHLine(1,0,0x03,128); 

  
    // DISPLAY MENU OPTIONS TO LCD


 while(Button.CheckState()!=ENTER){

    // CHANGE OPTION HERE

  }
  
  switch(option){
    case 2:
    StatePointer=Run;

    break;
    
    case 3:
    StatePointer=ChangeUnits;

    break;
    
    case 4:
    StatePointer=ChangeTimeDate;

    break;
    
    case 5:
    StatePointer=ChangeLogMode;

    break;
    
    case 6:
    StatePointer=ChangeTempPressure;
 
    break;
    
    case 7:
    StatePointer=ChangeLanguage;

    break;
    
    default:
    break;
  }
  
  return true;

Once mainmenu returns true, it launches you into whatever function you selected. Every other function returns false so that once you break out of the function, you are back in the main menu.

As for the EEPROM stuff, I used the following to read and save floats.

void SaveFloatToE2PROM(int ee, double value){    
 
  const byte* p = (const byte*)(const void*)&value;
    for (unsigned i = 0; i < sizeof(value); i++){
        EEPROM.write(ee++, *p++);
    }
    
}

double ReadFloatFromE2Prom(int ee){
  
  double value = 0.0;
     byte* p = (byte*)(void*)&value;
    for (unsigned i = 0; i < sizeof(value); i++)
        *p++ = EEPROM.read(ee++);
    return value;
  
}

But what was causing me grief, as I mentioned was simply using EEPROM.read or EEPROM.write. It worked fine and read bytes and floats from eeprom no problem during setup() , until I set the function pointer to RUN at which point the arduino crashed after roughly 2-3 seconds.

What is more baffling is that during my attempts to solve the issue and after uploading tens of sketches with serial.prints here there and everywhere, it stopped crashing....

I even tried a ISR(__vector_default) to see if an interrupt was being called but it seems there weren't any.

Finally as for the ISR issues I have, this is what has been causing a crash / lockup.

ISR(TIMERX_COMPX_vect){

 counter++  <- caused crash (global or class member)
 Serial.print(stuff) <- does not cause crash

}

Finally as for the ISR issues I have, this is what has been causing a crash / lockup.

Since that snippet won't even compile, it's hard to comprehend how it can cause a crash.

You need to take your snippets to http://snippets-r-us.com. I'm sure that they can help you.

setup(){

// After initialising functions set up variables and peripherals/pins....
StatePointer=MainMenu;
}

Gives me:

sketch_sep04a:1: error: ISO C++ forbids declaration of ‘setup’ with no type
sketch_sep04a.ino: In function ‘int setup()’:
sketch_sep04a:1: error: new declaration ‘int setup()’
/home/nick/Development/arduino-1.0.5/hardware/arduino/cores/arduino/Arduino.h:117: error: ambiguates old declaration ‘void setup()'

Did I forget to mention we wanted your code, not pseudocode?


Finally as for the ISR issues I have, this is what has been causing a crash / lockup.
Code:

ISR(TIMERX_COMPX_vect){

counter++  <- caused crash (global or class member)
Serial.print(stuff) <- does not cause crash

}

Read this: Gammon Forum : Electronics : Microprocessors : Interrupts

Don't do serial prints inside an ISR. Not for debugging or any other reason.