Trouble using I2C on FRDM-KL25

cancel
Showing results for 
Search instead for 
Did you mean: 

Trouble using I2C on FRDM-KL25

Jump to solution
844 Views
funkyguy4000
Contributor II

Hello,

 

I have been agonizing over this simple I2C application for quite some time now and I could really use some help.  I have been following this guide for sometime: Tutorial: Accelerating the KL25Z Freedom Board | MCU on Eclipse

 

I am attempting to use I2C to communicate with the magnetometer side of an LSM303DLHC on the 9DOF from Adafruit. 
The board has resistors on the breakout so that isn't my issue.

My SDA and SCL lines are hooked up properly.

The I2C frequency is set just fine according to the workaround for the silicon error listed in the errata.

My device library and my PEimplementation are communicated between the generated code and everything else just fine.

 

One issue I'm getting is that for some reason, the I2C1_S register will have the busy flag set.

 

The general flow of things for reading the data registers on the magnetometer is as follows: "SimpleHeading()" -> "getMagX" -> "LSM303_ReadReg" -> "CI2C1_MasterSendBlock"  which will send the device address and the register address without a stop bit.  I will then call "CI2C1_MasterReceiveBlock" with a stop bit so that I'll be getting data back from the register and then ending the communication.  Btu for some reason the code generated by PE things that the bus is busy all the time.

 

I'm not sure exactly why this is happening but I can't fix it the code.  I have attached my project in an archive file. 
If somebody could look at it, I would greatly appreciate it.  I am literally on the edge of having a complete mental breakdown because of this thing.

Original Attachment has been moved to: I2C_PE.zip

0 Kudos
1 Solution
196 Views
BlackNight
NXP Employee
NXP Employee

In addition, you might check my project for the Pololu Zumo robot where I use the LSM303.

http://mcuoneclipse.com/2013/01/31/the-freedom-zumo-robot/

The project is on GitHub:

https://github.com/ErichStyger/mcuoneclipse/tree/master/Examples/FRDM-KL25Z/Freedom_Zumo

I hope this helps,

Erich

View solution in original post

0 Kudos
3 Replies
196 Views
BlackNight
NXP Employee
NXP Employee

Have you checked your I2C SDA/SCL lines with a logic analyzer? There could be many things going wrong, including wrong wiring of the data/clock lines. At least this would give you insights what is going on with the bus. If the device reports that the bus is busy, then you should be able to see this in the logic analyzer if the device does not answer with an acknoledge.

But without having your hardware, it is very difficult to check and see what is going wrong on your end.

Erich

0 Kudos
197 Views
BlackNight
NXP Employee
NXP Employee

In addition, you might check my project for the Pololu Zumo robot where I use the LSM303.

http://mcuoneclipse.com/2013/01/31/the-freedom-zumo-robot/

The project is on GitHub:

https://github.com/ErichStyger/mcuoneclipse/tree/master/Examples/FRDM-KL25Z/Freedom_Zumo

I hope this helps,

Erich

View solution in original post

0 Kudos
196 Views
funkyguy4000
Contributor II

Thanks! I figured out my issue.  I was sending a pointer where it wasn't asking for it, whoops!
I've always been a fan of your tutorials and always recommend my peers to seek guides from there.  Keep up the good work!

0 Kudos