cancel
Showing results for 
Search instead for 
Did you mean: 

Stm32f302 interface to Adxl345

Bunty Gtm
Associate II
Posted on August 29, 2017 at 22:02

Hello everyone I am trying to interface acceleration sensor Adxl345 to stm32f302 through I2C  using the HAL Library. Actually I am learning the programming , does any one help me how to get the data from sensor. I wrote this code , it does not work it. 

void adxl345_data(void)

{

uint8_t data[2];

int x ;

int data_1;

char buff[100];

HAL_I2C_Mem_Read(&hi2c3, 0x53<<1, 0x32, I2C_MEMADD_SIZE_8BIT, (uint8_t*)data, 2, 1000);

x = ( data[1]<<8) |data[0];

}

could you give me idea where is mistake ? 

1 REPLY 1
Posted on August 29, 2017 at 22:46

Hello!

This is the right funtion to read the ADXL345 

You use the second 0x53 address, make sure that SDO/ALT ADDRESS pin (Pin 12) is grounded. else use the 0x1D address.

I2C_MEMADD_SIZE_8BIT must be 1.

But this isn't the correct way to read the X_data.

Needs some initialization first .

Try first to read the DEVID register (address 0x00   , one byte) to check the functionality of your code.

Then initialise the chip (at least the power control register 0x2d ) 

Regards.

vf