cancel
Showing results for 
Search instead for 
Did you mean: 

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 ?

MHass.2
Associate III
 
1 ACCEPTED SOLUTION

Accepted Solutions

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
Up vote any posts that you find helpful, it shows what's working..

View solution in original post

4 REPLIES 4
KnarfB
Principal III

Show us your code, please.

MHass.2
Associate III

  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 ;

}

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
Up vote any posts that you find helpful, it shows what's working..

Thanks,

it is work good now.