How to use I2C Component

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

How to use I2C Component

2,221 Views
adegonge
Contributor II

Hello,

I apologize for yet another noobish question. I'm trying to use the I2C component in Kinetis to interface with a sensor, however I'm having a bit of trouble understanding how the blocks work. I tried using the example code from the "help on component" but I think I'm missing quite a bit in order to make the program function.

 

What I want to do is first set the 7bit address, then issue a 16bit command to start measuring data, then I would like to receive that data (3 bytes) and store it in an array, and send the acknowledges after each byte if the component doesn't do that automatically. I don't need to write to the device, other than setting the address and issuing the commands. I'm sure this is actually a simple process but I'm very lost.

 

Side note - I do have the two devices set up properly with a pull-up resistor on the SDA and SCL lines, so that should all be set up properly. I'm just confused on how to use these blocks to get the data I want.

 

Thanks!

 

 

Update - I have been able to confirm transmitting data to the slave and also I am receiving data, however I keep only getting the values 5, 87, and 158 repeatedly. The first 2 bytes are meant to be the data and the third is the CRC, but I'm not seeing any fluctuation on those first 2 bytes no matter what I do.

 

I believe my problem is that the mastersendblock only sends a 7 bit value and automatically puts the 0 at the end to designate write. This probably affects my efforts to send the two command bytes following this command. Same likely goes with masterreceiveblock.

Labels (1)
10 Replies

1,827 Views
vítorpereira
Contributor III

     Hello, I'm facing some problems again. I have had some success communicating through the I2C, but some things appear just not to work well. I'm using the code below to write in a register of an IC I'm using. The problem I'm having with it is that the program just get stuck in the line 3, and I can't understand why. I have checked Events.c to see if the codes concerning the transmission and receiving flags were ok (what actually shouldn't make difference in this line), and they are. It has even worked in other codes I've written. I'm usging KDS v2.0

1    OutData[0] = 0x08U;  

2    OutData[1] = 0x09U;

3   Error = CI2C1_MasterSendBlock(MyI2CPtr, &OutData[0], 2U, LDD_I2C_NO_SEND_STOP);

4    while(!DataTransmittedFlg) {

5    }

6    DataTransmittedFlg = FALSE;

Does anybody know what could be possibly happening? Thanks.

0 Kudos
Reply

1,827 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello ,

I recommend you step into that function to check it stucked which place.

Please put  this question in a new thread, for this thread have past for so long ,

and people all hardly find your question , then it can not help you quickly.

Hope it helps

Alice

0 Kudos
Reply

1,827 Views
vítorpereira
Contributor III

Hi,

I'm a begginer and I'm even more lost. I understood how the I2C interface is supposed to work, but I don't know how to effectively use the I2C_LDD component (from Eric Styger's blog, MCU on Eclipse). For example, the "CI2C1_MasterSendBlock();" method. What exactly do I have to put in its parameter area? The same thing to the "CI2C1_MasterReceiveBlock();" method and the "CI2C1_Init();" method. And more: I have already configured the Slave adress in the componnent's properties tab. Then from now on, do I have to send it again at any time of the communication or the generated code and the component itself are going to do it without it being explicit in the main code?

Thanks!

0 Kudos
Reply

1,827 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello Vitor,

It doesn't matter , i can help you step by step.

- After you configure the I2C_LDD component , if you select the "Auto initialization" option,

after generate code , you do not write slave address on the main function, all of the configure aobut

the I2C_LDD all initialized .If you uncheck this one , you can use the function

MyI2CPtr = I2C2_Init(NULL); to initialize .

- About the  usage of these functions ,there is demo , i strongly recommend you refer to them:

pastedImage_0.png

pastedImage_1.png

Hope it can helps , if still have question ,you can contact me without any hesitate.


Have a great day,
Alice

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

1,827 Views
vítorpereira
Contributor III

Hi Alice,

What you said and the examples you told me about really helped me a lot. I'll ask for your help if Ihave any trouble. Thank you!

1,827 Views
adegonge
Contributor II

Bump

I'm still trying to use the I2C Processor Express block but I'm having no luck, it doesn't seem to ever signal the end of a transmission so it gets hung up, and if I bypass that and add a fixed delay instead I still can't read any data..

For my main code, I am basically copying the example code exactly but I just can't get it to work properly. Is there any advice anyone can give me? I have a good understanding of how I2C works now but I just can't figure out this component block..

0 Kudos
Reply

1,827 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello  Bump,,

Have your problem been resovled ?  if no , could you please tell me you cope which example , i can verify it on my side.

BR

Alice

0 Kudos
Reply

1,827 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello Bump,

Which IDE do you use ? And could you please send your project to me , i will test and debug it on my side .

BR

Alice

0 Kudos
Reply

1,827 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello Andrew,

Please tell me which board or chip you use ?

BR

Alice

0 Kudos
Reply

1,827 Views
adegonge
Contributor II

I'm using a K64F Board

0 Kudos
Reply