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
1 ACCEPTED SOLUTION

Accepted Solutions
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

View solution in original post

14 REPLIES 14
Posted on May 02, 2017 at 12:28

The SPI_DR is in fact two registers: when you write it, it is the transmit buffer; when you read it, it is the receive buffer. Thus you read always what you've received last.

JW

Posted on May 02, 2017 at 13:13

Thanks for your reply

But the problem is when i write 0x20 to data register ,it shows 0xff on dr

Posted on May 02, 2017 at 13:29

That's it - you'll never read back the data you've written into SPI_DR, except if you loop back MOSI into MISO externally.

JW

Posted on May 02, 2017 at 13:41

Use Cube example for SPI for Nucleo or Discovery of the same STM32Family. Check the schematics that the sensor can be properly addressed as SPI. In some sensors, they power up in SPI 3 wire mode and there might be a bit to write in the sensor to activate the 4 wire mode (for very generic SPI communication).

Posted on May 03, 2017 at 01:16

What version of the board do you have? Which accelerometer does it use?

Is this an official ST board, or a clone?

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 02, 2017 at 23:52

okay , i have tested shorted miso and mosi that worked . what i had sent over spi returned back and i can saw it .

but when  i try to communicate with accelerometer rx data become 0xff 

i can not handle the problem

Posted on May 02, 2017 at 23:54

i have looked into datasheet of accelerometer there is no such kind of information also tutorials written about onboard accelerometer (stm32f4discovery board) does not contain any that kind of info.

Posted on May 03, 2017 at 10:36

it is probably cloned one because i have bought it from china.

the accelerometer is 

LIS3DSH

how to check version of board?

Posted on May 03, 2017 at 17:28

0690X00000603ohQAA.jpg

The colour of the board, buttons, and audio jack should be consistent with this image. The version is in the top corner, the newer boards have ''STM32F407G-DISC1'' silk-screened in the top-left corner, and a board ♯ MB997D

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..