cancel
Showing results for 
Search instead for 
Did you mean: 

Setting of GPIO PUPDR and OTYPER for SPI pins

Gpeti
Senior II

Hello,

I know it sounds like a basic and dumb question but I actually didn't find the answer.

I have communication issues between 2 STM32H743 based Nucleos.

On the master I use SPI1.

If I use SPI1 on the Slave it works fine (repeated send/receive communications).

If I use SPI2 on the Slave, I have communication issues: the Slave receives data correctly but the Master receives crap (CRC error).

The settings are:

  • for the master: GPIOs PA5,6,7 in Alternate Function, Very High Speed, PullDown set in PUPDR, OTYPER not modified (so push pull by default). SPI in simplex mode (I disable SPI between send and receive phase as described in errata sheet, prescaler to 8 (so should not be any issue of SPI clock frequency). All clocks are maximum as in code examples provided by STMicro (400Mhz fo Sysclock etc...)
  • for the slave: exactly same config for SPI1 or SPI2 (I'm using pins PB13, PC2 and PB15 for GPIO, GPIOB and GPIOC have been clocked)

So my question: when using alternate function for a GPIO, does the pullup/pulldown setting matter ? Same question for output type (push-pull / open drain) ? And what settings should be used for SPI pins ? HAL examples from ST set all SPI pins with pull-down and push-pull. Is it correct ?

18 REPLIES 18

The single most important thing is to have short interconnections (that includes paths on the PCB, 10cm may be too long, stubs on the PCB going to some different onboard chip may have impact), good ground/return, best is individual return for each signal and signal wires twisted with their respective return.The most important is to maintain SCK integrity. VeryHigh OSPEEDR may be surprisingly wrong, try lower. You may need to add series terminator resistors to impedance-match.

If you switch off SPI between transactions, make sure slave is deselected the whole time (NSS is high).

OTYPER push-pull; pulldowns mostly don't matter as the lines are supposed to be hard driven from the respective party whenever needed.

JW

TDK
Guru

SPI1 and SPI2 are on different APBs, which typically have different clocks. Your slave SPI clock should be higher than the master clock by 2x. Lower the master clock or increase the slave clock and try it. Could also be the slave doesn't push data out fast enough for the master. A logic analyzer would provide more insight.

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

> A logic analyzer would provide more insight.

+1

Thank you, I didn't know for high speed being wrong. Will give it a try. I don't use NSS at all

yes sure, slave processing speed is definitely an issue, i am taking it into account. Unfortunately I don't have a logic analyser but agree with our comment.

Why did you strike through the first sentence ? Is it wrong ? (didn't have time to check yet)

About your comment the ref manual says:

"There is no specific constraint concerning the frequency ratio between these clock signals (spi_pclk and spi_ker_clk). The user

has to consider a ratio compatible with the data flow speed in order to avoid any data

underrun or overrun events only."

and

"The SPI working in slave mode handles data flow using the serial interface clock derived

from the external SCK signal provided by external master SPI device. That is why the SPI

slave is able to receive and send data even when the spi_pclk and spi_ker_ck clock

signals are inactive."

bivin mato
Associate III

So my question: when using alternate function for a GPIO, does the pullup/pulldown setting matter ? Same question for output type (push-pull / open drain) ? And what settings should be used for SPI pins ? HAL examples from ST set all SPI pins with pull-down and push-pull. Is it correct ?

Find the settings applicability below.

0693W000000XNG3QAO.png

Sorry I don't understand the meaning of this figure.

> when using alternate function for a GPIO, does the pullup/pulldown setting matter ?

Yes.

> Same question for output type (push-pull / open drain) ?

Yes.

> And what settings should be used for SPI pins ?

Whichever fits your application. With SPI, it would be typically push-pull, no pullup/pulldown; but then there are also non-typical applications.

JW