PlatformIO Community

Use of 2 different SPI hardware ports i parallel stm32f4 -Arduino

Hello, i am new here.

i want to use 2 different spi ports in parallel connected to different hardware. Single SPI is fine:
SPI.begin();
SPI.setClockDivider(SPI_CLOCK_DIV4);
SPI.setDataMode(SPI_MODE0);
SPI.setBitOrder(MSBFIRST);

I have only found 1 advice to use the second SPI port:

SPIClass SPIII(PB15, PB14, PB13);
SPIII.begin();
SPIII.setClockDivider(SPI_CLOCK_DIV4);
SPIII.setDataMode(SPI_MODE0);
SPIII.setBitOrder(MSBFIRST);

Trying to use the SPI ports:

sendbuffer[10] = SPI.transfer(0); is fine , works.

sendbuffer[4] = SPIII.transfer(0); does not work. The error message is:

src\main.cpp:264:19: error: ‘SPIII’ was not declared in this scope; did you mean ‘SPI’?

I have no idea what’s wrong.
It would be nice to get some help.

Thanks in advance.
Ulrich

What’s the full code? The SPIII variable must either be global or be declared in the same function (though, you probably want it global). Seems like a pure C++ issue to me.

Dear maxgerhardt,
thank you. Your suggestion helped me a lot to find the error between my ears.

it was

void setup() {

SPIClass SPIII(PB15, PB14, PB13);

  SPIII.begin();
  SPIII.setClockDivider(SPI_CLOCK_DIV4);
  SPIII.setDataMode(SPI_MODE0);
  SPIII.setBitOrder(MSBFIRST);
 }

but it should be:

SPIClass SPIII(PB15, PB14, PB13);

void setup() {

  SPIII.begin();
  SPIII.setClockDivider(SPI_CLOCK_DIV4);
  SPIII.setDataMode(SPI_MODE0);
  SPIII.setBitOrder(MSBFIRST);
 }

The examples have not been clear enough for me to understand the usage of the example.

It seems to work. Now i will check it with hardware.
Thanks a lot,
Ulrich

1 Like