I've got a P1 spin application that reads water flow rates from an ultrasonic flowmeter. As this code goes into a number of different products (the products differ by maximum flow rate), the software can be configured to set the correct maximum flow rate. This is done via a serial interface, and once the value is received, it is written to EEPROM using the Write_CodeMem routine from BS2 Functions ( https://github.com/parallaxinc/propeller/commit/8113778fa5586512d7282070d20d487ad6a8239f
). It all works fine except that in certain situations it does not read the EEPROM value back when it restarts. The following spin code is there at startup to see if there is an EEPROM value stored, and if not, it assigns the default value of 50.
if (max_flow_rate == 0) 'check if EEPROM value exists, if not, assign default 50l unit size)
max_flow_rate := 50
99% of the times it works, ie, if I have set another value then 50 somewhere else in the code it gets written to EEPROM and upon restart the value is read back. Except in a few niggly cases this doesn't work and it defaults back to 50 (which means it reads EEPROM value as 0 in the above if statement, even though it was written to EEPROM before).
And yes, I've checked the variable size and the size of the BS2 command,
BS2.Write_CodeMem(@max_flow_rate, max_flow_rate, 2) 'word size
So my question is: If there is a brown out or loss of power for a short time and the prop restarts, could it be the EEPROM is not read back into RAM but the variable is still somehow cleared? Or something along those lines?
This happens only rarely and I believe it does happen when brown outs occur (but not 100% sure, we got this out in the field).
Thanks a lot for your help