Hi,
Could you explain the control commands, for example:
IO_IOCTL_I2C_SET_STATION_ADDRESS
IO_IOCTL_I2C_SET_DESTINATION_ADDRESS
IO_IOCTL_I2C_SET_RX_REQUEST
IO_IOCTL_I2C_GET_STATISTICS
IO_IOCTL_FLUSH_OUTPUT
what are they for? what things are going on behind them? what registers do they change, or what data are they sending? which part I2C protocol they are acting? Thanks.
>> Functions fwrite/fread generate START condition and send destination address, only when bus is IDLE (the first time they are used until STOP condition).
How can I know those behind scene? Is this documented somewhere?
>>I2C master mode is default, so calling this IOCTL command does not change anything in the example.
I run the sample code, the I2CR0 register MSTA bit is always a "0", ie, slave mode. no matter I use "ioctl (fd, IO_IOCTL_I2C_SET_MASTER_MODE, NULL)" or change it to "ioctl (fd, IO_IOCTL_I2C_SET_SLAVE_MODE, NULL)" in file i2c.c file, at line 119. Don't know why.
>>fwrite (mem, 1, 0, fd) is dummy send of 0 units of 1 byte size from mem buffer (so the buffer doesn't have to be initialized), this only generates START condition on the bus (as it's first read/write call) and sends the I2C destination address.
I2C des address was set at line 74(file "eeprom_polled.c"): param = I2C_EEPROM_ADDRESS | ((addr >> 8) & 7); Then, "ioctl (fd, IO_IOCTL_I2C_SET_DESTINATION_ADDRESS, ¶m)" is called at line 76, don't know what is going on here though. Anyway, how can the fwrite, at line 88, send the first control byte, which seems to be with "param" out after initial a I2C start?
Thanks for the reply. BTW, Could you explain this command: ioctl (fd, IO_IOCTL_I2C_SET_MASTER_MODE, NULL)? Please note, it won't modify I2CR0 bit MSTA in the demo example, which I've tried.