2017-05-02 01:53 AM
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 msbfirstspi_cr2 |= 0x10; // select frf
spi_cr2 |= 0x04; // set ssoe spi_cr1 |= 0x04; // set mstr spi_cr1 |= 0x40; // enable spi##discovery ##spi #stm32Solved! Go to Solution.
2017-05-07 10:22 AM
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
2017-05-02 03:28 AM
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
2017-05-02 06:13 AM
Thanks for your reply
But the problem is when i write 0x20 to data register ,it shows 0xff on dr
2017-05-02 06:29 AM
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
2017-05-02 06:41 AM
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).
2017-05-02 04:16 PM
What version of the board do you have? Which accelerometer does it use?
Is this an official ST board, or a clone?
2017-05-02 04:52 PM
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
2017-05-02 04:54 PM
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.
2017-05-03 03:36 AM
it is probably cloned one because i have bought it from china.
the accelerometer is
LIS3DSH
how to check version of board?
2017-05-03 10:28 AM
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