Hi All,
I am using CW10.4, MQX4.0.1 and MK60F120.
I open a I2C channel and use ioctl(current_dev, IO_IOCTL_I2C_SET_MASTER_MODE, NULL) set it to master.
But when I debug and monitor the register, the value of register I2C0_C1 is always 0x80.
Any suggestions about this??
Thanks.
-Daniel
Solved! Go to Solution.
Yes. So the address field in register A1 is the upper 7 bits. The last bit is always read as zero. The MQX driver accounts for this. So when you pass param to the driver, it will shift it left by one bit (shifting in a zero). So if you pass in 0x60 (0b0110_0000), the driver will shift it left and store it in A1 as 0xC0 (0b1100_0000). The reason for this is to account for the R/W bit that it will receive from the master.
Best regards,
Chris
Daniel,
I believe this is normal operation. You have set the I2C instance to master mode, but the master mode bit in the register will not set until you send a message out this port. The reason for this is that once the master mode bit is set in the I2C module register, the module immediately puts a start condition on the bus. Please see the I2C C1 register description (chapter 54.3.3) in your device specific reference manual.
Thanks,
Chris
Chris,
Thank you.
One more question is that I use command
param = 0x60;
ioctl (fd, IO_IOCTL_I2C_SET_STATION_ADDRESS, ¶m))
set the station address which will effect the register I2C0_A1. It changes to 0xC0.
Does it make sense to you?
Thank you.
-Daniel
Yes. So the address field in register A1 is the upper 7 bits. The last bit is always read as zero. The MQX driver accounts for this. So when you pass param to the driver, it will shift it left by one bit (shifting in a zero). So if you pass in 0x60 (0b0110_0000), the driver will shift it left and store it in A1 as 0xC0 (0b1100_0000). The reason for this is to account for the R/W bit that it will receive from the master.
Best regards,
Chris