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

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

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

Jump to solution
984 Views
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

0 Kudos
1 Solution
659 Views
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

View solution in original post

0 Kudos
3 Replies
659 Views
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 Kudos
659 Views
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 Kudos
660 Views
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 Kudos