MMA8452 no I2C comms

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

MMA8452 no I2C comms

1,867件の閲覧回数
adamkarkowski
Contributor I

Hello,

 

I'm trying to get an MMA8452 working with a small 8-bit micro (8051 based). I'm bit-banging the I2C interface but the MMA8452 never responds. Looking at the scope, the comms frequency is about 60 kHz which the sensor should support.

 

Whenver I send the address (0x1D), I never get an ACK. If I ignore this and attempt to get a reading (e.g. from WHO_AM_I register) I always get 0xFF back meaning the device does not respond. I can scope the I2C lines and they look OK.

 

The procedure I'm using is (complete c file is attached).

// Start

      I2C_START();

    // Slave address

  I2C_WRITE(0x1D);

    // Slave control byte

  I2C_WRITE(0x0D);

     // Start

  I2C_START();

    // Slave address + read

  I2C_WRITE(TARGET | 0x80);

    // Read

    inData = I2C_READ();

 

VDD and VDDIO are definitely connected to 3V. Is there anything wrong with this? I really need an answer quickly so please respond as soon as you are able. If there is anything else you need to know, then please ask.

Original Attachment has been moved to: SMBus_Master.c.zip

ラベル(1)
0 件の賞賛
返信
3 返答(返信)

1,327件の閲覧回数
adamkarkowski
Contributor I

Hi Tomas,

You're correct. I had already worked that out but had to keep going due to an impending deadline so sorry about the slow response.

Regards,

0 件の賞賛
返信

1,327件の閲覧回数
TomasVaverka
NXP TechSupport
NXP TechSupport

Hi Adam,

Looking at your source code, it seems that you are not using the correct I2C slave address. Considering SA0 = 1, the 7-bit slave address is 0x1D, which translates to 0x3A for a write and 0x3B for a read:

MMA8452Q_Slave address.JPG

To read e.g. the WHO_AM_I register (0x0D) you have to:

1. Send a start sequence

2. Send 0x3A    // MMA8452Q slave address with the R/W bit low or 0x1D<<1

3. Send 0x0D

4. Send a start sequence again (repeated start)

5. Send 0x3B    // MMA8452Q slave address with the R/W bit high or (0x1D<<1)|0x01

6. Read the data byte from the WHO_AM_I register

7. Send NAK and a stop sequence.

Below is the image from a logic analyzer illustrating it (note that it is for the MMA8652FC I have on my desk).

Who_Am_I+register+read.JPG.jpg

And here is a single byte write operation which writes the value 0x3D to the CTRL_REG1 register 0x2A.

CTRL_REG1+register+write.JPG.jpg

I hope it helps.

Regards,

Tomas

PS: If my answer helps to solve your question, please mark it as "Correct". Thank you.

0 件の賞賛
返信

1,327件の閲覧回数
adamkarkowski
Contributor I

Incidentally, I've also got 4.7k pullups on the SDA and SCL lines.

0 件の賞賛
返信