cancel
Showing results for 
Search instead for 
Did you mean: 

SPI unable to write in SPI_CR1 register

gilles2399
Associate II
Posted on February 15, 2012 at 10:33

Hi All,

I try to configure SPI on a STM32 however something goes wrong in the SPI_Init() function.

 I remarked that the instuction SPIx->CR1 = Tempreg don't write in the SPI register, the register value stay at 0.

We have controlled all the program thoroughly, the adress of the SPI register and the Value of Tempreg and all seems to be OK.

Have you already had this problem ?

Thanks in advance for your advice.

7 REPLIES 7
Posted on February 15, 2012 at 13:42

I try to configure SPI on a STM32 however something goes wrong in the SPI_Init() function.

 

I remarked that the instuction SPIx->CR1 = Tempreg don't write in the SPI register, the register value stay at 0.

 

 

We have controlled all the program thoroughly, the adress of the SPI register and the Value of Tempreg and all seems to be OK.

 

 

Have you already had this problem ?

 

Forgot to enable the SPI's APB clock perhaps?
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
gilles2399
Associate II
Posted on February 15, 2012 at 14:13

No, I've already Enabled the SPI clock

Main part of my SPI Initialization are :

- Declaration of a new SPI Structure

- Declaration of a new GPIO Structure

- Enable The SPI Clock (RCC_APB1PeriphClockCmd(RCC_APB2Periph_SPI1, ENABLE))

- Enable GPIO Clock ( RCC_AHB1PeriphClockCmd)

- I connected Pin (MOSI, MISO, SCK) to AF5

- Initialize each field of  GPIO Structure (Speed, etc...)

- Configuration of MOSI, MISO and SCK PIN

- Configuration of the CS

- Set the CS to High

- Initialize each field of the SPI Strucutre (CPHA CPOL, etc, ...)

- SPI_ Init()

- SPI_CMD(SPI1, Enable)

I think I must have forgot one step or maybe invert something.

John F.
Senior
Posted on February 15, 2012 at 14:47

RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE) ?

gilles2399
Associate II
Posted on February 15, 2012 at 15:18

Yes that's it, Thanks  very much to all , it haven't seen this little error.

Posted on February 15, 2012 at 19:23

Yes that's it, Thanks  very much to all , it haven't seen this little error.

 

Yes, this mixes buses

  RCC_APB1PeriphClockCmd(RCC_APB2Periph_SPI1, ENABLE)

It always helps to post actual code fragments, or better yet compilable code. Without some context we all just have to guess.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
mbabu527
Associate II
Posted on February 25, 2012 at 11:11

hi Gilles

can you share your SPI code???? i am working on spi but its not working please post your code or give some instructions.

Posted on February 25, 2012 at 15:18

can you share your SPI code???? i am working on spi but its not working please post your code or give some instructions.

The firmware libraries have typically contained several working examples.

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