cancel
Showing results for 
Search instead for 
Did you mean: 

stm32f407vg spi1 data register stay 0xff

Jalal Sadigli
Associate III
Posted on May 02, 2017 at 10:53

hi, i am new to community.....

i have a stm32f4 discovery board with sym32f407cg microcontroller i tried to test spi communucation of the microcontroller with onboard accelerometer

but there is one or more problem that i can not hande

the problem is whatever i write on data register of spi1 , the register only shows 0xff when i read it with the help of pointer

how can i solve this problem

thats what i did as settings of spi1..

spi_cr1 |= 0x30; // select speed

spi_cr1 |= 0x03; // select cpha and cpol

spi_cr1 |= 0x00; // select dff

spi_cr1 |= 0x00; // select msbfirst

spi_cr2 |= 0x10; // select frf

spi_cr2 |= 0x04; // set ssoe

spi_cr1 |= 0x04; // set mstr

spi_cr1 |= 0x40; // enable spi

##discovery ##spi #stm32
14 REPLIES 14
Posted on May 03, 2017 at 17:30

You'd want to make sure the correct chip select GPIO pin is being used, and that you can read back the content of the CHIPID or WHOAMI type register.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on May 05, 2017 at 07:43

the board exactly the same with the image you upload ... the version is MB997D 

Posted on May 05, 2017 at 07:44

it the Pin E3 that i am using for chip select for spi1

Jalal Sadigli
Associate III
Posted on May 07, 2017 at 19:22

i have solved the problem....

the problem is spi does not communicate correctly because of reasons

***the ti frame format has its own cpha cpol settings which controlled by hardware and can not controlled through cr1 register

***rxne and txe flag should be checked with busy flag . because txe flag set after data transfered to shift register but transmission is not finnished

and also before setting cs pin  low the busy flag must be checked

Posted on May 07, 2017 at 20:14

Each slave chip manufacturer is free to choose the cpha and cpol settings. Each master manufacturer is free to choose how to express the phase and polarity. 

Beware, there is a bunch of documentation problems with this accelerometer.

I wrote a series of articles on SPI in general and the LIS3DSH on the F4Discovery in specific. See 

http://embedded.fm/blog/2017/4/26/i-apply-spi-good-vibrations

 and the two previous articles.

Andrei