cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L151CBT6 need help with SPI slave setup (no hal)

Chrizzly
Associate III

Setup:

  • Master: PLD, SPI Frequency 4MHz
  • Slave: STM32L151CBT6, SysClk 32MHz (this one uses the code below)

Hello Guys,

Below you can see my code. The Problem I have is that my configuration data which is 32 Bytes long is not received properly. For test reasons I send it back in the second half of a 64 Byte array.

The 1st byte of the received configuration data is a sent byte from previous received data. To be precicse its the 0x07 sent from the PLD of the start up phase below.

As a consequence the 32 Byte config data looks like this: [0x07, Config. Byte 1, ..., Config. Byte 31]. The 32th Byte is missing.

Can someone tell me what I am doing wrong?

4 REPLIES 4
TDK
Guru

You're off by one on your lengths.

Nevermind. Didn't read closely enough. It is a convoluted way of doing things, however.

If you feel a post has answered your question, please click "Accept as Solution".

Watch for the hazard of enabling the clock, and then immediately touching the peripheral.

Also be aware the multiple load-stores on the SAME register will not be folded by the compiler and are one of THE LEAST EFFICIENT ways possible of coding this.

The interest in unpacking others broken register level code is LOW, expect to own the burden of debugging it.

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

What do you mean by "enabling the clock, and then immediately touching the peripheral"? Do you mean I should include a delay after this line "RCC->APB2ENR |= (1<<12); //Enable SPI1 Clock"? If yes I don't see how this has any effect on my problem.

How can I make this more efficient?

In SPI_Reg_Transmit(), wait for RXNE to be set, before you read DR.

JW