NXC: PCF8574 i2c driver questions

Discussion specific to NXT-G, NXC, NBC, RobotC, Lejos, and more.
Post Reply
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

NXC: PCF8574 i2c driver questions

Post by HaWe »

hey,
I have a couple of questions to this PCF8574 driver I found in the web:

Code: Select all

int ReadPort(char PCF8574Port, byte PCF8574ID, char input)
{
    byte cnt = 0x02;
    byte I2CMsg[];
    byte inbuf[];
    byte Address = PCF8574ID;
    byte nByteReady = 0;
    int  result = -1;
    int loop;

    ArrayBuild(I2CMsg, Address);
    Wait(8);
    while (loop == STAT_COMM_PENDING)
    {
          loop = I2CStatus(PCF8574Port, nByteReady);
    }

    if (I2CBytes(PCF8574Port, I2CMsg, cnt, inbuf))
    {
        result = inbuf[1];
    }


    return result;
}
my questions:
- why is cnt =2 ? (I just have to read 1 Byte!)
- why is result to be found in inbuf[1] and not in [0] ?
- what is inbuf[0] for?
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests