Shop OBEX P1 Docs P2 Docs Learn Events
Help with i2c code — Parallax Forums

Help with i2c code

infoinfo Posts: 31
edited 2014-04-27 13:34 in Propeller 1
I'm unable to read i2c eeprom on propeller proto board using obex i2c driver. Something I'm not doing right, but can't figure it out. Programming is my weak point. I'm little better with soldering iron than keyboard. Can you put me on the right track? I want to use i2c i/o expander and I need to learn make it dance using scl and sda pins.

Attached is the short code.

Comments

  • T ChapT Chap Posts: 4,223
    edited 2014-04-27 04:23
    For the eeprom, try using %1010_000_0 for the address and see what happens. Also try %1010_000. The lowest bit of the address defines the read or write condition. Some drivers provide the low bit automatically and require only a 7 bit address , so you may need to provide the low bit as 0 or not depending on the driver. I didn't look at your driver to check. But, %1010 will not work as an address as this is only a 4 bit value you are providing. The driver will see this value instead with what you have written %0000_1010, which is not the same as the correct address of %1010_000_0. You have the same problem on the other addresses in the device address list, you have removed all of their lowest 4 bits.
  • infoinfo Posts: 31
    edited 2014-04-27 04:49
    The address works in ReadPage "devSel". Thanks. I still don't know how to ReadByte. It doesn't work there, or I'm doing it wrong. I can't figure out where does return put the data and ackbit. The propeller manual is not clear on that.
  • T ChapT Chap Posts: 4,223
    edited 2014-04-27 05:12
    Try something like x := i2c.ReadByte(28,%1010_000_0,$10)

    "Return" doesn't put the value somewhere, the return IS the value. So in the example I gave, X receives and becomes the returned value of the address location you have just read.
  • prof_brainoprof_braino Posts: 4,313
    edited 2014-04-27 09:22
    info wrote: »
    I'm unable to read i2c eeprom on propeller proto board using obex i2c driver. Something I'm not doing right, but can't figure it out. Programming is my weak point. I'm little better with soldering iron than keyboard. Can you put me on the right track? I want to use i2c i/o expander and I need to learn make it dance using scl and sda pins.

    Attached is the short code.

    Don't know if this is of interest, but, there is a way to look at this interactively. You load propforth and run stuff from the command line, and it can clear some stuff up. After you see the circuit works and the how th code iworks, its easier to get the code right in another method (spin, PASM, etc)

    caskaz did a bunch of work, you might start here:

    http://code.google.com/p/propforth/wiki/I2Ccaskaz

    The newest entries down to SERIAL on this page are germaine:

    http://code.google.com/p/propforth/w/list
  • infoinfo Posts: 31
    edited 2014-04-27 13:34
    Thanks for your help. I would never figure it out. As I tried to find more code snippets, I just got more confused. Either the description is incorrect, or I don't understand plain English. The FemtoBasic for example has full support for I2C and SPI SDcard. The description says the SCL (pin number 28) is divided by two and stored in bit 21...19 (3 highest bits of the device's address), but the code shows the number 28 is not divided by two. It is shifted left 18 times.

    Sometimes too much information is worse than simple one-line explanation. Thanks again for the help. Simple, right to the point, and it solved my problem.
Sign In or Register to comment.