i2c Word Addressing?

  • Greetings.

    I've followed instructions from @UFD to fix the built-in i2c routines and instead allow bit-banged i2c read and write. Thanks for all the work which went in to that post.


    I'm attempting to read and write to a 24c512 EEPROM. Its device address is 0b101000. Per the datasheet the device is expecting a 16 bit address for reading and writing. Best I can tell, command line tools i2cget and i2cset are only sending 8 bits worth.

    Here's a capture of me reading from device address 0x50, memory location 0x02. The stored data should be 0xAA.



    Is there a way to force these in-built routines to use a word-sized address?I've looked here already without seeing anything obvious:


    Thanks for your time.

  • After a few hours of banging around, here are some breadcrumbs for the next soul who wanders this way:

    1. The built-in routines only support 8 bit addressing. Full stop.

    2. However, there's a smbus2.py library which can handle larger writes. I grabbed it from here and installed it in the python2.7 directory:


    1. Then, these folks wrote simple read-eeprom16.py and write-eeprom16.py files, based on smbus which seem stable enough. The reference is halfway down the page:


    I renamed 'smbus' as 'smbus2' in the two files like this:

    import sys
    import smbus2
    import time
    bus = smbus2.SMBus(1)

    That said, as written it does not currently support page read / page write, merely 16 byte chunks. So it's very slow. I'll see what I can do to speed things up.

  • This is all for tonight... I edited line 33 in write-eeprom.py like this:

    # time.sleep(0.1) # needs some time to finish write, or fails [Errno 5]
    time.sleep(0.004) # datasheet calls for ~ 5 ms wait

    Which gives at 32k write time of ~16 seconds.

    Sorting out the page write function will make a big difference as well.


Log in to reply

Looks like your connection to Onion Community was lost, please wait while we try to reconnect.