Shop OBEX P1 Docs P2 Docs Learn Events
I2c memory — Parallax Forums

I2c memory

Chuck MintonChuck Minton Posts: 45
edited 2010-08-13 18:42 in Propeller 1
I am trying to write and read from the on board 24LC256.
Kwabena W. Agyeman wrote "I2C Electrically Erasable Programmable Read Only Memory Engine" from OBX. It looks so simple to use. I set up a simple project to test writing to the chip.

Depending on the state of a push button pin 11, I am trying to write the stat to the memory.
Then, when I reboot I would like to see via pin27 or pin15 the written previous state.
I use an audio conformation of a (high freq) set of beeps for a "1"state (push button up) and a set of bonks(lower freq) for a "0" state 9push button down), to prove the read state of the pin, while I power down.

When I apostrophe out the write command in PUB WRITEtest {'ROM.writeByte($7000, 0)} the beeping or bonking goes along with the input pin. When I make the command line active the audio generation stops, and moreover, gives erratic tone generation if I wait long enough... so think there is some kind of crashing going on in memory.



I would appreciate help on this a lot. Coding follows:

' TESTING WRITING TO EEPROM MEMORY
CON
_clkmode = xtal1 + pll16x ' Feedback and PLL multiplier
_xinfreq = 5_000_000 ' External oscillator = 5 MHz
BEEPpin =9 ' AUDIO CONFORMATION INJECTION PIN
OBJ
ROM:"I2C_ROMEngine"
VAR
LONG STACK [100] ' STACK
byte EOMhistory ' history read variabel
byte GOODbeep
byte GOODbonk ' Audio conformation variables
byte BEEP
PUB START 'START COGS TURNING

DIRA[BEEPpin]~~
DIRA[27]~~
DIRA[15]~~

COGNEW (WRITEtest(0), @STACK[20])
COGNEW (BEEPMODULE(0),@STACK[40])

EOMhistory:=ROM.readByte($7000) '***I2C READ BYTE TEST****
if EOMhistory==1
outa[27]:=1 'Read history byte from EEPROM; light app LED
elseif EOMhistory==0
outa[15]:=1

PUB WRITEtest(writeVAR) '***I2C WRIE BYTE TEST****

repeat
if INA[11] ==1
GOODbeep:=1
'ROM.writeByte($7000, 0) 'Depending on STATE of pushbutton write a "0" or "1"
' to EEPROM

elseif INA[11]==0
GOODbonk:=1
' ROM.writeByte($7000, 1)


WAITCNT(CLKFREQ+CNT) 'Wait a little bit. Then do it again


PUB BEEPMODULE (BEEPVAR1) ' ***HIGH/LOW AUDIO GENERATION MODULE***
DIRA[BEEPpin]~~ ' Turn on direction rigister for beep pin
Repeat ' Loop for a long time
Repeat while GOODbeep==1 ' Do this loop if the GOODbeep variable has
' been set to a 1
REPEAT 3 ' Do the same thing 3 times
WAITCNT(CLKFREQ/18+CNT) ' Give a short duration between
'beeps (1/18 second)
REPEAT BEEP FROM 1 TO 100 ' Do this loop 99 times
!OUTA[BEEPpin] ' Cycle pin
waitcnt(clkfreq/1000+cnt) ' Wait 1/1000 of a second
OUTA[BEEPpin]:=0 ' Set BEEPpin to off state
GOODbeep:=0 'Reset the GOODbeep flag to zero when done.
'Return to top of loop and wiat for flag to set.


repeat while GOODbonk==1
REPEAT 3 ' Do the same thing 3 times
WAITCNT(CLKFREQ/18+CNT) ' Give a short duration between beeps (1/18 second)
REPEAT BEEP FROM 1 TO 38 ' Do this loop 50 times
!OUTA[BEEPpin] ' Cycle pin
waitcnt(clkfreq/400+cnt) ' Wait 1/400 of a second
OUTA[BEEPpin]:=0 ' Set BEEPpin to off state
GOODbonk:=0

Comments

  • Oldbitcollector (Jeff)Oldbitcollector (Jeff) Posts: 8,091
    edited 2010-08-13 10:51
    Hey Chuck, is there any chance you could re-post that block of code using the [noparse]
    and
    
    [/noparse] at the top and bottom?

    It'll preserve the tabs and spacing, but you might have to re-paste it from your Spin editor.

    OBC
  • Chuck MintonChuck Minton Posts: 45
    edited 2010-08-13 11:11
    I2c memory-- RE-POST : Thanks... didn't know bout the "code" set out!
    I am trying to write and read from the on board 24LC256.
    Kwabena W. Agyeman wrote "I2C Electrically Erasable Programmable Read Only Memory Engine" from OBX. It looks so simple to use. I set up a simple project to test writing to the chip.

    Depending on the state of a push button pin 11, I am trying to write the stat to the memory.
    Then, when I reboot I would like to see via pin27 or pin15 the written previous state.
    I use an audio conformation of a (high freq) set of beeps for a "1"state (push button up) and a set of bonks(lower freq) for a "0" state 9push button down), to prove the read state of the pin, while I power down.

    When I apostrophe out the write command in PUB WRITEtest {'ROM.writeByte($7000, 0)} the beeping or bonking goes along with the input pin. When I make the command line active the audio generation stops, and moreover, gives erratic tone generation if I wait long enough... so think there is some kind of crashing going on in memory.



    I would appreciate help on this a lot. Coding follows:
    CON
      _clkmode   = xtal1 + pll16x           ' Feedback and PLL multiplier
      _xinfreq   = 5_000_000                ' External oscillator = 5 MHz
    
        BEEPpin      =9    '   AUDIO CONFORMATION INJECTION PIN
    OBJ
        ROM:"I2C_ROMEngine"
     
    VAR
        LONG STACK [100]   ' STACK 
        byte EOMhistory    ' history read variabel
        byte GOODbeep      
        byte GOODbonk      ' Audio conformation variables
        byte BEEP
     
    PUB START                       'START COGS TURNING
    
      DIRA[BEEPpin]~~
      DIRA[27]~~
      DIRA[15]~~
                                                    
      COGNEW (WRITEtest(0),   @STACK[20])
      COGNEW (BEEPMODULE(0),@STACK[40])
     
       EOMhistory:=ROM.readByte($7000)     '***I2C READ BYTE TEST**** 
        if EOMhistory==1
          outa[27]:=1                            'Read history byte from EEPROM; light app LED            
        elseif  EOMhistory==0
          outa[15]:=1
    
    PUB  WRITEtest(writeVAR)               '***I2C WRIE BYTE TEST****  
    
     repeat
       if INA[11] ==1
         GOODbeep:=1
         'ROM.writeByte($7000, 0)          'Depending on STATE of pushbutton write a "0" or "1" to EEPROM
         
       elseif INA[11]==0  
          GOODbonk:=1
         ' ROM.writeByte($7000, 1)
    
    
       WAITCNT(CLKFREQ+CNT)                       'Wait a little bit. Then do it again
                                   
                                     
    PUB  BEEPMODULE (BEEPVAR1)   ' ***HIGH/LOW AUDIO GENERATION MODULE***
         DIRA[BEEPpin]~~                          ' Turn on direction rigister for beep pin
    Repeat                                        ' Loop for a long time
         Repeat while GOODbeep==1                 ' Do this loop if the GOODbeep variable has been set to a 1
             REPEAT 3                             ' Do the same thing 3 times
                 WAITCNT(CLKFREQ/18+CNT)          ' Give a short duration between beeps (1/18 second)
                 REPEAT BEEP FROM 1 TO 100        ' Do this loop 99 times
                      !OUTA[BEEPpin]              ' Cycle pin 
                      waitcnt(clkfreq/1000+cnt)   ' Wait 1/1000 of a second  
           OUTA[BEEPpin]:=0                       ' Set BEEPpin to off state
           GOODbeep:=0                            'Reset the GOODbeep flag to zero when done. Return to top of loop and wiat for flag to set.
    
                                                                  
        repeat while GOODbonk==1     
            REPEAT 3                              ' Do the same thing 3 times
                 WAITCNT(CLKFREQ/18+CNT)          ' Give a short duration between beeps (1/18 second)
                 REPEAT BEEP FROM 1 TO 38         ' Do this loop 50 times
                     !OUTA[BEEPpin]               ' Cycle pin 
                     waitcnt(clkfreq/400+cnt)     ' Wait 1/400 of a second  
           OUTA[BEEPpin]:=0                       ' Set BEEPpin to off state
           GOODbonk:=0                             
              
    
    
  • KyeKye Posts: 2,200
    edited 2010-08-13 11:54
    You need to call the:

    ROMEngineStart(dataPinNumber, clockPinNumber, lockNumberToUse)

    function before using the I2C code to make sure everything is ready to go. You'll probably want the arguments...

    ROMEngineStart(29, 28, -1)


    The stack for each of you seperate cogs is too small. Notice how in the driver I put that the:

    writeByte(EEPROMaddress, value) '' 19 Stack Longs

    Requires 19 stack Longs. You only allocated 20 longs to the stack of the processor. Try increasing the stack to 40 for each processor.

    ---

    I hope that helps.

    Also, you may wish to use the http://obex.parallax.com/objects/497/ to generate audio.
  • Chuck MintonChuck Minton Posts: 45
    edited 2010-08-13 12:46
    Thanks Nye!
    So... no more crashing while buttons pressed. I changed the stacl space to 600 for now.
    I did not know exactly how to implement the stack space specifically for that application. I assume it is in the named "stack" space.

    I was also missing a repeat at end of PUB START so LED's didn't stay on ...except for a flash.

    Now, when rebooting the prop I always get pin15 to light (zero read from memory) ...so did I not write to EEPROM?? {I PUSHED INPUT BUTTON...assuming write bit to memory:=1. Then turned off the Prop. Then rebooted.}.

    Any suggestions to further this experiment???
    CON
      _clkmode   = xtal1 + pll16x           ' Feedback and PLL multiplier
      _xinfreq   = 5_000_000                ' External oscillator = 5 MHz
    
        BEEPpin      =9    '   AUDIO CONFORMATION INJECTION PIN
    OBJ
        ROM:"I2C_ROMEngine"
     
    VAR
        LONG STACK [600]   ' STACK 
        byte EOMhistory    ' history read variabel
        byte GOODbeep      
        byte GOODbonk      ' Audio conformation variables
        byte BEEP
     
    PUB START                       'START COGS TURNING
    
      ROM.ROMEngineStart(29, 28, -1) 
    
      DIRA[BEEPpin]~~
      DIRA[27]~~
      DIRA[15]~~
                                                    
      COGNEW (WRITEtest(0),   @STACK[100])
      COGNEW (BEEPMODULE(0),@STACK[400])
     
       EOMhistory:=ROM.readByte($7000)     '***I2C READ BYTE TEST**** 
        if EOMhistory==1
              outa[27]:=1                  'Read history byte from EEPROM; light app LED            
        elseif  EOMhistory==0
              outa[15]:=1
       REPEAT
       
    PUB  WRITEtest(writeVAR)               '***I2C WRIE BYTE TEST****  
    
     repeat
       if INA[11] ==1
         GOODbeep:=1
         ROM.writeByte($7000, 0)          'Depending on STATE of pushbutton write a "0" or "1" to EEPROM
         
       elseif INA[11]==0  
          GOODbonk:=1
          ROM.writeByte($7000, 1)
    
    
       WAITCNT(CLKFREQ+CNT)                       'Wait a little bit. Then do it again
                                   
                                     
    PUB  BEEPMODULE (BEEPVAR1)   ' ***HIGH/LOW AUDIO GENERATION MODULE***
         DIRA[BEEPpin]~~                          ' Turn on direction rigister for beep pin
    Repeat                                        ' Loop for a long time
         Repeat while GOODbeep==1                 ' Do this loop if the GOODbeep variable has been set to a 1
             REPEAT 3                             ' Do the same thing 3 times
                 WAITCNT(CLKFREQ/18+CNT)          ' Give a short duration between beeps (1/18 second)
                 REPEAT BEEP FROM 1 TO 100        ' Do this loop 99 times
                      !OUTA[BEEPpin]              ' Cycle pin 
                      waitcnt(clkfreq/1000+cnt)   ' Wait 1/1000 of a second  
           OUTA[BEEPpin]:=0                       ' Set BEEPpin to off state
           GOODbeep:=0                            'Reset the GOODbeep flag to zero when done. Return to top of loop and wiat for flag to set.
    
                                                                  
        repeat while GOODbonk==1     
            REPEAT 3                              ' Do the same thing 3 times
                 WAITCNT(CLKFREQ/18+CNT)          ' Give a short duration between beeps (1/18 second)
                 REPEAT BEEP FROM 1 TO 38         ' Do this loop 50 times
                     !OUTA[BEEPpin]               ' Cycle pin 
                     waitcnt(clkfreq/400+cnt)     ' Wait 1/400 of a second  
           OUTA[BEEPpin]:=0                       ' Set BEEPpin to off state
           GOODbonk:=0                             
              
    
  • KyeKye Posts: 2,200
    edited 2010-08-13 14:11
    Try making a simple audio step demo. As whenever you press and then release the button make the tone higher and higer pitched and store tone's frequency in the eeprom. So the code starts again where it left off.

    As for you're program you doing things in a rather confusing way. I cannot comment to much on why the eeprom state reverts back to zero.

    I would suggest using the object I posted a link to to make the tone output and I would suggest doing all that you are trying to in one cog.
  • Chuck MintonChuck Minton Posts: 45
    edited 2010-08-13 18:02
    OK ! Finally made it go....don't know why....
    Took it off of my Development Board #32111 and built it on my PE board with 2 pullups as Kye suggested.

    Success!

    So question is weather or not the Dev board is wired the same or not.

    At any rate here is the simple code that works.
    Pin 11 is state control button.
    pin 17 is LED that is on when history returns a "0"
    pin 21 is LED that is on when history returns a "1"
    pin 19 is LED that is on when button (pin 11) is pushed.

    When powered down while button not pushed (1) > reboot turns on pin 17.
    When powered down while button is pushed (0) > reboot turns on pin 21.

    Thanks so much Kye!
    now to find out why it did not work on other board!

    here is simplified code that works on the PE with 2 pullup resistors:
                        '        TESTING WRITING TO PROM MEMORY
      
    CON
      _clkmode   = xtal1 + pll16x           ' Feedback and PLL multiplier
      _xinfreq   = 5_000_000                ' External oscillator = 5 MHz
    
    OBJ
        ROM:"I2C_ROMEngine"
     
    VAR
        LONG STACK [600]   ' STACK 
        byte EOMhistory    ' history read variabel
     
    PUB START                      
    
      ROM.ROMEngineStart(29, 28, -1)
      DIRA[11]:=0 
      DIRA[21]~~
      DIRA[19]~~
      DIRA[17]~~
      
       
        EOMhistory:=ROM.readByte($7000)     '***I2C READ BYTE TEST**** 
        if EOMhistory==0
              outa[17]:=1                  'Read history byte from EEPROM; light app LED            
        elseif  EOMhistory==1
              outa[21]:=1
     repeat
           if INA[11] ==1
               ROM.writeByte($7000,0)    'Depending on STATE of pushbutton write a "0" or "1" to EEPROM
         
           elseif INA[11]==0  
               ROM.writeByte($7000,1)
               outa[19]:=1
    
               
        WAITCNT(CLKFREQ/3+CNT)                'Wait a little bit. Then read the buttons again.    }
        OUTA[19]:=0                           
                        
    
  • KyeKye Posts: 2,200
    edited 2010-08-13 18:42
    Glad you could get it working.
Sign In or Register to comment.