MinimalI2C question
In looking the the MinimalI2C object (which I have used before to write to PCF8575 expander), I now want to read from both a PCF 8575(16bit) and PCF 8574(8bit). Reading from these is a new process to learn.
Using the object before was simple:
i2c.I2CStart(clk pin)
i2c.I2CWrite (clk pin, %0100_000_0) 'send device address, 3 user pin address, and write mode
i2c.I2CWrite (clk pin, %0000_0000) 'write data byte 1
i2c.I2CWrite (clk pin, %0000_0000) 'write data byte 1
i2c.I2CStop
Two options for reading, I2CRead versus I2CPageRead, I am puzzled about which way to go. There are 3-8574's and 2-8575's on the same bus.
I2CRead simply says I2CRead(Clk, ack). I see no way to set the device address. What is ack in the parameters for here?
Using I2CPageWrite says I2CPageWrite(Clk, device address, register to read, dataPointer, count)
I see no way to make either of these work, as there is no register to set on 8575 or 8574, you just address it, and write or read, in this case 1 or 2 bytes depending on the device it is reading.
OK I am assuming that maybe something similar can take place as the write:
i2c.I2CStart(clk pin)
i2c.I2CWrite (clk pin, %0100_000_0) 'send device address, 3 user pin address, and write mode
i2c.I2CRead (clk pin, ack) 'read data byte 1 what to do with ack?
i2c.I2CRead (clk pin, ack) 'read data byte 1 what to do with ack?
i2c.I2CStop(clk)
I am guessing It would be best to read to a variable like this to make use of the return data:
i2c.I2CStart(clk pin)
i2c.I2CWrite (clk pin, %0100_000_0) 'send device address, 3 user pin address, and write mode
ReadByte1 := i2c.I2CRead (clk pin, ack) 'read data byte 1 what to do with ack?
ReadByte2 := i2c.I2CRead (clk pin, ack) 'read data byte 2 what to do with ack?
i2c.I2CStop(clk)
Any suggestions on what way to go to read these two devices?
Using the object before was simple:
i2c.I2CStart(clk pin)
i2c.I2CWrite (clk pin, %0100_000_0) 'send device address, 3 user pin address, and write mode
i2c.I2CWrite (clk pin, %0000_0000) 'write data byte 1
i2c.I2CWrite (clk pin, %0000_0000) 'write data byte 1
i2c.I2CStop
Two options for reading, I2CRead versus I2CPageRead, I am puzzled about which way to go. There are 3-8574's and 2-8575's on the same bus.
I2CRead simply says I2CRead(Clk, ack). I see no way to set the device address. What is ack in the parameters for here?
Using I2CPageWrite says I2CPageWrite(Clk, device address, register to read, dataPointer, count)
I see no way to make either of these work, as there is no register to set on 8575 or 8574, you just address it, and write or read, in this case 1 or 2 bytes depending on the device it is reading.
OK I am assuming that maybe something similar can take place as the write:
i2c.I2CStart(clk pin)
i2c.I2CWrite (clk pin, %0100_000_0) 'send device address, 3 user pin address, and write mode
i2c.I2CRead (clk pin, ack) 'read data byte 1 what to do with ack?
i2c.I2CRead (clk pin, ack) 'read data byte 1 what to do with ack?
i2c.I2CStop(clk)
I am guessing It would be best to read to a variable like this to make use of the return data:
i2c.I2CStart(clk pin)
i2c.I2CWrite (clk pin, %0100_000_0) 'send device address, 3 user pin address, and write mode
ReadByte1 := i2c.I2CRead (clk pin, ack) 'read data byte 1 what to do with ack?
ReadByte2 := i2c.I2CRead (clk pin, ack) 'read data byte 2 what to do with ack?
i2c.I2CStop(clk)
Any suggestions on what way to go to read these two devices?
Comments
For writing, you do a Start, then Write the device address and write mode, then Write one or two data bytes, then a Stop.
The acks tell you whether the byte transfer worked. They should normally be zero.
For reading, you do a Start, then Write the device address and read mode, then Read one or two data bytes, then a Stop.
The last ack has to have a value of 1 to indicate that this is the last byte to be read.
Thanks for explaining that.