Hello
I have PhyBoard-WEGA-AM335x and I'm testing its connection to PCF8575 I2C I/O expander.
I can use it in userspace with i2cset and i2cget, but I have no idea how to program it on C.
Could somebody give me example of reading and writing I/O values from PCF8575?
I've tried to send with ioctl, but all the time I receive "write error". My code below:
void pcfWrite(char *byte1, char *byte2){ struct i2c_rdwr_ioctl_data packets; int retVal = -1; struct i2c_msg messages[2]; messages[0].addr = 0x20; messages[0].flags = 0; messages[0].len = sizeof(byte1); messages[0].buf = byte1; messages[1].addr = 0x20; messages[1].flags = 0; messages[1].len = sizeof(byte2); messages[1].buf = byte2; packets.msgs = messages; packets.nmsgs = 2; retVal = ioctl("/dev/i2c-1", I2C_RDWR, &packets); if (retVal < 0) { printf("Error writing\n"); } }
Thanks in advance!
P.S. There are no examples neither on Beaglebone community nor on Raspberry
Best regards,
Pavlo