FRDM-kl25z problem when hardcoding I2C for MMA8451Q module

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

FRDM-kl25z problem when hardcoding I2C for MMA8451Q module

3,954 Views
humbertoaboud
Contributor I

Hello,

 

I'm trying to use the MMA8451Q accelerometer with I2C communication. I don't want to use process expert. I've studied closely the I2C module for kinetics family from the kl25z manuel and the MMA8451Q from the Data Sheet http://www.newark.com/pdfs/techarticles/freescale/MMA8451Q.pdf

 

I've studied the code generated from process expert, but it uses interruption so it is a little bit different, making the comparison between the programs harder.


My code is attached, it is small, simple and I commented it to help the comprehension. I'm will be really glad to answer any doubts about it. When I run it, my read function only returns 0xff or 0x00 from the I2C0_D, no matter what.

 

Does anyone has harcoded this before or know what can be wrong with it? I would appreciate any help on that.

 

 

Regards,

Original Attachment has been moved to: main.rar

Labels (1)
0 Kudos
10 Replies

1,514 Views
dmitrybriskiy
Contributor I

humbertoaboud Hello, please send me a reference or the project itself. It is important to work without mistakes and failures.​

0 Kudos

1,514 Views
sreenathreddy
Contributor II

please upload the code related to i2c,its needed to my project

0 Kudos

1,514 Views
juanm
Contributor III

I used this example and it works great.

https://community.freescale.com/docs/DOC-98836

0 Kudos

1,514 Views
humbertoaboud
Contributor I

Thanks a lot for the help juanm,

This example you sent me made me figure out that I was using the wrong address of the control register one of the MMA8451, as I wrote in reply to Erich. It was still not working though, then I figured out that my I2C read register function used to change to the receiver mode before waiting for the conclusion of the transmission.

Fixing those two things did the job, and it works perfectly now.

I will post my code here later so if someday someone wants to do it by coding it can be used it as reference, thanks!

0 Kudos

1,514 Views
sreenathreddy
Contributor II

HI CAN U SEND ME THE CODE

0 Kudos

1,514 Views
lilyann
Contributor I

Hi, I would greatly appreciate it if you could post your updated code. I'm having trouble using the I2C communication, and I also don't want to use Processor Expert. Thanks!

0 Kudos

1,514 Views
mjbcswitzerland
Specialist V

Hi Lily

http://www.utasker.com/kinetis/FRDM-KL25Z.html

http://www.utasker.com/docs/uTasker/uTaskerIIC.PDF

All code available. Doesn't need PE. Automatic I2C deal-lock recovery built in. Kinetis, I2C and project can be simulated in VisualStudio.

Regards

Mark

Kinetis: µTasker Kinetis support

KL25: µTasker Kinetis FRDM-KL25Z support / µTasker Kinetis TWR-KL25Z48M support

For the complete "out-of-the-box" Kinetis experience and faster time to market


0 Kudos

1,514 Views
BlackNight
NXP Employee
NXP Employee

Hello,

first I want to mention that the Processor Expert I2C driver can be with or without interrupts: using interrupts is just the normal case (at least for me).

Have you seen the Freescale provided example code on:

FRDM-KL25Z: Freescale Freedom Development Platform for Kinetis KL14/15/24/25 MCUs

?

I recommend that you use a logic analyzer to check the signals on the bus, as many things could be wrong. You even could use a FRDM-KL25Z as logic analyzer (see Tutorial: Using the FRDM-KL25Z as Low Power Board | MCU on Eclipse). Make sure that you verify your internal clock distribution settings, as there is an errata on this (see KL25Z and I2C: Missing Repeated Start Condition | MCU on Eclipse).

I hope this helps,

Erich

0 Kudos

1,514 Views
humbertoaboud
Contributor I

Thanks a lot for the help Erich,

I don't want to use process expert, with or without interrupts, I'm trying to code everything by myself. Fortunately, I fixed my code today, it had two problems:

  • First, my I2C read register function used to change to the receiver mode before waiting for the conclusion of the transmission.
  • And second, for some reason my code was setting the control register of the MMA8451Q in the wrong address, setting 0x1A instead of 0x2A. Fixing those two issues it works perfectly!

I will post my code here later so if someday someone wants to do it by coding it can be used it as reference.

0 Kudos

1,514 Views
sreenathreddy
Contributor II

HI CAN U SEND ME THE CODE

0 Kudos