Shop OBEX P1 Docs P2 Docs Learn Events
Code overwrites program? — Parallax Forums

Code overwrites program?

lardomlardom Posts: 1,659
edited 2011-12-07 09:05 in Propeller 1
I adapted a method from "Test Propeller Eeprom v0.677". In the last line of the method I replaced the variables with numbers to see if I could follow the formula. The method retrieves values from the transmit window of HyperTerminal.

[HTML]PUB Write | i, temp '' Write individual values to EEPROM
''
'' Prompts user for EEPROM starting address, number of values to be entered and variable
'' size. Then, prompts user for values to store. Each value gets stored in EEPROM
'' locations building from the start address entered by teh user to smaller addresses.

menu.EeParams(@eeAddr, @count, @size)
repeat i from eeAddr - size + 1 to eeAddr - (count * size) + 1 step size
temp := menu.getElement(i)
eeprom.FromRam(@temp.byte[0], @temp.byte[size-1], i)[/HTML]

I wanted to get values from my top object instead of the transmit window of HyperTerminal. My version is below:

[HTML]PUB Wryte(addr, cownt, syze) | i, temp

repeat i from addr - syze + 1 to addr - (cownt * syze) + 1 step syze
temp := Y
Menu.DisplayElement(Y,start) ' I wanted to see if the values were passed
Menu.DisplayElement(Y,count)
Menu.DisplayElement(Y,size)
' eeprom.FromRam(@temp.byte[0], @temp.byte[syze-1], i) ' EXECUTES ONLY ONCE. RESET LEAVES SCREEN BLANK!
Menu.DisplayElement(Y, index + 6) ' This line is here to see if the previous line executed[/HTML]

The object will only display values after a reset if I comment "eeprom.FromRam". The calls to "Menu" are there only to display values. Please help.

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2011-12-02 08:21
    If the indenting shown in your message is correct, the repeat only applies to the next line and i is undefined when it's used in the eeprom.FromRam call (although it's probably addr - (count * size) + 2). What are the values of start, count, size, addr, cownt, and syze?
  • lardomlardom Posts: 1,659
    edited 2011-12-02 09:09
    The indentation in the post was incorrect but I changed it in the Prop tool also and cleared up another bug. It still will not execute without F11. I simplified my adapted method:

    [HTML]PUB Wryte(addr, cownt, syze) | i, temp

    repeat i from addr - syze + 1 to addr - (cownt * syze) + 1 step syze
    temp := Y
    eeprom.FromRam(@temp.byte[0], @temp.byte[syze-1], i) ' Will not execute 2nd time![/HTML]

    size/syze = 1
    count/cownt = 1
    addr = Y[4], (I think)
    value = 7
    I'm trying to write "7" to the 4th element of a 5 element byte array then write that to the eeprom. I changed the spellings in the parameter list only so it would compile. "i" and "byte[0]" are puzzling. I could try writing to high memory but that would add to my list of 'unknowns'.
  • lardomlardom Posts: 1,659
    edited 2011-12-02 09:18
    Correction: When "Wryte" is called Y[4] = 7. "Wryte" has to copy that to eeprom.
  • Mike GreenMike Green Posts: 23,101
    edited 2011-12-02 10:22
    I can't see anything obvious from the small program fragment you've provided. I'm guessing about what the calls to eeprom. do. Without a more complete program listing including some way for me to look at the eeprom. object, I can't give you any more advice.
  • lardomlardom Posts: 1,659
    edited 2011-12-02 10:45
    I zipped it but I left it with all my commented tweaks which I leave to remind me of what I have tried. I did try changing byte[0] to byte[1] which allowed me to print values with a reset but I still can't decipher the command.
  • kuronekokuroneko Posts: 3,623
    edited 2011-12-02 19:56
    In your main method you fill your array with 7 (index check should be => as index runs from 0..4 and your scan loop needs another exit condition in case the array is full). Then you call your wryte method with the following values: 7 (Y is the same as Y[0]), 3 (4th element) and 1. Which translates into a repeat loop range of 7-1+1 to 7-3+1, i.e. 7 to 5 which is an area you really don't want to write to. This looks all a bit messed up :)

    I'm only guessing here, presumably you want to write out the array Y. For a start you should pass the array address @Y{0} and - optionally - fill level (highest index) and element size. Which would then translate to a single call (untested):
    length := (highest_index+1[COLOR="silver"]{0-based}[/COLOR])*size -1        ' highest_index+1 == count
      eeprom.FromRam(@Y, @Y+length, @Y)
    
    Can you confirm and/or clarify?
  • lardomlardom Posts: 1,659
    edited 2011-12-03 08:38
    Changing "Y" to "@Y[index]" has solved the problem with having to constantly press F11. :smile: This is encouraging.
    I'm going to try to implement the line of code quoted below and I'll report back.
    length := (highest_index+1{0-based})*size -1
  • lardomlardom Posts: 1,659
    edited 2011-12-07 09:05
    kuroneko, you are a great teacher. My object now works and it will be adapted to perform load leveling in my application.
    Quite a few concepts have become clear by studying your explanations and your code. Thanks much!
Sign In or Register to comment.