AnsweredAssumed Answered

multi-Slave SPI using STM32F7's?

Question asked by David Littell on May 16, 2017
Latest reply on May 18, 2017 by David Littell

To run multiple STM32F7's as SPI Slaves I enable/disable their active control of MISO using:


/* Enable MISO to be actively driven (i.e., controlled by the SPI2 module). */

GPIO_InitStruct.Pin = SMCU_SPI2_MISO_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Alternate = GPIO_AF5_SPI2;

HAL_GPIO_Init( SMCU_SPI2_MISO_GPIO_Port, &GPIO_InitStruct );




/* Set MISO to be an input until it needs to be actively driven (only when I'm sending to the SPI Master). */

GPIO_InitStruct.Pin = SMCU_SPI2_MISO_Pin;
GPIO_InitStruct.Pull = GPIO_PULLUP;

HAL_GPIO_Init( SMCU_SPI2_MISO_GPIO_Port, &GPIO_InitStruct );


This works well...until it doesn't.  ;-)  After some (highly variable) number of SPI transactions I see a Slave simply not drive MISO even though control of the pin has been given to the SPI module via the code above.  A logic analyzer trace shows that the Slave appears to start driving MISO but then stops driving it after about 1 uS.  (I can tell this because the Slaves are set to apply their pullups when their MISO pins are configured as inputs in the code above and the Slave-produced data begins and ends with 0's.)  Here's a logic analyzer trace of a good SPI transaction followed by a failing one:



(I have no idea if anyone's going to be able to see that, so I'll attach it as well and hopefully that'll be more readable.)

The yellow/green pair of signals shows a successful transfer from a Slave.  The bottom red trace (MISO) goes to 0 near the rising edge of the yellow signal, as expected and the correct data is clocked out of the Slave.  The blue/violet pair of signals shows where the Slave starts to drive MISO near the rising edge of the blue signal but then abandons it and leaves the Master to clock in all those 1's.  Note that the SPI data being produced by the Slaves are identical.  Note also the position of the logic analyzer's timeframe scrolling marker (the gray circle at the bottom of the trace).  Thousands of SPI transfers had occurred flawlessly for 3 Slaves until suddenly blue/violet decided to not play anymore.


By the way, there's no error returned from HAL_SPI_Transmit_DMA() and the SPI error callback isn't being called.


Any insights or recommendations would be eagerly received.