LoPy4 - I2C - FRAM Memory - MicroPython Library

  • @Elizar Thank you for the pointer I was definitely overthinking this. Altho I am still in a bind
    when I call a writeto_mem() method It returns a number of bytes written like intended and then when call readfrom_mem() it returns me a byte array representing all 0, I played with baud rates and also with toggle my Write Protect Pin H to L with no success.
    I'm a bit puzzled but I am learning a lot about i2c so it's a good thing :)

    >>> i2c.init(I2C.MASTER, baudrate=20000)
    >>> i2c.scan()
    >>> i2c.writeto_mem(81,3,4,addrsize=8)
    >>> i2c.readfrom_mem(81,2,6,addrsize=8)
    >>> i2c.writeto_mem(0x51,0x2,bytearray(1),addrsize=8)
    >>> i2c.readfrom_mem(81,2,6,addrsize=8)

  • There is no need for a "firmware" when it comes to using an FRAM. You just need to understand how an I²C bus operates.

    Reading or writing is a straight forward process:

    1. Create and i2c-Object (see example in the pycom docs)
    2. Write data by
    i2c.writeto_mem(ADDR_FRAM, Offset, bytearray(Data), addrsize=16)
    DataByteArray = i2c.readfrom_mem(ADDR_FRAM, Offset, Size, addrsize=16)

    Page 8 of the datasheet explains which bytes sequence has to be sent: two bytes for the target address, then the data byte(s).

    Then write yourself two functions WriteFRAM(Offset, Byte) and ReadFRAM(Offset) and you are done. The whole thing may finally have just about 20 lines of code.

    Don't spend too much time on searching for an already working program. Writing your own FRAM code is a very instructive task and will also lead to a better understanding of the possible pitfalls. Just as an example: how do you plan to react when a bus transmission fails due to a temporary electrical interference?

Log in to reply

Pycom on Twitter