MMA8452, reads returning 0xFF

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

MMA8452, reads returning 0xFF

ソリューションへジャンプ
3,070件の閲覧回数
keefw2000
Contributor I

Hello, I am using the MMA8452Q Sparkfun Breakout board https://www.sparkfun.com/products/14587 connected to an STM32F401RE Nucleo board. I used the STM32CubeMX default configuration and just added an I2C bus to the setup. All peripheral initializations are auto-generated by CubeMX.

On the logic analyzer, I am able to write and read with the appropriate ACKs and NACKs, but the reads all return 0xFF. I read through the other forum posts, but was unable to get my device to read properly.

Any help would be much appreciated.

#define MMA8452Q_DEFAULT_ADDRESS 0x3A

uint8_t I2C_ByteRead(uint8_t reg)
{
   uint8_t result = 0;
   uint8_t dataBuffer[1]={0};
   //Specify the register to read from
   if(HAL_I2C_Master_Transmit(&hi2c2), MMA8452Q_DEFAULT_ADDRESS, &reg,
                             1, 100)==HAL_OK)
   {
      if(HAL_I2C_Master_Receive(&hi2c2, MMA8452Q_DEFAULT_ADDRESS, dataBuffer,
                                1, 100)==HAL_OK)
      {
         result = dataBuffer[0];
      }
   }
   return result;
}
ラベル(1)
0 件の賞賛
返信
1 解決策
3,055件の閲覧回数
TomasVaverka
NXP TechSupport
NXP TechSupport

Hi Kayla,

 

Looking at your screenshot, there is the stop condition between the second (0x0D) and third byte (0x3B). This is incorrect.

 

You will likely need to modify the HAL_I2C_Master_Transmit() function as it sends the stop condition after the data (0x0D). So you need to change it so that SDA transitiones to high before the SCL goes high in order to eliminate this stop condition.

 

The transaction should look as follows:

 

1. Send a start sequence

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

3. Send 0x0D // Address of the WHO_AM_I register

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 WHO_AM_I register

7. Send NAK and the stop sequence

 

Here is an example for the MMA8652FC (Device ID = 0x4A) as I do not have access to the MMA8452Q right now.

 

Who_Am_I+register+read.jpg

 

I hope it helps!

 

Best regards,

Tomas

 

元の投稿で解決策を見る

0 件の賞賛
返信
2 返答(返信)
3,056件の閲覧回数
TomasVaverka
NXP TechSupport
NXP TechSupport

Hi Kayla,

 

Looking at your screenshot, there is the stop condition between the second (0x0D) and third byte (0x3B). This is incorrect.

 

You will likely need to modify the HAL_I2C_Master_Transmit() function as it sends the stop condition after the data (0x0D). So you need to change it so that SDA transitiones to high before the SCL goes high in order to eliminate this stop condition.

 

The transaction should look as follows:

 

1. Send a start sequence

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

3. Send 0x0D // Address of the WHO_AM_I register

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 WHO_AM_I register

7. Send NAK and the stop sequence

 

Here is an example for the MMA8652FC (Device ID = 0x4A) as I do not have access to the MMA8452Q right now.

 

Who_Am_I+register+read.jpg

 

I hope it helps!

 

Best regards,

Tomas

 

0 件の賞賛
返信
3,052件の閲覧回数
keefw2000
Contributor I

Hi Tomas,

Thank you for the suggestion.

I will take a look at that and let you know how it goes.

Best,

Kayla

0 件の賞賛
返信