Skip to main content
MHass.2
Associate II
July 26, 2020
Solved

Accelerometer Reading Issue Hi everyone, I am using MMA8451Q Accelerometer with stm32f407 discovery board . there is a problem every time i try to read WHO_AM_I register i get 0x00 value , Knowing that it's default value is 0x1A. can you help me ?

  • July 26, 2020
  • 4 replies
  • 1476 views

..

This topic has been closed for replies.
Best answer by Tesla DeLorean

I'd use HAL_I2C_Mem_Read() myself.

Getting a NACK from the device?

Try dumping the entire register space, check with a logic analyzer

4 replies

KnarfB
Super User
July 26, 2020

Show us your code, please.

MHass.2
MHass.2Author
Associate II
July 26, 2020

  uint8_t WHO_AM_I = 0x0D;

uint8_t temp = 0;

I2C_HandleTypeDef* Handle = I2Cx;

/* Format I2C address */

DataStruct->Address = 0x38;

uint8_t address = DataStruct->Address;

/* Check if device is connected */

if(HAL_I2C_IsDeviceReady(Handle,address,2,5)!=HAL_OK)

{

return MM8451_Error;

}

/* Check who am I */

//------------------

/* Send address */

if(HAL_I2C_Master_Transmit(Handle, address, &WHO_AM_I, 1, 1000) != HAL_OK)

{

return MM8451_Error;

}

/* Receive multiple byte */

if(HAL_I2C_Master_Receive(Handle, address, &temp, 1, 1000) != HAL_OK)

{

return MM8451_Error;

}

/* Checking */

while(temp != 0x1A)

{

bug = temp; // i print this value using usart it is 0x00

return MM8451_error ;

}

Tesla DeLorean
Tesla DeLoreanBest answer
Guru
July 26, 2020

I'd use HAL_I2C_Mem_Read() myself.

Getting a NACK from the device?

Try dumping the entire register space, check with a logic analyzer

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
MHass.2
MHass.2Author
Associate II
July 27, 2020

Thanks,

it is work good now.