Shop OBEX P1 Docs P2 Docs Learn Events
24lc515 — Parallax Forums

24lc515

NewzedNewzed Posts: 2,503
edited 2005-11-05 20:45 in BASIC Stamp
Does anyone have a program for the 24LC515 they would like to share?· I'm running a BS2PE.

Thanks

Sid

Comments

  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-11-05 17:42
    With a BS2pe you can use I2COUT an I2CIN commands.· The trick is the addressing, but if you look on page 7 of the Microchip documentation you'll see how it's setup.· This is not a full program, but here are the elements I would use:

    EE24515···· CON··· %1010

    devNum···· ·VAR··· Nib··············' device to connect: %00 - %11
    slvAddr··· ·VAR··· Byte·············' slave address byte for I2COUT/I2CIN
    wrdAddr···· VAR··· Word·············' address within EE
    blockSel··· VAR··· wrdAddr.BIT15····' block select bit

    Main:
    · slvAddr = (EE24515 << 4)·|(blockSel << 3) | (devNum << 1)
    · I2CIN·SDA, slvAddr, wrdAddr.BYTE1\wrdAddr.BYTE0, [noparse][[/noparse]myValue]

    The construction of the slave address looks trickier than it is; the point is to·set the device type (%1010), the 32k block select bit·for the word address, then the·the device that you want to talk to (%00 -·%11).·

    Insider tip: You don't have to worry about·BIT0 of the slvAddr byte -- I2COUT and I2CIN take care of this bit for you.

    If you happen to use this code in one of your commercial applications, please include credit to Parallax, Inc. (in your listing/documentation) for this bit of code.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-11-05 17:53
    I updated my standard I2C memory test program for the '515 -- it's attached.


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax

    Post Edited (Jon Williams (Parallax)) : 11/5/2005 5:56:57 PM GMT
  • Tracy AllenTracy Allen Posts: 6,658
    edited 2005-11-05 18:05
    Program to do what, Sid?

    This chip works like two times 24LC256 in one box. The 'LC515 uses address lines A0 and A1 in the same way as does the '256. The address line A2 has to be wired high (meaning, you can only hang 4 'LC515 easily on the same I2C buss, for a total of 256k). In the control byte:
    1010BAAR
    1010 identifies this as a memory chip.
    B is a bit that selects either the low or high segment of 256kbytes
    AA is the address of the chip corresponding to the levels on hardware pins A1 and A0.
    R is the read/write bit (managed by the Stamp I2Cin/out command).

    In other words, the bit B is the most significant bit of the 16 bit address. The 15 least significant bits are in the two bytes that follow the control byte.
    XEDCBA98 76543210

    Why they didn't use the bit labeled "X" for the high address bit, I don't know. That would be logical, but that is not the way it is. You have to manipulate the B bit instead. The main consequence of that comes if your program does sequential reads. The address pointer will autoincrement up to the 256k boundary and then roll over to zero, within each 256k segment. Your program has to detect and manage crossing the 256k boundary. For block writes to the chip, the page size is 64 bytes exactly as in the 'LC256.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • NewzedNewzed Posts: 2,503
    edited 2005-11-05 19:55
    Tracy, I studied Jon's code above and your comments and I'm having a bit of trouble understanding everything.

    For instance, Jon's code said

    FOR wrdAddr = $0000 TO $FFFF

    That is 0 to 65535.· The 515 has 512Kb of storage - that is 8000 pages of 64 bytes each.· I have a special requirement where I want to store some data on the last two pages of the 515 - 7999, starting address·511872and 8000, starting address 511936.· On page 7999 I want to store:

    29LAHDGPR

    Do you have time to show me how?

    One other thing - Near the beginning of my program I wrote:

    for idx = 0 to 8
    serin 16, baud, [noparse][[/noparse]pt(idx)]
    next

    That's where the 29LAPDGPR comes from.· So....can I write:

    for idx = 0 to 8
    i2cdata = pt(idx)
    gosub Tx_Byte
    next

    Thanks, Tracy

    Sid

    ·Post edited by Newed




    Post Edited (Newzed) : 11/5/2005 7:58:32 PM GMT
  • Tracy AllenTracy Allen Posts: 6,658
    edited 2005-11-05 20:31
    Hi Sid,
    It is 512 kilobits of storage, not kilobytes! The chip contains 64 kilobytes. (512k/8)

    There are in fact 64 bytes per page as concerns block writes. That is 1024 pages of 64 bytes. Note that the 64 byte page relates ONLY to the block write function. If you are not doing block writes, it is of no consequence in your programming. The highest address in this chip is 65535. Or, to put it another way, the highest address is 32767 in segment B.

    The math in Jon's program starts with a 16 bit address, wrdAddr, and parses it so that it will select a correct 16 bit address within the 24LC515. The reason it needs parsing is what we talked about. The bit15 of the address is handled differently than the other address bits. The math shifts that bit into its proper position in the command byte.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-11-05 20:45
    The documentation for the part makes it pretty clear, Sid, have a look (especially at the transmission diagrams). You'll see that it only uses 16 bits for addressing (as Tracy explained above), and Bit15 of the address is stuck into the slave address byte (BIT3) -- why they do this, I don't know, but I'm sure somebody on the design team had a good reason.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
Sign In or Register to comment.