3
\$\begingroup\$

I want to use two SPI peripherals on the same STM32 MCU just to practice this protocol, because I don't have any other device to test with.

Is it possible to do that?

\$\endgroup\$
8
  • 3
    \$\begingroup\$ That's exactly the point of having multiple peripherals...so that you can connect much stuff. It's even possible to send with one SPI and receive it with another (connect one SPI to another directly, talk to yourself basically). You probably have like 6 USARTs. Who do you think would be the point if you could only use one. \$\endgroup\$
    – Ilya
    Feb 21, 2022 at 10:49
  • \$\begingroup\$ So, I need to configure one as master and one as slave ? \$\endgroup\$ Feb 21, 2022 at 10:51
  • \$\begingroup\$ if you recommend any article about SPI transmission and receiving , please le me know \$\endgroup\$ Feb 21, 2022 at 10:52
  • \$\begingroup\$ What you NEED to do is entirely up to you. If you want to have 3 SPI all as masters - you can do that too. The bottom line is - yes, every peripheral can function independently from all other. \$\endgroup\$
    – Ilya
    Feb 21, 2022 at 10:52
  • 1
    \$\begingroup\$ Then...still get the documentation and basic tutorials \$\endgroup\$
    – Ilya
    Feb 21, 2022 at 10:55

4 Answers 4

5
\$\begingroup\$

You can use two SPI devices on this board.

You need to disable LIS302 chip by PE3 -> GND

Then configure SP1 as master with hardware NSS and SPI2 as slave with hardware NSS.

CONNECT:

SPI1 MISO -> SPI2 MISO
SPI1 MOSI -> SPI2 MOSI
SPI1 SCK  -> SPI2 SCK
SPI1 NSS  -> SPI2 NSS

enter image description here

\$\endgroup\$
2
  • \$\begingroup\$ what is hardware NSS exactly ? does it play the role of a chip select ? \$\endgroup\$ Feb 21, 2022 at 15:45
  • \$\begingroup\$ Depending on the mode selected. It is good to read the Reference Manual \$\endgroup\$ Feb 21, 2022 at 15:46
1
\$\begingroup\$

Yes, it's possible. Just connect two SPI peripherals together and make one of them master and the other slave.

\$\endgroup\$
9
  • \$\begingroup\$ when I active the SPI interface on STM32CubeMX it doesn't highlight a "Chip Select" pin for me, I can choose one for the master, but for the salve what I can do exactly ? \$\endgroup\$ Feb 21, 2022 at 13:25
  • \$\begingroup\$ Select a proper mode which has hardware chip select. \$\endgroup\$
    – Justme
    Feb 21, 2022 at 13:43
  • \$\begingroup\$ What do you mean exactly by proper mode ? when I choose SPI interface as a slave on the cubeMX, it highlights MISO, MOSI, and SCLK pins only,, What pin should I put as "Chip Select" so I can link it with the "Chip Select" pin in the master interface ? \$\endgroup\$ Feb 21, 2022 at 13:52
  • 1
    \$\begingroup\$ Please note that you never asked a specific instance. It is possible your eval board has already reserved nSS pins for other purposes so CubeMX will not let you select a mode with hardware chip select, it would be displayed in red and give a reason why it is unavailable. \$\endgroup\$
    – Justme
    Feb 21, 2022 at 14:06
  • 1
    \$\begingroup\$ @BartvanHeukelom Because the OP has no other SPI devices, that is why OP is interested to use two SPI interfaces on the same MCU, to practice. The OP has previoisly asked same question regarding use of two I2C interfaces on same MCU. It really does not have anything to do with STM32 specifically, you can use as many SPI intefaces any MCU provides. \$\endgroup\$
    – Justme
    Feb 26, 2022 at 12:20
1
\$\begingroup\$

Please have a look at this repo: miniwinwm/BluePillDemo

John Blaiklock, the author, is using CubeIDE and has provided the .ioc files for each project.

BluePillDemo_SPI_IT is a project where two SPI interfaces are configured as master-slave in the same MCU.

\$\endgroup\$
0
\$\begingroup\$

If you want, you can use just a master set in full duplex and feed MOSI to the MISO pin. The data you send out should come back in! Put an inverter (appropriate voltage levels!) in the circuit and the inverse data will come in.

That will demonstrate the master is doing its thing. The slave should be easy then. --- madGambol

\$\endgroup\$

Your Answer

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

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