cancel
Showing results for 
Search instead for 
Did you mean: 

multi-Slave SPI using STM32F4's?

Seng Tak Goh
Associate III

I am trying to implement a star SPI interface, using STM32F4 as a single master, and interfaces with multiple STM32F4 MCU using SW managed NSS.

I have made sure that SSI is cleared when NSS is activated and set when NSS is deactivated so that the SCK on the common line will not shift the data out of the deselected slave. However, I am still having corrupted data received by the master and I think the problem is due to the fact that the MISO pin of deselected slave is not in High Impedance state.

While searching through the forum, I stumbled upon a similar post https://community.st.com/s/question/0D50X00009XkZWvSAN/multislave-spi-using-stm32f7s, in which it is mentioned that the MISO of all slaves should be configured in Alternate Function Open Drain mode instead of Alternate Function Push Pull, in the Reference Manual of STM32F7.

I gave it a try but the Master was then not able to read any data from the selected slave anymore.

My questions are:

  1. Was the recommendation of making MISO AF OD on the slaves only applicable to STM32F7?
  2. Is it true that the MISO pin is not automatically changed to Hi-Z state when NSS is not activated (when the frame protocol is not TI Mode), or am I doing something wrong?

End note: I did try to toggle the MISO pins between input mode when deselected and AF_PP when selected, as a workaround and it does work. Just wish to have the fastest approach. Using HW managed NSS did not seem to work.

Thanks in advance for answering

1 ACCEPTED SOLUTION

Accepted Solutions

> I changed the GPIO mode of NSS pin to EXTI on falling edge instead of AF_PP

There is no separate EXTI and AF_PP mode. This is a Cube nonsense; we see it here in forum way too often. EXTI is independent of MODER setting; as long as the pin is not set to Analog, you can use it as EXTI in parallel to whatever other setting you have.

JW

View solution in original post

4 REPLIES 4

> I think the problem is due to the fact that the MISO pin of deselected slave is not in High Impedance state.

Confirm that by observing the levels on the bus by oscilloscope.

> I have made sure that SSI is cleared when NSS is activated and set when NSS is deactivated

In Slaves? You don't need to do that.

SSM is set how?

> I stumbled upon a similar post https://community.st.com/s/question/0D50X00009XkZWvSAN/multislave-spi-using-stm32f7s, in which it is mentioned

> that the MISO of all slaves should be configured in Alternate Function Open Drain mode instead of Alternate Function Push Pull, in the Reference Manual of STM32F7.

Yes, it is; and in the forked thread https://community.st.com/s/question/0D50X00009XkaBbSAJ/does-spi-in-slave-mode-threestate-miso-on-inactive-nss-or-not the answer (from somebody whom I suspect is/was from the Prague support crew) clearly indicates it is nonsense. @Amel NASRI​  @Imen DAHMEN​ can you please confirm that it's a nonsense, and if so, can you please initiate purging this from the RMs (I've seen itin more than just one)?

JW

>> I think the problem is due to the fact that the MISO pin of deselected slave is not in High Impedance state.

>Confirm that by observing the levels on the bus by oscilloscope.

It is tedious at the moment as the PCB made by our hardware engineer omitted test points on the SPI lines. My hypothesis is made on the experiments that the interface works when I toggle the MISO between Input and AF_PP.

>> I have made sure that SSI is cleared when NSS is activated and set when NSS is deactivated 

>In Slaves? You don't need to do that.

Yes you are right.

I said that in my OP I did try to use HW to manage NSS in slave but MISO did not seem to change to Hi-Z, I did not tell the complete story. My application requires the NSS to trigger an interrupt when pulled low on the slave, so I changed the GPIO mode of NSS pin to EXTI on falling edge instead of AF_PP, and am thinking whether this may have rendered MISO not being abled to be tri-stated when NSS is high...will try to confirm this when I have the chance.

> I changed the GPIO mode of NSS pin to EXTI on falling edge instead of AF_PP

There is no separate EXTI and AF_PP mode. This is a Cube nonsense; we see it here in forum way too often. EXTI is independent of MODER setting; as long as the pin is not set to Analog, you can use it as EXTI in parallel to whatever other setting you have.

JW

Hi JW,

Thanks for the tip and I tried to change the slaves' NSS to be HW managed, and having them triggering EXTI as well. It now works as expected. Indeed I was misled by MXCube.

So I would like to:

  1. Second the statement that having NSS HW managed may have the MISO tristated automatically when deactivated. (Logically so when TI mode works in this manner)
  2. Second your statement that the note in the RM of STM32F7, what says MISO should be configured in AF_OD when in multi-slave configuration, is a nonsense.

Thanks a lot!