MMA8652FC 3-axis accel - need timing diagram for single byte read and single byte write

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

MMA8652FC 3-axis accel - need timing diagram for single byte read and single byte write

Jump to solution
1,883 Views
tonybarry
Contributor I

Hi People,

Mods, if this is not in the right place for Freescale Forums, please advise and I will move to the location you specify.

I am using the above mentioned accel for an upcoming project.  The part is (just) small enough to do the job and I like the digital interface.

But so far I am having trouble with comms to the device.  I have worked through the docs and there are ambiguities in them (e.g. section 5.11.1 Single Byte Read - NAK is shown in the timing diagram but the text implies there is no NAK ("…The Master does not acknowledge (NAK) the transmitted data …".

What I am after is the timing diagram for a single byte read and an single byte write.  Ideally with a reg address on 0x0D (the Who-Am-I reg) for the Read, and a reg address of 0x2A (the Control Reg 1) for the Write.

This could be a screen grab off a scope, or something else showing the transitions and the originators of the transitions (i.e. master, slave).

Regards,

Tony Barry

Labels (1)
Tags (3)
0 Kudos
1 Solution
1,110 Views
TomasVaverka
NXP TechSupport
NXP TechSupport

Hi Tony,

I think there is something of a misunderstanding if you are referring to the SPI.

The MMA8652FC only has an I2C interface, so both SDA (data) and SCL (clock) lines need to be connected to the supply voltage via a pull-up resistor. The recommended value is between 1kΩ - 4.7kΩ.

If you want to use an accelerometer similar to the MMA8652FC, but with an SPI interface, I would recommend considering the FXLS8471Q. My example code including some screenshots illustrating SPI transactions is available here.


Regards,

Tomas

View solution in original post

0 Kudos
10 Replies
1,110 Views
TomasVaverka
NXP TechSupport
NXP TechSupport

Hi Tony,

Below is the image from a logic analyzer illustrating a single byte read from the WHO_AM_I register 0x0D. As you can see, it returns the correct value 0x4A.

Who_Am_I register read.JPG.jpg

A common problem with the read operation is sending a stop condition (a low to high transition of SDA while SCL is high) after the second byte (in this case 0x0D). The correct way is to release the SDA line (so that it transitiones to high) before the SCL line goes high.


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" or “Helpful”. Thank you.

1,110 Views
tonybarry
Contributor I

Hi Tomas,

This is exactly what I need.  Many thanks.

I have put your message as Helpful, and will apply the information over the next day.  If it is indeed the solution I shall also mark as Correct.

I would also like to mark it as Super Prompt, but I don't see that button.

Regards,

Tony Barry

0 Kudos
1,110 Views
TomasVaverka
NXP TechSupport
NXP TechSupport

You are welcome, Tony.

I will be glad hearing back from you regarding your progress in this matter.

Regards,

Tomas

0 Kudos
1,110 Views
tonybarry
Contributor I

Hi Tomas,

I have implemented your timing diagram in my firmware, and used a second MMA8652 to test out my interface code.

As with the first device, when I ask for the WhoAmI byte (loc: 0x0D value: 0x4A) it sees this address as holding 0x00.

All addresses from 0x00 to 0x30 read as 0x00.

If I change the device address (byte 2 in the single byte read sequence) from 0x3A to some other value, the device does not acknowledge.

Is it possible that the whoAmI byte is programmed in my devices as 0x00 ?

I will continue my investigations.

Regards,

Tony Barry

0 Kudos
1,110 Views
TomasVaverka
NXP TechSupport
NXP TechSupport

Hi Tony,

If you posted here your timing diagrams as well as your schematic, I might be able to help you in your investigation.

As you can see in Table 12 of the data sheet, there are some other registers with default value different from 0x00 such as the PL_BF_ZCOMP or P_L_THS_REG register, so if you read 0x00 also from these registers, it will not be a problem with an incorrect ID in the WHO_AM_I register.

As for changing the device address, the second byte is actually the address of the register you want to read from, so in your case 0x0D and not 0x3A.

As you can see above, to read the WHO_AM_I register:


1. Send a start sequence

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

3. Send 0x0D    // WHO_AM_I register address

4. Send a start sequence again (repeated start)

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

6. Read the data byte from WHO_AM_I register

7. Send NAK and a stop sequence

I hope it helps.

Regards,

Tomas

0 Kudos
1,110 Views
tonybarry
Contributor I

Hi Tomas,

Many thanks for your reply, and offer of help. I attach the timing diagram for a single byte read of address 0x0D.

The four traces are :

CLK - the SPI clock, driven from the microcontroller.

DAT - the SPI data line, driven by the microcontroller or the accel.

CS - not used by the accel, but output by the microcontroller and used by the Rigol scope to decode the data.

IND - not used by the accel, but output by the microcontroller to bracket when the ACK signal is sent by the accel. and sampled by the microcontroller.

I have used the standard circuit as described in the data sheet. The DAT line is pulled up with a 1K resistor. The accel is buffered by 100nF caps on BYPASS and Vdd close to the chip (within 5cm trace length). Vdd is also buffered by a 1uF cap.

As you can see in Table 12 of the data sheet, there are some other registers with default value different from 0x00 such as the PL_BF_ZCOMP or P_L_THS_REG registers, so if you read 0x00 also from these registers, it will not be a problem with an incorrect ID in the WHO_AM_I register.

Thank you for this. I attempted a read of P_L_THS_REG and PL_BF_ZCOMP and they also returned 0x00.

When I WRITE 0x01 to address 0x2A (i.e. set ACTIVE to 1) then subsequent reads of any addresses change from 0x00 to 0xFF. Attempting to set ACTIVE to 0 does not revert this behaviour (a power cycle is required). This leads me to think that I must look harder at my code and the timing.

I continue.

Many thanks for your help thus far.

Regards,

Tony Barry

0 Kudos
1,111 Views
TomasVaverka
NXP TechSupport
NXP TechSupport

Hi Tony,

I think there is something of a misunderstanding if you are referring to the SPI.

The MMA8652FC only has an I2C interface, so both SDA (data) and SCL (clock) lines need to be connected to the supply voltage via a pull-up resistor. The recommended value is between 1kΩ - 4.7kΩ.

If you want to use an accelerometer similar to the MMA8652FC, but with an SPI interface, I would recommend considering the FXLS8471Q. My example code including some screenshots illustrating SPI transactions is available here.


Regards,

Tomas

0 Kudos
1,110 Views
tonybarry
Contributor I

Hi Tomas,

After your insightful emails, I was able to get my accel reading the Who-Am-I byte correctly.

The timing diagrams were very helpful and if they could be incorporated in the datasheet it would be very good.

However the biggest help was when you politely pointed out that the accel was an I2C device rather than SPI :smileyhappy: - I rewrote my code over the weekend to reflect this protocol and now it is working correctly.

Such a blooper on my part is probably worthy of a beer or two at the Friday evening debug session.

I have set the OP question as "Answered". Hope this helps.

I can also post the code if your site works this way. Otherwise I can host it and link back.

Regards,

Tony Barry

0 Kudos
1,110 Views
TomasVaverka
NXP TechSupport
NXP TechSupport

Hi Tony,

Glad to hear that you got it working and thanks for your feedback.

We will consider including the timing diagrams in the data sheet.

Yes, you can post your code here or provide a link, it might be useful for other customers using our I2C accelerometers in conjunction with Atmel AVR MCUs.


Regards,

Tomas

0 Kudos
1,110 Views
tonybarry
Contributor I

Hi Tomas,

I think there is something of a misunderstanding if you are referring to the SPI.

Yes you are correct of course. I am using SPI decoding for the scope - the accel bus is I2C. I synthesise a chip select (CS) to make it easy for the scope to decode, but this signal is not part of the accel signals.

The MMA8652FC only has an I2C interface, so both SDA (data) and SCL (clock) lines need to be connected to the supply voltage via a pull-up resistor. The recommended value is between 1kΩ - 4.7kΩ.

Ah OK. Clock stretching during the data transmission segment.

I shall continue.

Regards,

Tony Barry

0 Kudos