1

I am using STM32H7 family of microcontroller as SPI Master Transmit device which needs to talk to 4 SPI slave devices receive only which are also all STM32H7 MCU's. Both master and slave are configured for software slave management. The confusion is how slave will identify when master wants to talk to it or transmit data to it without using hardware NSS pin? How slave device will start receiving in this scenario and stop receiving when all data transmitted?

A 786
  • 488
  • 1
  • 6
  • 16

3 Answers3

2

It is very simple. Every slave has one pin called CS. You need to select this device by setting this pin just by using the GPIO. Then you can transmit or receive data. Remember that master has to supply clock even if it wants only to receive data.

0___________
  • 60,014
  • 4
  • 34
  • 74
  • I thought its software slave management by using CS pin does it not mean hardware slave management? – A 786 Dec 01 '19 at 19:48
  • Software slave management is just the way of doing it. SPI works as usually and it needs CS lines to work – 0___________ Dec 01 '19 at 19:54
  • @P__J__ I think you misunderstood the question. It's not about the master side, and not about the wire run from the master to slave. The OP understand this. The question is: If software slave management is used, the SPI peripheral hardware does not act on changes to the CS pin. So how does it know when it should listen to SCK/MOSI and write to MISO and when it should ignore the SPI bus? – Codo Dec 02 '19 at 19:41
2

If you use software slave select (NSS), you must select and deselect the SPI interface by software.

Typically, you would setup an external interrupt on the pin used as NSS/CS and select/deselect the SPI interface when the interrupt is triggered.

On an STM32F1 chip, the SPI interface is selected/deselected by setting/clearing the SSI bit in the SPI_CR1 register. I assume it's very similar on a STM32H7 chip.

Update

I've just checked the STM32H7 and it's exactly the same.

Codo
  • 75,595
  • 17
  • 168
  • 206
0

It seems that the code shown below can manage the problem.

__HAL_SPI_ENABLE(&hspi1);
__HAL_SPI_DISABLE(&hspi1);
Suraj Rao
  • 29,388
  • 11
  • 94
  • 103
Junseok Oh
  • 11
  • 3
  • that's only available in hal library while I was programming on my own program created from scratch. It's only enabled and disabled using your provided functions. CS pin has to be used for controlling – A 786 Sep 04 '22 at 04:15