Using IOCTL set the I2C master, but the I2C0_C1 register value still 0x80

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

Using IOCTL set the I2C master, but the I2C0_C1 register value still 0x80

跳至解决方案
1,013 次查看
danielchai
Senior Contributor I

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

标记 (3)
0 项奖励
1 解答
688 次查看
chris_brown
NXP Employee
NXP Employee

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

在原帖中查看解决方案

0 项奖励
3 回复数
688 次查看
chris_brown
NXP Employee
NXP Employee

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

0 项奖励
688 次查看
danielchai
Senior Contributor I

Chris,

Thank you.

One more question is that I use command

param = 0x60;

ioctl (fd, IO_IOCTL_I2C_SET_STATION_ADDRESS, &param))

set the station address which will effect the register I2C0_A1. It changes to 0xC0.

Does it make sense to you?

Thank you.

-Daniel

0 项奖励
689 次查看
chris_brown
NXP Employee
NXP Employee

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

0 项奖励