Computing > Embedded Computing

How to connect a custom i2c C library here?

(1/1)

triedgetech:
I have NanoPi with installed Ubuntu 16 LTS, kernel 4.14.
I want to read value from a specific register on slave device.
On default, there's no support for SMBUS commands in C, and I don't have  i2c/smbus.h
The read command that there is, reads all values from 0x00 register up to whatever register you pass on as an argument in "read()".
I have found this C library (though I heard it's not a good C library for i2c). What steps should I do in order to have a simple
#include <customI2C.h> in my script?? I read this guide on how to connect an external library, and it seems like such a hassle, not sure how to start.
Looks like i2c.c is implementation file, how do I create an i2c.h interface file then??? It'll take too long for me to figure out. I just need a tl;dr.

Its function declaration for read assumes the to pass on the third argument like this I guess:

--- Code: ---u8 result_val;
u8 reg = 0x05;
u8 slave_addr = 0x18;
if (err = i2c_read(slave_addr, reg, &result_val)) {
   // handle error
}
// do things with val
--- End code ---

Does it mean, that if this command reads a register 0x05 (System Clock in MAX9867), it might return an 8-bit value in hex like 0x10?

Anyhow, using the read command right now:


--- Code: ---char bufer[15];
read(file, buffer, 15);
for (int i=0;i<=sizeof(buffer);i++) {
     printf("buffer[%d] is %d \n", i, buffer[i]);
     usleep(1000);
     }
--- End code ---

Will print every register's value up to 14 (15 -1, idk why that's so), which in hex is 0x0E. Obviously that won't do, as this is inefficient, a read command should only access the specific register and then return its value.
What's the simplest way to achieve that? I noticed some C libraries utilize the ioctl command, as a declared function before int main? Perhaps there's a ready to use (copy & paste) sample of it?

Navigation

[0] Message Index

There was an error while thanking
Thanking...
Go to full version