NXC: read i2c bytes from a Arduino device
Posted: 16 Jun 2014, 15:10
hey,
I don't get along:
I need to read an array of bytes from an Arduino slave (length 1 byte for the start, later on up to 8 bytes) from a device (devaddr 0x03), no register address.
the device is attached to NXTport S4.
But I don't understand the NXC syntax of all those i2c API commands, nothing matches what I'm looking for.
Now i need a simple command like
all over, the code would look like this:
thanks in advance!
I don't get along:
I need to read an array of bytes from an Arduino slave (length 1 byte for the start, later on up to 8 bytes) from a device (devaddr 0x03), no register address.
the device is attached to NXTport S4.
But I don't understand the NXC syntax of all those i2c API commands, nothing matches what I'm looking for.
Now i need a simple command like
Code: Select all
result=I2CReadAddr(port, devaddr, cnt, reply);
all over, the code would look like this:
Code: Select all
long Readi2cDevice(byte port, byte devaddr, byte cnt, byte &reply){
byte nByteReady = 0;
long result = -1;
while (I2CStatus(port, nByteReady) == STAT_COMM_PENDING){
Yield();
}
result=I2CReadAddr(port, devaddr, cnt, reply); // <<<<<<<<<<<<<<< how to...?
if(result!=NO_ERR){
TextOut(0, LCD_LINE1, "Err:no dev "); NumOut(78,LCD_LINE1, devaddr);
PlayTone(100,500);
Wait(500);
ClearScreen();
return result;
}
}