SPI on the PHOTON, Confused

I am working with the SPI on the Photon.
The details of the pins are shown here.

Where is gets confusing, is when i look at the doc pages here to set it up
https://docs.particle.io/reference/firmware/core/#spi

They show “SPI.begin(ss);” Now with the scope I see that this is using SPI1, yet when I try SPI1.begin(ss), it comes out on SPI3 pins. This is confusing, it should be SPI1.begin & SPI3.begin or am I missing something.

SPI3 is the physical hardware label on the STM32F205 microcontroller.

You should look at: https://docs.particle.io/reference/firmware/photon/#spi for Photon since you are at the Core firmware reference.

Take note that most libraries will set the SS or it will default to A2 as mentioned in the documentation. SPI3_SS is for the STM32F205 label as well so ignore it since Chip Select pins can be assigned to any GPIO

  • SPI.begin() will use Pins A5-A3 (excluding SS)
  • SPI1.begin() will use Pins D5-D3 (excluding SS)
1 Like

If you bring up both of those web pages side by side makes it even more strange as they are both 100% the same. Same photo of the “core” withe the only difference being an addition for hte photon for SPI.transfer.
It does not mention what pins are used for SPI, and it does not even mention that you can use SPI1, and what pins that would use.

https://docs.particle.io/reference/firmware/core/#spi
https://docs.particle.io/reference/firmware/photon/#spi

Actually this is not quite true

When you look at the photo (despite being a photo of a white Core in both versions) the SPI pins are clearly to be seen (and the same on both devices).
And here you'll find even the written pin mapping for the Core
https://docs.particle.io/datasheets/core-datasheet/#spi
The hardware pin mapping for the Photon is a bit more complicated, but you've seen the table (as you posted a pic of it ;-))
An indirect reference to the Photon pins can be found here (the doc search function does help finding things)
https://docs.particle.io/datasheets/photon-shields/#shield-shield-pin-mapping

And AFAIK there is no direct mentioning of the SPI1 object (which refers to the hardware SPI3 interface of the Photon chip STM32F205 - and is not available on the Core).

I agree tho', that it's not explicitly stated - and can be confusing - that the software object SPI refers to the the hardware interface SPI1 on the Core the Photon and the software object SPI1 referst to the hardware interface SPI3 on the Photon and doesn't exist on the Core (due to non-accessible SPI2 GPIO_B pins 12..15).
But this naming scheme comes form the endevour to keep close to the Arduino naming where possible and useful.
The knowledge about which hardware interface is actually referenced is not required for programming the thing, but if you need to know (e.g. for close to hardware tweaking), you'd definetly be used to the fact that hardware and software representation don't have to line up all the time and how to get around it :sunglasses:

But absolutely agreed: This could and should definetly be stated more clearly in the firmware as in the hardware docs.

Thanks for the help guys. however I must admit that the site needs a good going through and cleanup.
when one wants to simply use SPI they should not have to hit 4-5 different pages to merge together information how and what pins to use.
The first link here should have everything one would need to know about it and show both SPI set of pins on a newer photon photo. So at least one looking at the docs could see that you have 2 options and not just one.
https://docs.particle.io/reference/firmware/photon/#spi

Matters get worse when the above page does not mention there are 2 SPI’s that one can use. So when you hit the photos page give in my first post confuses people because they are labeled SPI1 & SPI3, yet the calls do not use that

I dont mean to sound like a jerk, but when I spend a long time trying to get something simple going, it aggravating when the docs page is not clear and decisive.

Reading this thread inspired me to work on an update to the docs (for which I will put in a pull request soon). However, while researching some details, I have a question regarding the default SS pins.

Looking through the firmware source (I checked both the ‘latest’ and ‘develop’ branches), I can see that there is an alias for SS defined in the pinmap, mapping to physical pin 12, AKA A2. That’s fine for the standard SPI object.

But, for the SPI1 firmware object, which maps to SPI3 hardware interface (yeah, that’s slightly confusing), the pinout image above would lead one to believe that it would default to pin D5 for its slave-select. But it doesn’t – it still uses the default SS symbol (pin A2). And there are also no other defines in the pinmap for the SPI3 pins.

I’m thinking that we need to add some additional entries to hal/inc/pinmap_hal.h for the second SPI interface. And also, make SPI1.begin() default to pin D5. I’m pretty sure there must be a way to do that, but my C++ fu isn’t that strong. My best guess is that the solution would involve wiring_globals/src/wiring_globals_spi.cpp, wiring/inc/spark_wiring_spi.h, and wiring/src/spark_wiring_spi.cpp.

attn: @mdma, @Dave, @BDub?

4 Likes

This is a great suggestion, and I’m sorry it was overlooked! We’ll add it to the next firmware release 0.4.6.

4 Likes