Shop OBEX P1 Docs P2 Docs Learn Events
Weird EEPROM Bug — Parallax Forums

Weird EEPROM Bug

kt88seampkt88seamp Posts: 112
edited 2009-11-30 22:00 in Propeller 1
There is a problem with this program. What it does is it writes some values to the eeprom and reads one of the cells. It is a test program for my programmable dimmer project. The program does work but only ONCE! If you want it to work again you have to upload the program again to the propeller, removing the power does not even work. Is this a sign of some kind of write protection?




CON
_xinfreq = 5_000_000
_clkmode = xtal1 + pll16x

OBJ

BS2 : "BS2_Functions"
SER : "FullDuplexSerial"
        
PUB Main
    
SER.Start(15, 14, 0, 9600)
BS2.Start(22, 21)
Program

PUB Program | eepromAddress, functionCodeBuffer, functionDataBuffer, i, dimmerVal

' Initialization Code:
dira[noparse][[/noparse]0..7] := 255
dimmerVal := 640000
setBrightness(dimmerVal)

repeat

  eepromAddress := 32767
  functionCodeBuffer := 0
  functionDataBuffer[noparse][[/noparse]0] := 0
  functionDataBuffer := 0
  functionDataBuffer := 0
  functionDataBuffer := 0

  'Write a * to EEPROM to indicate start of storage bank:
  BS2.Write(eepromAddress, "*", 1) 

  'Recieve function code and write to EEPROM:
  repeat while SER.rx <> "*" 'A star needs to be recieved to keep garbage data from noise out of the buffer.
  functionCodeBuffer := ser.RX 'Recieve function code
  eepromAddress-- 'Next address
  BS2.Write(eepromAddress, functionCodeBuffer, 1) 'Write function code to eeprom.

  'Recieve function data:
  if functionCodeBuffer < 2 'Do not write any data to the EEPROM when functions 0 and 1 are recieved. 
  elseif functionCodeBuffer < 4 'Write 4 bytes to the EEPROM when function codes 2 and 3 are recieved.
  i := 0
  repeat while i < 4 'Read function data from C# program
    repeat while SER.rx <> "*" 'A star needs to be recieved to keep garbage data from noise out of the buffer.
    eepromAddress-- 'Next address 
    functionDataBuffer[i] := SER.rx 'Store each byte in buffer.
    BS2.Write(eepromAddress, functionDataBuffer[i], 1) ' Write function data bytes into eeprom.
    i++
 
  'Write a * to EEPROM to indicate start of storage bank:
  eepromAddress--
  BS2.Write(eepromAddress, "*", 1) 

  outa[noparse][[/noparse]0..7] := BS2.Read(32766, 1) 
[/i][/i]

SOme of the code copies funny due to some of the characters being the same as html functions.

Post Edited (kt88seamp) : 11/28/2009 2:20:47 AM GMT

Comments

  • dMajodMajo Posts: 855
    edited 2009-11-28 08:29
    kt88seamp said...
    There is a problem with this program. What it does is it writes some values to the eeprom and reads one of the cells. It is a test program for my programmable dimmer project. The program does work but only ONCE! If you want it to work again you have to upload the program again to the propeller, removing the power does not even work. Is this a sign of some kind of write protection? NO




    I have never used BS2 but by looking at the code (though I am not a skilled spin-er) it seems you are overwriting the first eeprom address thus corrupting the code/program image. BS2.Write (from the comments) have a top-down addressing mode so 32767 is the first eeprom byte and 0 is the last.

    You have to change the addressing or replace bs2.write with·bs2.write_codemem

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    · Propeller Object Exchange (last Publications / Updates);·· Vaati's custom search

  • kt88seampkt88seamp Posts: 112
    edited 2009-11-30 22:00
    Yes your were right, BS2 reverses the numbers. Thanks [noparse]:)[/noparse]
Sign In or Register to comment.