I haven't seen any explanation on this.
Say the I2C master hasn't initiated anything. The physical I2C slave is not sending anything out. But in C code of the master, I could read the I2C. The read() returns with how ever many bytes that I call in read(). So what is really happening?
Here is my contention. In the C level, we should not read the bus any time. The underlying hardware/low level driver should only sample the bus when there is a I2C Start Bit and buffer the data internally. And when there is data in the buffer, then the kernel should allow the user code to do the read(). It shouldn’t allow the user code read() to read I2C if there is no data in the buffer.
But I could execute the following code.
I haven’t seen any documentation that talks about this. Any insight?
… //this is a master
fd = open("/dev/i2c-1", O_RDWR ); //let’s say there is no error
ioctl(fd, I2C_SLAVE, 0x2a); //let’s say that there is no error
read(fd, buffer, 10); //this is where I have a question
…
Thanks,
Bobby.
static ssize_t i2cdev_readIf you still have trouble understanding you can also try to get an idea by: lwn.net/Kernel/LDD3. if you are still having problems I should have time tomorrow at the same time. - Alexander Oh