Has anyone successfully use SPI1 of those pins?

SCLK -> PB3 
SDIO -> PB5 
SDO -> PB4 

I've tried to use another side of SPI1 pins on the other sides of the board (PA4, 5, 6, 7) and i can successfully communicate with enter image description here

  • Arduino and STM32 Blue pill are not the same, they are different platforms. And you need to supply more details, like the complete code.
    – RocknRoll
    Commented Apr 26, 2023 at 11:25
  • i used the stm32arduino core , so i will perform like arduino and the code is very simple just spi output to sensor its not responsing at all until i switch the pin it will work fine
    – Settasak
    Commented Apr 26, 2023 at 15:23

1 Answer 1


It depends on how you use the SPI object. If you use the SPI object directly like what Arduino Uno without creating an instance object, the SPI construct will default to the PA4 - PA7, see the default pins definition and default Class construct of Blue Pill.

For STM32 Arduino Core (Stm32duino), there are four STM32 Arduino Core specific APIs for configure the alternative SPI pins.

void setMISO(uint32_t miso)
void setMOSI(uint32_t mosi)
void setSCLK(uint32_t sclk)
void setSSEL(uint32_t ssel)

These must be called before the SPI.begin().

Another alternative way of using the alternative SPI pins is to create an SPI object and pass-in the pin assignments like this:

#include <SPI.h>

SPIClass mySPI(PB5, PB4, PB3, PB15); //mosi, miso, sclk, ssel

See the alternative construct API, and further information on STM32duino wiki page.

  • Thank a lot , you had no idea how many hours i waste on this thing :)
    – Settasak
    Commented Apr 27, 2023 at 16:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.