NXC: PCF8574 read 8 values all at once ?
Posted: 29 Apr 2013, 08:05
hey,
I currently read the PCF8574 once for each muxport like this:
So currently I need 8 i2c calls to get all the single PCF muxer values.
Now: is it possible to read all the 8 PCF bytes all at once to get an array[8] back by only 1 i2c call ?
That would probably speed up the performance by factor 8x....?!
I currently read the PCF8574 once for each muxport like this:
Code: Select all
int ReadPCF8574Port(char PCF8574Port, byte PCF8574ID, char input);
int ReadPCF8574Port(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];
}
if( result == (result | (1<<input-1)) )
{
result = 0;
}
else
{
result = 1;
}
if(result==-1){
TextOut(0, LCD_LINE1, "Error: Check the");
TextOut(0, LCD_LINE2, " connection!");
Wait(500);
ClearScreen();
}
return result;
}
Now: is it possible to read all the 8 PCF bytes all at once to get an array[8] back by only 1 i2c call ?
That would probably speed up the performance by factor 8x....?!