beginSPI()
[Serial Peripheral Interface]
void beginSPI(unsigned short clock,
unsigned short dataIn,
unsigned short dataOut,
unsigned short chip_select = 32768,
bool polarity = false);Description
Initializes the SPI communication.
To use the SPI peripheral as follower, the chip_select
and polarity parameters must be specified.
Parameters
clock: the pin for the clock.
data_in: the pin for the data in.
data_out: the pin for the data out.
chip_select: the pin for the chip select. This
parameter is optional and only necessary if the chip is acting as a
follower.
polarity: the chip select polarity. This parameter
is optional and only necessary if the chip is acting as a
follower.
Returns
Nothing.
Example Code
For a Leader Device
The code initializes the SPI communication with the clock pin connected to pin 13, the data in pin connected to pin 12, and the data out pin connected to pin 11.
void setup() {
beginSPI(13, 12, 11); // initializes the SPI communication with the clock pin connected to pin 13, the data in pin connected to pin 12, and the data out pin connected to pin 11
}
void loop() {
}For a Follower Device
The code initializes the SPI communication with the clock pin connected to pin 13, the data in pin connected to pin 12, the data out pin connected to pin 11, the chip select pin connected to pin 10, and the polarity of the chip select line set to LOW.
void setup() {
beginSPI(13, 12, 11, 10, LOW); // initializes the SPI communication with the clock pin connected to pin 13, the data in pin connected to pin 12, the data out pin connected to pin 11, the chip select pin connected to pin 10, and the polarity of the chip select line set to LOW
}
void loop() {
}Notes and Warnings
- Any pin can be used for the clock, data in, data out, and chip select lines, except for the ground and power pins.
- This function will take of all the pins specified, and configure them as needed, please, do not change the configuration of the pins after calling this function.
