Quantcast
Channel: Embedded Software (Read Only)
Viewing all articles
Browse latest Browse all 25965

Forum Post: AM335x PCF8575 Programming

$
0
0

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


Viewing all articles
Browse latest Browse all 25965

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>