cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F407VG discovery SPI1 configuration/communication(nrf24l01+pa+lna) CMSIS

MKarp.1
Associate II

Trying to setup communication between stm32f407VG discovery and nrf24l01 via SPI. It looks like reading data from registers is going fine, but there is trouble with writing to them because, doesn't matter if i write something to register or if I don't, it always shows same values, different for every register and not 0x00 or 0xFF. I've looked at Arduino library for nrf24l01 and my read/write register functions look same, so it looks like that the problem is with SPI configuration or transmission functions. I've tried to connect this chip to Arduino and it worked fine, so the chip is definitely not broken. Google didn't help much because there is almost no information about configuration of SPI on stm32f4, most info is about stm32f1 series. Any idea what might be wrong there?

6 REPLIES 6
TDK
Guru

> Google didn't help much because there is almost no information about configuration of SPI on stm32f4, most info is about stm32f1 series.

There are plenty of examples on the internet and within the STM32CubeF4 example library. Among many others:

https://github.com/STMicroelectronics/STM32CubeF4/tree/master/Projects/STM32F4-Discovery/Examples/SPI

https://github.com/STMicroelectronics/STM32CubeF4/tree/master/Projects/STM32F411RE-Nucleo/Examples_LL/SPI

Note that the CS pin should be manually toggled on the STM32.

If you feel a post has answered your question, please click "Accept as Solution".
MKarp.1
Associate II
  1. Yeah, I know it, i toddle it with another functions(CSN_L/CSN_H), which are defined in rf24lib.h file.
  2. I know about STM32CubeF4, but I don't wanna use it, I want to configure registers manually, using only CMSIS.
TDK
Guru

> I know about STM32CubeF4, but I don't wanna use it, I want to configure registers manually, using only CMSIS.

You can still look through the library to see how it configures the peripherals and duplicate that behavior. You can also read the reference manual directly. LL functions are pretty easy to trace.

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

I've looked at datasheet and I thought I configured everything correctly, but it still doesn't work. The library functions are very strange, so I can't understand them. As a result, I'm asking this question.

berendi
Principal

The proper sequence to end the transmission according to the reference manual is

After the last data is written into the SPI_DR register:

1. Wait until TXE=1

while(!(SPI->SR & SPI_SR_TXE))
  ;

2. Then wait until BSY=0

while(SPI->SR & SPI_SR_BSY)
  ;

and now you can set set CS high.

By the way the SPI controller on the STM32F4 series is binary compatible with that of the STM32F1, so examples for STM32F1 should work.

If I correctly understood you, now the write function should look like this

void SPI1_write(unsigned char data){
	while(!(SPI1->SR & SPI_SR_TXE));
	SPI1->DR = data;
	while(!(SPI1->SR & SPI_SR_TXE));
	while(SPI1->SR & SPI_SR_BSY);
}

but now the read values are always the same for every register(0x0F). Didn't I understand you correctly?