Skip to main content
Jalal Sadigli
Associate II
May 2, 2017
Solved

stm32f407vg spi1 data register stay 0xff

  • May 2, 2017
  • 14 replies
  • 2457 views
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
This topic has been closed for replies.
Best answer by Jalal Sadigli
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

14 replies

waclawek.jan
Super User
May 2, 2017
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

Jalal Sadigli
Associate II
May 2, 2017
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

waclawek.jan
Super User
May 2, 2017
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

Tesla DeLorean
Guru
May 2, 2017
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 (See Profile) Up vote any posts that you find helpful, it shows what's working..
Jalal Sadigli
Associate II
May 3, 2017
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?

Tesla DeLorean
Guru
May 3, 2017
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 (See Profile) Up vote any posts that you find helpful, it shows what's working..
Jalal Sadigli
Jalal SadigliAuthorBest answer
Associate II
May 7, 2017
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

Andrei Chichak
Lead
May 7, 2017
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