Shop OBEX P1 Docs P2 Docs Learn Events
Writing to 24LC515 EEPROM — Parallax Forums

Writing to 24LC515 EEPROM

ArchiverArchiver Posts: 46,084
edited 2003-07-16 06:09 in General Discussion
I recently purchased 4 Microchip 24LC515 EEPROMs. These are
512Kbits each. I have them wired into a 2Mbit group of 4, using
the A0 and A1 pins to designate chips 0 thru 3. A2 is wired to
Vcc. The write-protect pins are left floating, which should
leave the whole chip write-enabled. The SDA and SCK lines use
4.7kohm pull-up resistors. I've checked the wiring and all seems
OK there. I'm using the I2CIN and I2COUT commands on the
BS2p-24.

The problem I have is that I can only write to addresses $8000 to
$FFFF. In other words, I can only write to the part of the chip
where the block select bit is set to 1. If I set it to 0, I
can't read that data back - I get what appears to be all binary
1s in return. I'm setting B0 in the slave address (bit 3) and
not A15 (highest bit in the address, which is a don't care bit)
to select addresses $8000-FFFF.

I have verified I can write to all 4 chips by writing a pattern,
swapping two chips, then reading it back and seeing the pattern
in the wrong order for those chips. Also, I'm not reading and
writing across block or chip boundaries, and my reads/writes are
limited to 32 bytes at a time so I'm not crossing page
boundaries.

Can anyone give me ideas on what to troubleshoot? I can't
believe all 4 chips are half-bad. Here is the test program I use
(lots of extra variables declared from the program this logging
will eventually be used for).

- Mark

Mark D. Conner
E-mail: n9xtn@a...
Homepage: http://members.cox.net/mconner1
"Arrogance and stupidity, all in the same package.....how
efficient of you!" - Ambassador Londo Mollari, Babylon 5

'{$STAMP BS2p}
CLK con 0 ' clock line
ADC_CS con 1 ' chip select for max186
DATA_IO con 2 ' data line
GPS_RXD con 3 ' data from gps
TNC_TXD con 16 '4
GPS_TXD con 5 ' data to tnc
MAIN_V con 6 ' main V undervolt
SSC con 7 ' data to SSC
IO_0 con 8 ' io line 0
IO_1 con 9 ' io line 1
'TNC_TXD con 10 ' io line 2
IO_3 con 11 ' io line 3
LED1 con 12 ' io line 4
LED2 con 13 ' io line 5
CAM con 14 ' io line 6
TNC_RXD con 15 ' io line 7
RS232_Port con 16 ' RS232 line

'****************************
'* Comm Values *
'****************************

TNCRate con 16624
B4800N con 16884 'baud for TNC/GPS
'B2400N con 396+$4000 'baud for servo and stretch
B1200N con 18447 'baud for FSK output
B4800 con 500 'Jupiter board

'****************************
'* Flight Status *
'****************************

LandingPix var bit
Ascent var bit
Descent var bit

'****************************
'* General Experiment *
'* Result Variable *
'****************************

EXP_Value var word 'result of ADC conversion
T_Byte var byte 'temp var
TLMcount var word
LastAscent var bit
LastDescent var bit
PixNow var bit


'****************************
'* GPS Variables *
'****************************

Hour var byte
Mins var byte
Secs var byte
Nsats var nib
Lat var word
Latfrac var byte
Lon var word
Lonfrac var byte
Alt var word

Altfrac var nib
Cse var word
Spd var byte
Ft10K var nib
Ft var word
GSAFixType var nib
Sign var bit
I var word

VVel var Alt
VVelfrac var Altfrac
VVelft var Cse
LastGgaSec var Spd
FtHigh var Ft.highbyte
FtLow var Ft.lowbyte
MaxFt10K var T_byte
MaxFtHigh var Alt.highbyte
MaxFtLow var Alt.lowbyte
MaxFt var Alt
ERecHigh var Alt.highbyte
ERecLow var Alt.lowbyte
ERec var Alt
CByte var T_Byte


' Store max altitude in scratch RAM vars 1-3
ScrFt10K con 1
ScrFtHigh con 2
ScrFtLow con 3
' Store seconds of last GGA read in #4
ScrLastGgaSec con 4
ScrLastAlt10K con 5
ScrCam con 6
ScrERecHigh con 7
ScrERecLow con 8

RollSize con 40 ' # frames to take


FOR i=126 to 8191 step 128
ERec = i

Hour = 12
Mins = 15
Secs = i // 100
lat = i
lon = i
cse =315
spd = 35
ft10k = 4
ft = 1689

CByte = 160 + (ERec.bit10*8) + (ERec.bit12*4) + (ERec.bit11*2)
'debug dec5 ERec, " ",dec5 (ERec>>3)//256, " ",dec5
(ERec<<5)//256, CR
debug dec4 i, " ", bin8 CByte, " ", bin8 (ERec>>3)//128, " ",
bin8 ((ERec<<5)//256), CR
I2COUT 8, CByte, (ERec>>3)//128\((ERec<<5)//256),[noparse][[/noparse]Hour, Mins,
Secs, Lat.lowbyte,lat.highbyte, Latfrac, Lon.lowbyte,
Lon.highbyte, Lonfrac, Ft10K, Ft.lowbyte, ft.highbyte,
Cse.lowbyte, Cse.highbyte, Spd]
pause 100
next


FOR i= 126 to 8191 step 128
ERec = i

CByte = 161 + (ERec.bit10*8) + (ERec.bit12*4) + (ERec.bit11*2)

debug dec4 i, " ", bin8 CByte, " ", hex2 (ERec>>3)//128, " ",
hex2 ((ERec<<5)//256), " "

I2CIN 8, CByte, (ERec>>3)//128\((ERec<<5)//256),[noparse][[/noparse]Hour, Mins,
Secs, Lat.lowbyte,lat.highbyte, Latfrac, Lon.lowbyte,
Lon.highbyte, Lonfrac, Ft10K, Ft.lowbyte, ft.highbyte,
Cse.lowbyte, Cse.highbyte, Spd]
debug dec2 Hour, dec2 Mins, dec2 Secs, " ",dec4 Lat, ".", dec2
Latfrac,"N", dec5 Lon, ".", sdec2 Lonfrac, "W ", dec2 Ft10K, dec4
Ft,"ft ",dec3 Cse,"/",dec3 Spd,CR
pause 100

next

stop

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2003-07-14 06:55
    Have you tried using constant slave id bytes.
    Since you wired A2 pins to vcc, your
    Slave id bytes are $A8, $AA, $AC and $AE not $B0 as you mention.

    Regards peter


    Oorspronkelijk bericht
    Van: Mark Conner [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=X9TfIunafB7-hMKpEL7yNBzdTGWC2wENEnT936OwjCvM8kGFgCJhX3Lu8ntTjcRLLYxJYiTtsg]n9xtn@c...[/url
    Verzonden: maandag 14 juli 2003 01:00
    Aan: basicstamps@yahoogroups.com
    Onderwerp: [noparse][[/noparse]basicstamps] Writing to 24LC515 EEPROM

    I recently purchased 4 Microchip 24LC515 EEPROMs. These are
    512Kbits each. I have them wired into a 2Mbit group of 4, using
    the A0 and A1 pins to designate chips 0 thru 3. A2 is wired to
    Vcc. The write-protect pins are left floating, which should
    leave the whole chip write-enabled. The SDA and SCK lines use
    4.7kohm pull-up resistors. I've checked the wiring and all seems
    OK there. I'm using the I2CIN and I2COUT commands on the
    BS2p-24.

    The problem I have is that I can only write to addresses $8000 to
    $FFFF. In other words, I can only write to the part of the chip
    where the block select bit is set to 1. If I set it to 0, I
    can't read that data back - I get what appears to be all binary
    1s in return. I'm setting B0 in the slave address (bit 3) and
    not A15 (highest bit in the address, which is a don't care bit)
    to select addresses $8000-FFFF.

    I have verified I can write to all 4 chips by writing a pattern,
    swapping two chips, then reading it back and seeing the pattern
    in the wrong order for those chips. Also, I'm not reading and
    writing across block or chip boundaries, and my reads/writes are
    limited to 32 bytes at a time so I'm not crossing page
    boundaries.

    Can anyone give me ideas on what to troubleshoot? I can't
    believe all 4 chips are half-bad. Here is the test program I use
    (lots of extra variables declared from the program this logging
    will eventually be used for).

    - Mark

    Mark D. Conner
    E-mail: n9xtn@a...
    Homepage: http://members.cox.net/mconner1
    "Arrogance and stupidity, all in the same package.....how
    efficient of you!" - Ambassador Londo Mollari, Babylon 5

    '{$STAMP BS2p}
    CLK con 0 ' clock line
    ADC_CS con 1 ' chip select for max186
    DATA_IO con 2 ' data line
    GPS_RXD con 3 ' data from gps
    TNC_TXD con 16 '4
    GPS_TXD con 5 ' data to tnc
    MAIN_V con 6 ' main V undervolt
    SSC con 7 ' data to SSC
    IO_0 con 8 ' io line 0
    IO_1 con 9 ' io line 1
    'TNC_TXD con 10 ' io line 2
    IO_3 con 11 ' io line 3
    LED1 con 12 ' io line 4
    LED2 con 13 ' io line 5
    CAM con 14 ' io line 6
    TNC_RXD con 15 ' io line 7
    RS232_Port con 16 ' RS232 line

    '****************************
    '* Comm Values *
    '****************************

    TNCRate con 16624
    B4800N con 16884 'baud for TNC/GPS
    'B2400N con 396+$4000 'baud for servo and stretch
    B1200N con 18447 'baud for FSK output
    B4800 con 500 'Jupiter board

    '****************************
    '* Flight Status *
    '****************************

    LandingPix var bit
    Ascent var bit
    Descent var bit

    '****************************
    '* General Experiment *
    '* Result Variable *
    '****************************

    EXP_Value var word 'result of ADC conversion
    T_Byte var byte 'temp var
    TLMcount var word
    LastAscent var bit
    LastDescent var bit
    PixNow var bit


    '****************************
    '* GPS Variables *
    '****************************

    Hour var byte
    Mins var byte
    Secs var byte
    Nsats var nib
    Lat var word
    Latfrac var byte
    Lon var word
    Lonfrac var byte
    Alt var word

    Altfrac var nib
    Cse var word
    Spd var byte
    Ft10K var nib
    Ft var word
    GSAFixType var nib
    Sign var bit
    I var word

    VVel var Alt
    VVelfrac var Altfrac
    VVelft var Cse
    LastGgaSec var Spd
    FtHigh var Ft.highbyte
    FtLow var Ft.lowbyte
    MaxFt10K var T_byte
    MaxFtHigh var Alt.highbyte
    MaxFtLow var Alt.lowbyte
    MaxFt var Alt
    ERecHigh var Alt.highbyte
    ERecLow var Alt.lowbyte
    ERec var Alt
    CByte var T_Byte


    ' Store max altitude in scratch RAM vars 1-3
    ScrFt10K con 1
    ScrFtHigh con 2
    ScrFtLow con 3
    ' Store seconds of last GGA read in #4
    ScrLastGgaSec con 4
    ScrLastAlt10K con 5
    ScrCam con 6
    ScrERecHigh con 7
    ScrERecLow con 8

    RollSize con 40 ' # frames to take


    FOR i=126 to 8191 step 128
    ERec = i

    Hour = 12
    Mins = 15
    Secs = i // 100
    lat = i
    lon = i
    cse =315
    spd = 35
    ft10k = 4
    ft = 1689

    CByte = 160 + (ERec.bit10*8) + (ERec.bit12*4) + (ERec.bit11*2)
    'debug dec5 ERec, " ",dec5 (ERec>>3)//256, " ",dec5
    (ERec<<5)//256, CR
    debug dec4 i, " ", bin8 CByte, " ", bin8 (ERec>>3)//128, " ",
    bin8 ((ERec<<5)//256), CR
    I2COUT 8, CByte, (ERec>>3)//128\((ERec<<5)//256),[noparse][[/noparse]Hour, Mins,
    Secs, Lat.lowbyte,lat.highbyte, Latfrac, Lon.lowbyte,
    Lon.highbyte, Lonfrac, Ft10K, Ft.lowbyte, ft.highbyte,
    Cse.lowbyte, Cse.highbyte, Spd]
    pause 100
    next


    FOR i= 126 to 8191 step 128
    ERec = i

    CByte = 161 + (ERec.bit10*8) + (ERec.bit12*4) + (ERec.bit11*2)

    debug dec4 i, " ", bin8 CByte, " ", hex2 (ERec>>3)//128, " ",
    hex2 ((ERec<<5)//256), " "

    I2CIN 8, CByte, (ERec>>3)//128\((ERec<<5)//256),[noparse][[/noparse]Hour, Mins,
    Secs, Lat.lowbyte,lat.highbyte, Latfrac, Lon.lowbyte,
    Lon.highbyte, Lonfrac, Ft10K, Ft.lowbyte, ft.highbyte,
    Cse.lowbyte, Cse.highbyte, Spd]
    debug dec2 Hour, dec2 Mins, dec2 Secs, " ",dec4 Lat, ".", dec2
    Latfrac,"N", dec5 Lon, ".", sdec2 Lonfrac, "W ", dec2 Ft10K, dec4
    Ft,"ft ",dec3 Cse,"/",dec3 Spd,CR
    pause 100

    next

    stop



    To UNSUBSCRIBE, just send mail to:
    basicstamps-unsubscribe@yahoogroups.com
    from the same email address that you subscribed. Text in the Subject and
    Body of the message will be ignored.


    Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
  • ArchiverArchiver Posts: 46,084
    edited 2003-07-14 14:29
    I have not used constants in the slave ID bytes, but will try it
    out. The debug statements seem to indicate the right bits are
    being set.

    The B0 I referred to is the block select bit, and not a hex value
    for the slave ID. It's bit 3 (of 0-7) in the control byte.

    For this EEPROM, the A2 pin must be wired to Vcc for it to
    function - it's not a chip select pin.


    > Message: 10
    > Date: Mon, 14 Jul 2003 07:55:07 +0200
    > From: "peter verkaik" <peterverkaik@b...>
    > Subject: RE: Writing to 24LC515 EEPROM
    >
    > Have you tried using constant slave id bytes.
    > Since you wired A2 pins to vcc, your
    > Slave id bytes are $A8, $AA, $AC and $AE not $B0 as you
    mention.
    >
    > Regards peter
    >
    >
    >
    Oorspronkelijk bericht
    > Van: Mark Conner [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=PAVYqeuSjx_Vj2ztlINwQIDl_SWOow4Az6Nio6RJE6XZ-8XTN3frDxqEd62j6dK89dwUvbdw]n9xtn@c...[/url
    > Verzonden: maandag 14 juli 2003 01:00
    > Aan: basicstamps@yahoogroups.com
    > Onderwerp: [noparse][[/noparse]basicstamps] Writing to 24LC515 EEPROM
    >
    > I recently purchased 4 Microchip 24LC515 EEPROMs. These are
    > 512Kbits each. I have them wired into a 2Mbit group of 4,
    using
    > the A0 and A1 pins to designate chips 0 thru 3. A2 is wired to
    > Vcc. The write-protect pins are left floating, which should
    > leave the whole chip write-enabled. The SDA and SCK lines use
    > 4.7kohm pull-up resistors. I've checked the wiring and all
    seems
    > OK there. I'm using the I2CIN and I2COUT commands on the
    > BS2p-24.
    >
    > The problem I have is that I can only write to addresses $8000
    to
    > $FFFF. In other words, I can only write to the part of the
    chip
    > where the block select bit is set to 1. If I set it to 0, I
    > can't read that data back - I get what appears to be all binary
    > 1s in return. I'm setting B0 in the slave address (bit 3) and
    > not A15 (highest bit in the address, which is a don't care bit)
    > to select addresses $8000-FFFF.
    >
    > I have verified I can write to all 4 chips by writing a
    pattern,
    > swapping two chips, then reading it back and seeing the pattern
    > in the wrong order for those chips. Also, I'm not reading and
    > writing across block or chip boundaries, and my reads/writes
    are
    > limited to 32 bytes at a time so I'm not crossing page
    > boundaries.
    >
    > Can anyone give me ideas on what to troubleshoot? I can't
    > believe all 4 chips are half-bad. Here is the test program I
    use
    > (lots of extra variables declared from the program this logging
    > will eventually be used for).
    >
    > - Mark
  • ArchiverArchiver Posts: 46,084
    edited 2003-07-14 14:48
    I looked at the datasheet and now I understand.
    Each chip has 64k address range but address line A15 is put
    In bit3 of the id byte. You need 18 bits to address all eeprom
    Locations.
    Try the following test routine (may take a while to fill all eeproms)

    Bank var byte '0-3 for chipselect eeprom
    Address var word 'for 0-FFFF locations inside eeprom
    Cbyte var byte 'to hold slave id
    Result var byte 'to hold read back values

    Eeprom_fill:
    For bank=0 to 3
    For address=0 to $FFFF 'take a lower value such as 31 to speed up testing
    Debug "bank ",dec1 bank," address ",hex4 address,cr
    Cbyte = $A0+(bank<<1)+(address.bit15<<3) 'calculate id
    I2cout 8,cbyte,address.highbyte&0x7F,address.lowbyte,[noparse][[/noparse]address.lowbyte]
    Next
    Next

    Eeprom_read:
    For bank=0 to 3
    For address=0 to $FFFF
    Cbyte = $A0+(bank<<1)+(address.bit15<<3)+1 'calculate id +1 for read
    I2cin 8,Cbyte,address.highbyte&0x7F,address.lowbyte,[noparse][[/noparse]result]
    If result == address.lowbyte then done
    Debug "invalid byte ",hex2 result," at bank ",dec1 bank," address ",hex4
    address,cr
    Done:
    Next
    Next
    Debug "program finished",cr
    End_program
    Goto end_program

    Regards peter



    Oorspronkelijk bericht
    Van: Mark Conner [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=HOZy2ML0799oDEVQWV3BILh-3cCGu2_8Fci3dqoQb2wbO0QeUFGikHTpe1cU_BN8jNRp]n9xtn@c...[/url
    Verzonden: maandag 14 juli 2003 15:30
    Aan: basicstamps@yahoogroups.com
    Onderwerp: [noparse][[/noparse]basicstamps] RE: Writing to 24LC515 EEPROM

    I have not used constants in the slave ID bytes, but will try it
    out. The debug statements seem to indicate the right bits are
    being set.

    The B0 I referred to is the block select bit, and not a hex value
    for the slave ID. It's bit 3 (of 0-7) in the control byte.

    For this EEPROM, the A2 pin must be wired to Vcc for it to
    function - it's not a chip select pin.


    > Message: 10
    > Date: Mon, 14 Jul 2003 07:55:07 +0200
    > From: "peter verkaik" <peterverkaik@b...>
    > Subject: RE: Writing to 24LC515 EEPROM
    >
    > Have you tried using constant slave id bytes.
    > Since you wired A2 pins to vcc, your
    > Slave id bytes are $A8, $AA, $AC and $AE not $B0 as you
    mention.
    >
    > Regards peter
    >
    >
    >
    Oorspronkelijk bericht
    > Van: Mark Conner [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=HOZy2ML0799oDEVQWV3BILh-3cCGu2_8Fci3dqoQb2wbO0QeUFGikHTpe1cU_BN8jNRp]n9xtn@c...[/url
    > Verzonden: maandag 14 juli 2003 01:00
    > Aan: basicstamps@yahoogroups.com
    > Onderwerp: [noparse][[/noparse]basicstamps] Writing to 24LC515 EEPROM
    >
    > I recently purchased 4 Microchip 24LC515 EEPROMs. These are
    > 512Kbits each. I have them wired into a 2Mbit group of 4,
    using
    > the A0 and A1 pins to designate chips 0 thru 3. A2 is wired to
    > Vcc. The write-protect pins are left floating, which should
    > leave the whole chip write-enabled. The SDA and SCK lines use
    > 4.7kohm pull-up resistors. I've checked the wiring and all
    seems
    > OK there. I'm using the I2CIN and I2COUT commands on the
    > BS2p-24.
    >
    > The problem I have is that I can only write to addresses $8000
    to
    > $FFFF. In other words, I can only write to the part of the
    chip
    > where the block select bit is set to 1. If I set it to 0, I
    > can't read that data back - I get what appears to be all binary
    > 1s in return. I'm setting B0 in the slave address (bit 3) and
    > not A15 (highest bit in the address, which is a don't care bit)
    > to select addresses $8000-FFFF.
    >
    > I have verified I can write to all 4 chips by writing a
    pattern,
    > swapping two chips, then reading it back and seeing the pattern
    > in the wrong order for those chips. Also, I'm not reading and
    > writing across block or chip boundaries, and my reads/writes
    are
    > limited to 32 bytes at a time so I'm not crossing page
    > boundaries.
    >
    > Can anyone give me ideas on what to troubleshoot? I can't
    > believe all 4 chips are half-bad. Here is the test program I
    use
    > (lots of extra variables declared from the program this logging
    > will eventually be used for).
    >
    > - Mark



    To UNSUBSCRIBE, just send mail to:
    basicstamps-unsubscribe@yahoogroups.com
    from the same email address that you subscribed. Text in the Subject and
    Body of the message will be ignored.


    Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
  • ArchiverArchiver Posts: 46,084
    edited 2003-07-16 03:06
    I adapted Peter's test program a little. I still get bad
    results if the bank selection bit in the control byte is zero. I
    dropped a note on the Microchip site to see if anyone there could
    help.

    The I2CIN/I2COUT docs say that the only thing the Stamp overrides
    in the control byte is bit 0 for read/write.

    - Mark

    '{$STAMP BS2p}

    bank var bit
    a0 var bit
    a1 var bit
    addr var word

    cbyte var byte
    result var byte


    pause 1000
    for a0 = 0 to 1
    for a1 = 0 to 1
    for bank = 0 to 1
    for addr = 1 to 128 ' max is 7FFB since I add up to 4 with the
    A1/A2 bits
    'debug "bank ", dec1 bank, " a0 ", dec1 a0, " a1 ",dec1 a1," addr
    ", hex4 addr
    cbyte = $A1 + (bank<<3) + (a1<<2) + (a0<<1)
    debug " cbyte ", bin8 cbyte, CR
    i2cout 8,cbyte, (addr.highbyte)\addr.lowbyte,
    [noparse][[/noparse]addr.lowbyte+(a1*2)+a0]
    next
    next
    next
    next

    pause 1000

    for a0 = 0 to 1
    for a1 = 0 to 1
    for bank = 0 to 1
    for addr = 128 to 1 ' go backwards just to make sure we're
    reading the addresses we think we are
    debug "bank ", dec1 bank, " a0 ", dec1 a0, " a1 ",dec1 a1," addr
    ", hex4 addr
    cbyte = $A1 + (bank<<3) + (a1<<2) + (a0<<1)
    debug " cbyte ", bin8 cbyte
    i2cin 8, cbyte, (addr.highbyte)\addr.lowbyte, [noparse][[/noparse]result]
    debug " result ", hex2 result
    if result = addr.lowbyte+(a1*2)+a0 then cont:
    debug " bad "
    cont:
    debug $0D
    next
    next
    next
    next
  • ArchiverArchiver Posts: 46,084
    edited 2003-07-16 06:09
    The code seems ok to me.
    Only I would use $A0 in the cbyte calculation in the first part just above
    the I2COUT statement.
    ($A1 indicates a read operation, better to be safe and clear bit0)
    Can you give test results of what is supposed to be written and what is read
    back? Together
    with the location addresses where your results are bad?

    The datasheet stated that a 5ms write delay is required after writing bytes.
    You could add this delay after the I2COUT command and see what happens.

    Regards peter


    Oorspronkelijk bericht
    Van: Mark Conner [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=9PL_7ppcNM4swI_CphEpxA-taKmM4ZGNnFL8HYiOob6i5YxEKU_fBf_udziUpoD_rjX0_weA1Q]n9xtn@c...[/url
    Verzonden: woensdag 16 juli 2003 04:06
    Aan: basicstamps@yahoogroups.com
    Onderwerp: [noparse][[/noparse]basicstamps] RE: Writing to 24LC515 EEPROM

    I adapted Peter's test program a little. I still get bad
    results if the bank selection bit in the control byte is zero. I
    dropped a note on the Microchip site to see if anyone there could
    help.

    The I2CIN/I2COUT docs say that the only thing the Stamp overrides
    in the control byte is bit 0 for read/write.

    - Mark

    '{$STAMP BS2p}

    bank var bit
    a0 var bit
    a1 var bit
    addr var word

    cbyte var byte
    result var byte


    pause 1000
    for a0 = 0 to 1
    for a1 = 0 to 1
    for bank = 0 to 1
    for addr = 1 to 128 ' max is 7FFB since I add up to 4 with the
    A1/A2 bits
    'debug "bank ", dec1 bank, " a0 ", dec1 a0, " a1 ",dec1 a1," addr
    ", hex4 addr
    cbyte = $A1 + (bank<<3) + (a1<<2) + (a0<<1)
    debug " cbyte ", bin8 cbyte, CR
    i2cout 8,cbyte, (addr.highbyte)\addr.lowbyte,
    [noparse][[/noparse]addr.lowbyte+(a1*2)+a0]
    next
    next
    next
    next

    pause 1000

    for a0 = 0 to 1
    for a1 = 0 to 1
    for bank = 0 to 1
    for addr = 128 to 1 ' go backwards just to make sure we're
    reading the addresses we think we are
    debug "bank ", dec1 bank, " a0 ", dec1 a0, " a1 ",dec1 a1," addr
    ", hex4 addr
    cbyte = $A1 + (bank<<3) + (a1<<2) + (a0<<1)
    debug " cbyte ", bin8 cbyte
    i2cin 8, cbyte, (addr.highbyte)\addr.lowbyte, [noparse][[/noparse]result]
    debug " result ", hex2 result
    if result = addr.lowbyte+(a1*2)+a0 then cont:
    debug " bad "
    cont:
    debug $0D
    next
    next
    next
    next



    To UNSUBSCRIBE, just send mail to:
    basicstamps-unsubscribe@yahoogroups.com
    from the same email address that you subscribed. Text in the Subject and
    Body of the message will be ignored.


    Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
Sign In or Register to comment.