2
\$\begingroup\$

I'm using a RP2040 for a personal project. I'm already using the SPI0 with GPIO 3 to 6, and SPI1 with GPIO 11 to 14. Is it possible to use the SPI0 with GPIO 16 to 19 at the same time with another device?

I'm asking this question because I feel like it can be possible if many GPIO have SPI0 and SPI1, but I don't how it can work if both devices are using SPI0 at the same time.

I worked a lot in the past on the CAN and I²C bus but I'm new with SPI so I'm sorry if my knowledge of this bus communication is not that great.

Thanks for answers

enter image description here

\$\endgroup\$
3
  • 4
    \$\begingroup\$ If I'm not reading the pin functions table wrong you can't use SPI0 with GPIO7~10 because only GPIO7 can be configured as a part of SPI0, the rest's alternate functions are SPI1-related, apparently. And if I understood your question correctly, you can't get SPI0 functionality from both of, say, GPIO0~3 and GPIO4~7. I don't know the architecture but as far as I know from other MCUs there's only one SPI0 module and the I/Os are directed to the pins via MUXes. This means that only one group (e.g. GPIO0~3) can be connected to SPI0 module at a time and the rest can't be used for SPI0 functionality. \$\endgroup\$ Aug 17, 2023 at 10:10
  • \$\begingroup\$ @RohatKılıç Of course my bad for the example, I wanted to say an example for GPIO7-10 but I guess I was tired. Thanks for your answer, that's what I wanted to know. \$\endgroup\$
    – Bouboubi
    Aug 17, 2023 at 12:20
  • \$\begingroup\$ @RohatKılıç I've edited my question in order to remove more confusion \$\endgroup\$
    – Bouboubi
    Aug 17, 2023 at 12:27

1 Answer 1

3
\$\begingroup\$

Most SPI slave devices have a chip select line that, when inactive, cause them to ignore the MOSI/MISO lines. This feature allows you to connect multiple SPI slaves to the same SPI bus. The SPI master simply activates the appropriate chip select line to perform a transaction with a given SPI slave.

Edit: Just reread your question, and my answer, while potentially a possible solution for you, doesn't seem to answer your fundamental question. Many microcontrollers will map a given peripheral (such as SPI0) to multiple pins for maximum design flexibility, but they do not duplicate the peripheral devices. So basically, you cannot use SPI0 on two different set of pins. See the beginning of my answer about how to use multiple slave devices on a single SPI peripheral.

\$\endgroup\$
3
  • 1
    \$\begingroup\$ +1 This is a good answer. There is just one thing the OP might be missing. Instead of letting the SPI0 peripheral drive the CSn signals, they have to be driven manually. \$\endgroup\$
    – Velvet
    Aug 17, 2023 at 14:18
  • \$\begingroup\$ @Velvel So if I resume, I can use two differents devices on my SPI0, but I have to choose one of them with my Chip Select when I want to communicate with it, and not both at the same time \$\endgroup\$
    – Bouboubi
    Aug 17, 2023 at 14:22
  • \$\begingroup\$ @bouboubi That is correct. You can either use the SPI0 CSn lines and have SPI0 drive the chip selects, or you can use GPIOs and manually drive them. Whichever works better for you. \$\endgroup\$ Aug 17, 2023 at 14:28

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.