AnsweredAssumed Answered

Problem communicating with MMA8452Q

Question asked by juanm on Jan 17, 2014
Latest reply on Jan 23, 2014 by juanm

Hi! I'm having problems with this accelerometer. I'm using an FRDM KL25Z and I tested the onboard MMA8451Q with this code:

 

MMA8451Q - Bare metal example project

 

This code works great. The problem started when I wanted to try this code with the MMA8452Q. I modified the code so I can use it with the I2C1 module and I used PTC1 as SCL and PTC2 as SDA. Also, I used PTA5 for the interrupt. So, the configuration is like this:

 

/******************************************************************************

* MCU initialization function

******************************************************************************/

 

 

void MCU_Init(void)

{

  //I2C0 module initialization

  SIM_SCGC4 |= SIM_SCGC4_I2C1_MASK; // Turn on clock to I2C0 module

  SIM_SCGC5 |= SIM_SCGC5_PORTC_MASK; // Turn on clock to Port C module

  PORTC_PCR1 = PORT_PCR_MUX(2); // PTC1 pin is I2C1 SCL line

  PORTC_PCR2 = PORT_PCR_MUX(2); // PTC2 pin is I2C1 SDA line

  I2C1_F  = 0x14; // SDA hold time = 2.125us, SCL start hold time = 4.25us, SCL stop hold time = 5.125us *

  I2C1_C1 = I2C_C1_IICEN_MASK;     // Enable I2C0 module

 

  //Configure the PTA5 pin (connected to the INT1 of the MMA8451Q) for falling edge interrupts

  SIM_SCGC5 |= SIM_SCGC5_PORTA_MASK; // Turn on clock to Port A module

  PORTA_PCR5 |= (0|PORT_PCR_ISF_MASK| // Clear the interrupt flag

   PORT_PCR_MUX(0x1)| // PTA5 is configured as GPIO

   PORT_PCR_IRQC(0xA)); // PTA5 is configured for falling edge interrupts

 

  //Enable PORTA interrupt on NVIC

  NVIC_ICPR |= 1 << ((INT_PORTA - 16)%32);

  NVIC_ISER |= 1 << ((INT_PORTA - 16)%32);

}

 

But this doesn't work. The program get stuck in the function I2C_Wait();

If I try to read the WHO AM I register, it always return 0xFF. I tried with two different accelerometers, and both fails.

 

I attach the complete code, maybe someone can test it.

 

PD: This is the breakout board that I'm using.

 

MMA8452 3-Axial Triaxial Digital Accelerometer Module for Arduino - Free Shipping - DealExtreme

Original Attachment has been moved to: MMA8452q_KL25.zip

Outcomes