Eerpm write going wrong
Igor_Rast
Posts: 357
Can anyone tell me wht this code after a power up the program locks up
I want to save the tempmin to the eeprom so with power out next power on the data is still there
What Am I overlooking ??
I want to save the tempmin to the eeprom so with power out next power on the data is still there
What Am I overlooking ??
PUB getTemperature ow.reset ' send convert temperature command ow.writeByte(SKIP_ROM) ow.writeByte(CONVERT_T) repeat ' wait for conversion waitcnt(cnt+clkfreq/1000*25) if ow.readBits(1) quit ow.reset ' read DS1822 scratchpad ow.writeByte(SKIP_ROM) ow.writeByte(READ_SCRATCHPAD) ' read temperature temp := F.FDiv(F.FFloat(ow.readByte + ow.readByte << 8), 16.0) ' convert to floating point temp1:=f.FRound(f.fmul(temp,10.0)) {integer valvue of temp} if tempmin == 0 rom.readLong($4000) if tempmin == 0 tempmin:=temp1 if temp1 > tempmax tempmax := temp1 if temp1 < tempmin tempmin := temp1 rom.writeLong($4000,temp1)
Comments
-Phil
When you say it crashes on power up, is that AFTER the eeprom has already been programmed.... and the eeprom has had a value stored in $4000... and THEN you reboot?
I frequently see (and use) the locations starting at $8000 for storing data to an EEPROM since $8000 is the start of the upper half of a 64K EEPROM chip.
There's a link in post #3 of my index to a program that will determine if your EEPROM is 32K of 64K (in case you're not sure of its size).
datasheet
http://ww1.microchip.com/downloads/en/DeviceDoc/21203R.pdf
schematic
about the $8000 location , this value I found around in some post , I don't realy understand the ram locations completly . so that is probably the problem
wich value is good to store I don't know
wanting to store 3 long values to be safe after power op.
hope I get the good advise
esentialy what this code needs to do is
1 read the temp value and display it on lcd ( working complete )
2 remember what value was the highs temp value and store it to tempmax ( must be saved to eeprom not to get lost on powerup, max value doing what is needs to remember , only not at power out)
3 remember what value was the lowest temp value and store it to tempmin ( must be saved to eeprom not to get lost on powerup ,min value doing what is needs to remember , only not at power out))
4 set an offset value ( must be saved to eeprom not to get lost on powerup)
hope I make myself clear
but what's wrong with my code, because it still doesn't remember the value at powerup
so the rom.readLong($7FF0)
and the rom.writeLong($7FF0,temp1) folowed by a temp1:=f.FRound(f.fmul(temp,10.0)) to restore the value in temp1 because what you sugested it gets lost
it's getting me crazy
For a test, forget about your full code. Write a test method that writes a value ie 7 to the location, then read the location and show the result that is currently in the eeprom address.
Also, it is a good practice to not have code hard left, only the PUB, VAR, OBJ, designators. DAT is ok to have declarations hard left
Take a look at the PEK sticky at the top of the Propeller forum. There's an EEPROM data logging lab that shows you how to same variables to EEPROM. A very common way to do this is to just use the same EEPROM address as the variables' RAM location.
I think you're making this harder than it needs to be.
Not sure in the case of your i2c object, but in my example it is required to pass the address of the variable with@, not just using the var itself.
I Got it working , thnx