cancel
Showing results for 
Search instead for 
Did you mean: 

STM32 DR register 0 when multiple SPI in use

snigur_andrey
Associate II

I have two SPI buses activated SPI1 (flash memory) and SPI3 (nrf24l01) on my STM32F407. Separately, they work fine. But, if I transfer something via SPI1, SPI3 read from the register always returns 0 (and in DR register for SPI3 is also 0, BUT sometimes it has value 3 (though has to be 46)). And I don't know where to look and dig dipper. Let me know if you need additional code or screenshots. 

1 ACCEPTED SOLUTION

Accepted Solutions
snigur_andrey
Associate II

I've found the solution!
I've added HAL_SPI_DeInit(&hspi1); and it works now!

 

Thanks @Tesla DeLorean and @waclawek.jan  for the help.

View solution in original post

7 REPLIES 7

a) There shouldn't be any interrelationship between different SPI peripherals on an STM32

b) The DR write and read go to DIFFERENT registers, you can't inspect what you sent

c) The debugger is very invasive. Don't use a Peripheral View it breaks DR/SR and FIFO's

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

Thanks for the reply.

a) yes, I have 2 different handlers and they have different addresses in memory

c) the interesting thing that when I don't send anything to SPI1, I can read from SPI3->DR the value I need and it's working stable, but as soon as I transmit via SPI1, SPI3->DR == 0 and never changes

What is on the respective SPI3_MISO and SPI3_SCK lines?

JW

I tried to check SPI3_SCK line and when SPI1 was not used I saw signals there, but when SPI1 was in use, nothing happened.

I also debugged HAL_SPI_Transmit() function and what I've found: DR is '0' even if I try to set it like this.

snigur_andrey_0-1717527623349.png

Original code from library:

snigur_andrey_1-1717527733613.png

 

Why's it in the SLAVE branch?

Both peripherals you have described are SLAVE devices, and the STM32 is the MASTER.

Not sure how this situation is going to be replicated elsewhere with the presentation provided so far.

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

It's in SLAVE branch, because it has only 1 byte to transmit

snigur_andrey_0-1717529002127.png

I've pushed the whole project to github

https://github.com/litai-tech/colir_one/tree/main/rocket_code

snigur_andrey
Associate II

I've found the solution!
I've added HAL_SPI_DeInit(&hspi1); and it works now!

 

Thanks @Tesla DeLorean and @waclawek.jan  for the help.