Closed xpeedster closed 4 years ago
i2c_read/write and i2c_ioctl_read/write accept void *
as input parameter, you can just force convert a numerical value to void *
then to write.(Actually any kind of data can using this way write) Notice the endian and data length.
// Write 2 bytes data to i2c
unsigned short data16 = 123;
i2c_write(&i2c_device, 0x0, &data16, strlen(data16));
// Write 4 bytes big-endian data to i2c
unsigned int data32 = htonl(0x12345678);
i2c_write(&i2c_device, 0x0, &data32 , strlen(data32));
More example please reference: https://github.com/amaork/libi2c/tree/master/example
Hi, I am using libi2c to communicate between a Jetson TX2 and a Teensy 3.6.
The thing is that I'd like to send numbers (I send values to the teensy via i2c and the teensy does its things, then the teensy reads a sensor and sends the data to the Jetson).
However, I've been looking at the source of the code and I can't see a way of sending numerical values in a way that is not a char (each number would take 1 byte = 123 takes 3 bytes).
Is there a way to do so?
Thanks for the help.