cancel
Showing results for 
Search instead for 
Did you mean: 

Connect accelerometer to stm32

wsevendays
Associate II
Posted on December 04, 2011 at 23:11

Hello. I have troubles with connecting adxl345 to stm32f103vet6.

When I try to read a data from device, I always get '0'. For example:

int16_vect3 myVec;

ADXL_GetACC(myVec);

///myVec.x now is '0', myVec.y=0,myVec.z=0I'm sure that I connect and initialize the accelerometer properly - http://pastebin.com/T4fuArEr

#spi #stm32 #adxl345
3 REPLIES 3
Posted on December 04, 2011 at 23:56

Be sure you enable the clocks for GPIOA and SPI1, before configuring the peripherals.

You initialize some pins for SPI2

Set the pins as AF_PP, the peripheral will control the direction/use based on 2wire and Master/Slave settings.

  /* Configure SPI1 pins: SCK, MISO and MOSI ----------------------------*/

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7;

  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;

  GPIO_Init(GPIOA, &GPIO_InitStructure);

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
wsevendays
Associate II
Posted on December 05, 2011 at 12:15

If I doing it how you say  ADXL_SPI_Setup()!=Success

And now I can't initizalize, but few days ago all was be ok.
wsevendays
Associate II
Posted on December 12, 2011 at 23:32

I decided to use I2C connection and all is ok.