Confused about SPI

Everything I read about SPI references 4 signals: MOSI, MISO, SCLK, and CS. The libraries I am using have two parameters for SPI devices: Interrupt and CS. How do I translate the 4 signals into those two parameters?
Reference:

SPI complete .... is not CAN.

For most Arduino boards the pins used for MOSI, MISO, SCLK are pre-defined by the Arduino framework and are specific to the particular model of board you are using. Checkout the board documentation to see where the SPI pins appear. You don't need to tell the device library what MOSI, MISO, SCLK pin numbers are being used, however you do need to specify the CS.

1 Like

As mikb55 said, MOSI, MISO, and SCK usually have fixed locations due to hardware. CS maps to CS, and Interrupt is probably an extra pin that allows the slave to say "I may be a slave, but I have something you need to talk to me about."

1 Like

assuming you're using a MCP2515 for your CAN communication SPI is used as the communication media between your arduino and the MCP2515 chip, see the link below.

hope that helps...

As the others have said, MOSI, MISO, & SCLK are usually fixed by the hardware - so don't need to be configured.

But note that not everything uses all four:

  • If there's only 1 slave on the bus, CS may not be needed;
  • If the slave is write-only, MISO is not needed;
  • If the slave is read-only, MOSI is not needed.
2 Likes

Thanks, everyone. These explanations make a lot of sense.

1 Like

I case anyone searches this topic in the future, what I've found is that in addition to most development boards having fixed, specific pins for MOSI and MISO, many libraries define these pins in a header file somewhere, and sometimes don't use #define MOSI (or #define MISO). So you might have to do some poking around, but if your library is well written, and it makes assumptions about those pins, they will be dependent on the hardware type and will most likely be correct.
One of the first things I do in setup() when I'm trying a new board or module is:
Serial.print("MOSI:"); Serial.println(MOSI);
...
That way you know immediately if they've been defined using the conventional names.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.