I'm working on spi communicate between stm32f0308-discovery and jetson tx2. Jetson is master and stm32 should be slave. (idk how but if it is possible stm32 may be master too.) My problem is I'm new for stm32 and I don't know how an I make stm32 to slave. Can someone show me a way for stm32 spi slave ? Thanks in advance.
Asked
Active
Viewed 1,510 times
3 Answers
1
You can start by reading the reference manual of your product family. Then, you can find examples of SPI peripheral configuration source code in STM32Cube software packages.
If you are new to STM32 and new to the microcontroller ecosystem, I'm afraid you will need some training. But there are plenty of resources online.

Guillaume Petitjean
- 2,408
- 1
- 21
- 47
-
Thank you! I just use 2 device which are master and slave and also NSS is activaded. I wonder it's necessary or not because when I try to read data from stm32 (slave device) there must be interrupt to use read data function. Should I use NSS interrupt or is there any way? – Burak Berzener Jul 31 '19 at 14:36
1
You can select SPI mode when configuring the SPI_InitTypeDef structure. You need to set the SPI_Mode to Slave as follows:
SPI_InitDef.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
SPI_InitDef.SPI_Mode = SPI_Mode_Slave; // <-- This is it
SPI_InitDef.SPI_DataSize = SPI_DataSize_8b; // 8-bit transactions
SPI_InitDef.SPI_FirstBit = SPI_FirstBit_MSB; // set it to match Master conf
SPI_InitDef.SPI_CPOL = SPI_CPOL_Low; // set it to match Master conf
SPI_InitDef.SPI_CPHA = SPI_CPHA_2Edge; // set it to match Master conf
SPI_InitDef.SPI_NSS = SPI_NSS_Hard; // use hardware SS
An example tutorial using blue pill boards can be found here

SOFuser
- 134
- 1
- 10
0
Yes. You can make STM32 as the slave. The only thing you need to do is CLEAR the MSTR Bit in The Control Register on the peripheral. You perhaps then can load some values in the SPI Data Register & then can read them from your other board.

Devashish Lahariya
- 23
- 4