Understanding InternalI2C

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

Understanding InternalI2C

Jump to solution
1,103 Views
Smiffytech
Contributor III

I am, for the first time, setting up I2C communications to a couple of devices - an MPL115A2 barometer and a Sensiron SHT21 humidity/temperature sensor. Other devices will follow as soon as I have got my head around how this bean works.

Looking through AN3785 for the barometer and example code for the Sensiron part, I am unable to fully reconcile I2C operations with the methods of the InternalI2C bean. Specifically, I can't see how or when a start is sent. I've found that I can send stops manually using SendStop - once I finally located the "Automatic stop condition" in the Advanced view of the Component Inspector. But how do I send a start at the appropriate point? Here's an example from the Sensiron documentation, which I just happen to have open:

I2c_StartCondition();

error |= I2c_WriteByte (I2C_ADR_W);

error |= I2c_WriteByte (USER_REG_R);

I2c_StartCondition();

error |= I2c_WriteByte (I2C_ADR_R);

*pRegisterValue = I2c_ReadByte(ACK);

checksum=I2c_ReadByte(NO_ACK);

error |= SHT2x_CheckCrc (pRegisterValue,1,checksum);

I2c_StopCondition();

Easy to see how the functions above map to InternalI2C methods, other than the start condition - of which I can't find a mention in the online documentation. The starts are specified at very specific points but - and I need to know how to make this happen.

Also can't figure out the [Restart] in the AN3785, but am assuming this just means send a start again.

0 Kudos
1 Solution
580 Views
vfilip
NXP Employee
NXP Employee

Hello,

please find below the detailed steps to resolve your issue:

1

I2c_StartCondition();

error |= I2c_WriteByte (I2C_ADR_W);

The start (repeat start) condition and slave device address are set automatically within SendBlock (SendChar) method(s).

2

error |= I2c_WriteByte (USER_REG_R);

The register content is filled via the passed parameter of SendBlock (SendChar) method(s).

3

I2c_StartCondition();

error |= I2c_WriteByte (I2C_ADR_R);

*pRegisterValue = I2c_ReadByte(ACK);

checksum=I2c_ReadByte(NO_ACK);

Use RecvBlock method with Siz parameter set to value 2 to do this job.

4

I2c_StopCondition();

Use corresponding method from I2C component.

Note:

Do not forget to fill the correct value of I2C_ADR_W in the "Target slave address init" property in I2C component.

best regards

Vojtech Filip

Processor Expert Support Team


View solution in original post

0 Kudos
3 Replies
581 Views
vfilip
NXP Employee
NXP Employee

Hello,

please find below the detailed steps to resolve your issue:

1

I2c_StartCondition();

error |= I2c_WriteByte (I2C_ADR_W);

The start (repeat start) condition and slave device address are set automatically within SendBlock (SendChar) method(s).

2

error |= I2c_WriteByte (USER_REG_R);

The register content is filled via the passed parameter of SendBlock (SendChar) method(s).

3

I2c_StartCondition();

error |= I2c_WriteByte (I2C_ADR_R);

*pRegisterValue = I2c_ReadByte(ACK);

checksum=I2c_ReadByte(NO_ACK);

Use RecvBlock method with Siz parameter set to value 2 to do this job.

4

I2c_StopCondition();

Use corresponding method from I2C component.

Note:

Do not forget to fill the correct value of I2C_ADR_W in the "Target slave address init" property in I2C component.

best regards

Vojtech Filip

Processor Expert Support Team


0 Kudos
580 Views
Smiffytech
Contributor III

I have been doing a little research and think I fully understand the situation and my concerns are now addressed.

I was under the impression that starts needed to be seen at specific times, but it appears that multiple starts are permissible, and should be understood by slave devices.

My concern had been that, if every SendBlock/SendChar was sending a start condition first, this might cause problems with the slave, if it was not expecting these extra starts. Now I think this would only be the case if the slave were implementing the protocol incorrectly :smileyhappy:

0 Kudos
580 Views
Smiffytech
Contributor III

Thanks for the explanation. Now that I've got a mapping between the documentation and the PEx methods, it should all make sense when I code this up.

0 Kudos