LPC11C24 I2C troubles

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

LPC11C24 I2C troubles

1,867 Views
f_fiorini
Contributor III

Hello to all,
I am using LPC11C24 for a project that requires me to implement I2C communication between the board (LPCXpresso LPC11C24 Rev B) and some sensors using I2C protocol.

I looked at the example code provided on LPCOpen but it doesn't really seem clear to me.

In particular, I want to read 8bit data from a particular register of the sensor.

In my setup, the sensor I2c address is 0x1D while the register I'm looking for is at 0x0D.

Which one should I put in the Chip_I2C_MasterRead function?
Furthermore, which function do you suggest me to use? Read, CmdRead or Transceive? 

Thanks in advance!
Kind regards,


Federico

Labels (5)
9 Replies

1,409 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Federico Fiorini,

    You can refer to this code's I2C project:

1. lpcxpresso project

   https://community.nxp.com/servlet/JiveServlet/download/920261-1-406142/LPC11xx-LPCXpresso-CMSIS-upda... 

2. KEIL project

 https://community.nxp.com/servlet/JiveServlet/download/920261-1-406141/lpc11xx.keil-examples-CMSIS-u... 

  There has a i2c project which communicate with the external PCF8594, you can refer to that working flow.

   Besides, you need to check your own i2c slave, and check what the i2c command and address it need, then modify the project, and check the I2C bus wave, make sure the I2C data meet your slave's demand. This I2C project have the I2C write and read function!

Please check it at first.


Have a great day,
Kerry

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

0 Kudos

1,409 Views
f_fiorini
Contributor III

Another small thing:

I noticed that when I don't use external pull-up resistors, the SCL and SDA lines are low (meaning there's something wrong), so this is corrected by using two resistors (3.3kΩ each). 
After placing the resistors, though, even if I set the START condition (LPC_I2C->CONSET = I2C_I2CONSET_STA) I can't see the lines going low... why is this happening? 

I'm sorry to bother you but I'm kind of a newbie with microcontrollers and this communication protocol.

Thank you in advance!

0 Kudos

1,409 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Federico,

   When the I2C pin is open drain pin, you need to add the external pull up.

   When use my code, send the I2C, what the I2C wave on your I2C bus?

   You can give me test wave, then I will help you to analysis it.


Have a great day,
Kerry

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

0 Kudos

1,409 Views
f_fiorini
Contributor III

Thank you kerryzhou‌ for the patience :smileyhappy:
I managed to solve some problems, but I noticed that every time I try to read from the sensor I get I2C_STATUS_NAK as a return value. 
Do you think that this is a software or hardware problem? I got the same result when trying the LPC4088 I2C communication using a temperature sensor (LM75) on Embedded Artists' Development Kit.

I'm asking this because I doubt it is a software problem, because I tried to follow example codes and I'm using the LPCOpen library code, so it should perfectly work.

Thank you in advance for the reply.
Kind regards

0 Kudos

1,409 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Federico Fiorini,

    Thank you for your updated information.

    You said: "I'm asking this because I doubt it is a software problem, because I tried to follow example codes and I'm using the LPCOpen library code, so it should perfectly work."

    LPCopen code works OK, then your another software can't work, is it right?

   So, very good.

    Do you have the Logic Analyzer Tool on your side, please test the I2C bus wave on both the lpcopen code and your own software, compare the I2C bus wave, then check your code, which point have the difference. This will help you find the root problem quickly.


Have a great day,
Kerry

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

0 Kudos

1,409 Views
f_fiorini
Contributor III

Hi kerryzhou‌, 
I think I found the problem: apparently the code works with 7-bits addresses and not already formed 8-bit ones... because now the communication works :smileyhappy:

0 Kudos

1,409 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Federico,

   Good information!

   Yes, the LPC I2C address is 7 bits, so normally in the code, you need to lef shift one bit:

pastedImage_1.png

  But, if you check the official lpcopen code, it will be very clear.


Have a great day,
Kerry

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

1,409 Views
f_fiorini
Contributor III

Thank you for the help! 
In the end it was this stupid misunderstanding I had that didn't let my code work :smileyhappy:

0 Kudos

1,409 Views
f_fiorini
Contributor III

Thanks kerryzhou‌! 
I've looked through the example code and it seems pretty clear!

I have a more general question regarding I2C tho.. is there some example code or some demo application that uses the i2c_11xx primitives? 
Like Chip_I2C_MasterTransfer, because I don't get why they are not working properly in my case.

Thank you in advance!

0 Kudos