Skip to main content
MHass.2
Associate II
Jul 26, 2020 8:17 PM UTC
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 ?

..

This topic has been closed for replies.
Tesla DeLorean
Tesla DeLoreanBest answer
Guru
Jul 26, 2020 10:43 PM UTC

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..

4 replies

KnarfB
Super User
Jul 26, 2020 8:30 PM UTC

Show us your code, please.

MHass.2
MHass.2Author
Associate II
Jul 26, 2020 8:39 PM UTC

  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
Jul 26, 2020 10:43 PM UTC

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
Jul 27, 2020 10:20 AM UTC

Thanks,

it is work good now.