Reference Language | Libraries | Comparison | Changes
These APIs should not be used in new projects. Use SPISettings with SPI.beginTransaction() to configure SPI parameters.
On the Arduino Due, the SAM3X has advanced SPI capabilities. It is possible to use these extended methods, or the AVR-based ones.
The extended API can use pins 4, 10, and 52 for CS.
You must specify each pin you wish to use as CS for the SPI devices.
It is possible for the Due to automatically handle the chip selection between multiple devices sharing the SPI bus. Each device may have also different attribues such as speed and datamode.
If using multiple devices with different CS pins, you'll need to declare those pins in setup(). In the following example, there are two devices that share the SPI MISO, MOSI, and SCK pins. One device CS is attached to pin 4, the other to pin 10.
Once a pin has been declared as a CS pin, it's possible to change its default behaviors as well. For example, if the devices run at different clock speeds, the setup() may look like this :
A single byte transfer to a device on pin 4 could look like this :
It's possible to send more than one byte in a transaction by telling the the transfer command to not deselect the SPI device after the transfer :
See the individual reference pages for setClockDivider(), setDataMode(), transfer(), setBitOrder() for proper syntax when using the extended methods.
NB : once SPI.begin() is called, the declared pin will not be available as a general purpose I/O pin
Reference Home
Corrections, suggestions, and new documentation should be posted to the Forum.
The text of the Arduino reference is licensed under a Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain.