Shop OBEX P1 Docs P2 Docs Learn Events
Can anyone help me with the Basic_I2C_Driver object? — Parallax Forums

Can anyone help me with the Basic_I2C_Driver object?

Sabre00Sabre00 Posts: 30
edited 2008-09-25 11:51 in Propeller 1
Can anyone help me with the Basic_I2C_Driver object?

The problem I am having is that when I use it as an object with in another object I am not sure where the data is being stored when read within the Basic_I2C_Driver.

can anyone help me with this problem? sad.gif

Comments

  • TimmooreTimmoore Posts: 1,031
    edited 2008-09-24 18:48
    basic_i2c_driver doesn't has any variables to store data. What are you trying to do with it?
    If you want some examples of using it to read I2C sensors then look at hmc6343 or lis302dl on obex. If you are talking about reading/writing to eeprom, I know the support for this is in the driver but I haven't used it.
  • Sabre00Sabre00 Posts: 30
    edited 2008-09-24 23:37
    I am trying to write and read to and from the 24LC256 EEPROM chip. I have written ( so I believe) to the chip and I am trying to see if what I have written. I am trying to see where the data being read from the EEPROM is saved so I can see if what is there is the same that I wrote. I have successfully used the 24LC256 before with a microcontroller with built in I2C commands. I had written my own I2C protocols for a basic stamp but I was trying not to reinvent the wheel and see what the obex had to offer.

    I may end up writing my own and posting it on the obex...
  • T ChapT Chap Posts: 4,223
    edited 2008-09-24 23:40
    Maybe posting what you have that isn't working would be best. Writing and reading the EEPROM is fairly simple, would be a waste to start a new object for that purpose.
  • Sabre00Sabre00 Posts: 30
    edited 2008-09-24 23:52
    ok I have brought the basic_I2C_Driver into my application as I2C : "Basic_I2C_Driver.spin"

    I then tried to write to the EEPROM using the following : I2C.WriteByte(16,$A0,$0000,"F") where pin 16 by default pin 17 are the SCL and SDA pins respectively.

    I then have a 50 millisecond delay, being very generous. Then I use the following. I2C.ReadByte(16,$A1,$0000).
    However the object seems to only return if the action was successful, so assigning that statement to a variable was useless and the variable "@data" where the retrieved byte seems to be stored I can't seem to access from that object.

    sorry if that isn't much help. I am not on the same system where I wrote the original code. Any help would be appreciated.
  • Mike GreenMike Green Posts: 23,101
    edited 2008-09-25 00:10
    In the ReadByte routine, "data" is a local result variable allocated on the stack.
    It doesn't exist once ReadByte returns. ReadByte returns a -1 (TRUE) when an error occurs.
    On success, it returns the byte that was read.
    If you want to detect errors, you need to store the result of ReadByte into a WORD or LONG
    variable, test for -1 or TRUE and, if not equal, you can copy the resulting byte to a BYTE variable.
    If you don't want to do it this way, you can call ReadPage instead. ReadByte, ReadWord, and
    ReadLong are just "wrappers" around ReadPage for convenience. Similarly, WriteByte, WriteWord,
    and WriteLong are just "wrappers" around WritePage for convenience.
  • TimmooreTimmoore Posts: 1,031
    edited 2008-09-25 00:13
    try this, note the addres for read doesn't change

    var
    byte·readb

    i2c.writebyte(16,$a0,$0000,"F")
    readb := i2c.readbyte(16,$a0,$0000)
  • Sabre00Sabre00 Posts: 30
    edited 2008-09-25 00:20
    Thanks guys. I will give it a try in the morning and see the results. will keep you guys posted.
  • Sabre00Sabre00 Posts: 30
    edited 2008-09-25 11:51
    Thanks Timmoore. The problem I had was that I was using $A1 in the read command. I can even use it in this form;

    LCD.WRITEBYTE(4,15,I2C.ReadByte(16,$A0,$0000)).

    I am using an LCD to output the data and I created my own object for that. but this line places the readbyte from the EEPROM at line 4 position 15. now that the easy part is over now on to coding the rest.
Sign In or Register to comment.