We have upgraded the community system as part of the upgrade a password reset is required for all users before login in.

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.

    0_1520301636644_i2cdetect.png

    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.

    0_1520301531234_i2cdatasheet.png

    0_1520301479029_i2read.png

    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:

    https://docs.onion.io/omega2-docs/i2c-python-module.html

    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:

    https://pypi.python.org/pypi/smbus2/0.2.0

    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:

    https://medium.com/@rxseger/i2c-interfacing-on-the-bus-pirate-and-raspberry-pi-to-serial-eeproms-for-a-hat-c776ea50f8f4

    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.

    0_1520311019301_shortchunk.png


Log in to reply
 

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