Shop OBEX P1 Docs P2 Docs Learn Events
PROPBasic I2CREAD — Parallax Forums

PROPBasic I2CREAD

Helen CHelen C Posts: 34
edited 2010-03-23 16:37 in Propeller 1
First I would like to say thanks for developing the PROPBasic. I have been using BS2pe's for some time now and have looked several times at the possibility of migrating to the PROP chip but was put off by the learning curve of going to SPIN. So I was really interested when I saw the PROPBasic post.

I have had some success with it but I am now stuck on the I2CRead command. I am trying to interface to the clock chip (PCF8583). I have tested my layout with the 2pe chip so I know that this is ok. For the 2pe interface I need 4k7 pull up resistors on both the SDA and SCL lines. Are these required for the PROP?

I am trying to get the time to display on the serial terminal every second but it is not incrementing.

I suspect that I am not reading the data in correctly and maybe not converting it to ASCII correctly either.
Any suggestions as to what I am doing wrong would be gratefully appreciated!

I am using the following FUNC for the I2CRead

FUNC I2C_READ
temp var long
I2CREAD I2C_SDA, I2C_SCL,__param1, temp
RETURN __param1
ENDFUNC

I am not sure why the temp variable is required but the code will not compile without it.

I have posted my pbas code below.

Thanks
Helen

Comments

  • BeanBean Posts: 8,129
    edited 2010-03-22 17:03
    Helen,
    The last parameter in the I2CREAD command is the ACK bit sent TO the device (not read from the device). So this value must be set before the I2CREAD command.
    I think it is normally a zero, then a 1 for the LAST byte received. Sometimes you can just use zero for everything.

    Also you need to divide by 16 instead of 10 because the data is in HEX not DECimal.

    Let me know if you still can't get it working after making the changes.

    Bean

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    Use BASIC on the Propeller with the speed of assembly language.

    PropBASIC thread http://forums.parallax.com/showthread.php?p=867134

    March 2010 Nuts and Volts article·http://www.parallax.com/Portals/0/Downloads/docs/cols/nv/prop/col/nvp5.pdf
    ·
  • Helen CHelen C Posts: 34
    edited 2010-03-22 17:36
    Hi Bean,

    Thanks for the reply. I realised that I was using the incorrect read and write addresses for the PCF8583 chip. I have changed these now and at least I getting values that are changing but they seem to be a bit random.

    Cheers
    Helen
  • Helen CHelen C Posts: 34
    edited 2010-03-22 18:33
    Hi Again,

    Does the I2CRead command deal with the ACK bit automatically?

    Looking back at the spec sheet for the RTC I see that I need to do the following:

    I2CWrite SlaveID for write command
    Get Ack
    I2CWrite WordAddress for data
    Get Ack
    I2CWrite SlaveID for read command
    Get Ack
    I2CRead Data byte
    Send Ack

    So how do I send and receive the ACKs?

    Thanks
    Helen
  • Helen CHelen C Posts: 34
    edited 2010-03-23 11:31
    Solved it!

    I re-read all the I2C documentation and realised that you need to do the following:

    I2CStart
    I2CWrite SlaveID for write command
    I2CWrite WordAddress for data
    I2CStop

    I2CStart
    I2CWrite SlaveID for read command
    I2CRead Data byte
    I2CRead Data byte
    I2CStop

    I have posted the working code for anyone else who may be interested.

    Cheers
    Helen
  • BeanBean Posts: 8,129
    edited 2010-03-23 16:37
    Helen,
    Great. I'm glad you got it working. And thanks for posting the working code.

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    Use BASIC on the Propeller with the speed of assembly language.

    PropBASIC thread http://forums.parallax.com/showthread.php?p=867134

    March 2010 Nuts and Volts article·http://www.parallax.com/Portals/0/Downloads/docs/cols/nv/prop/col/nvp5.pdf
    ·
Sign In or Register to comment.