-1
\$\begingroup\$

I'm interfaceing an Xmega128C3 with MMA8451Q acceleration sensor via i2c. I was able to initialize the accelerometer, I checked every transmission on oscilloscope, it was done properly.

The problem occurs when the xmega tries to read (in Master mode) from the slave. According to the following figure, after an acknowledged Address+Read transmission, the xmega should start receiving the first byte from the slave. However, I checked it on the scope, it does not do so.

figure

(One more thing I discovered which possibly relates to this: if I send the "Send acknowledge and receive next byte" command (CTRLC=0x02) right after the Address+read+ACK, then the whole i2c seems to "rush" one cycle ahead, and this way I was able to recieve 7 bits from the slave.)

Is this a hardware error in the xmega, or am I misunderstanding something?

\$\endgroup\$
1
\$\begingroup\$

I don't know if this is actually your problem, but looking at the MMA8451Q datasheet, page 17 and 18 for "Single Byte Read", you cannot just do an I2C read. You must do the following sequence:

  • START
  • Address with R/W bit 0 (write)
  • Write byte with register address
  • Repeated-START
  • Address with R/W bit 1 (read)
  • Read data byte
  • STOP

This sequence is very common in I2C slave devices to allow the master to specify the register to read.

I have no direct experience with the MMA8451Q so I cannot be sure but I'm guessing that the raw I2C read is confusing its internal state machine.

\$\endgroup\$
  • \$\begingroup\$ Yes, I know this, and I follow these steps, the problem is that it doesn't read, unless I make the last "bug" I mentioned, where the whole thing rushes one cycle and then of course I lose the first bit, and I cannot ACK (so cant do multiple byte read as well) since the ACK slips to the "next byte's first bit". Sorry for the broken english, I hope I can make myself understood. So in short: im not doing "raw read" \$\endgroup\$ – balazs94 May 16 '15 at 0:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.