This class is used for creating objects to manage the Maple’s built-in SPI ports. The Maple has two SPI ports. The relevant pins corresponding to each port’s logic signals are documented in the following table (and on the Maple silkscreen):
Port number | NSS | MOSI | MISO | SCK |
---|---|---|---|---|
1 | 10 | 11 | 12 | 13 |
2 | 31 | 32 | 33 | 34 |
If you use a SPI port, you cannot simultaneously use its associated pins for other purposes.
You can declare that you want to use SPI in your sketch by putting HardwareSPI Spi(number); with your variables, where number is 1 or 2, depending on which SPI you want to use. Then you can use the functions described in the next section. For example:
// Use SPI 1
HardwareSpi Spi(1);
void setup() {
Spi.begin(SPI_18MHZ);
}
void loop() {
// Get the next byte from the peripheral
uint8 byte = Spi.recv();
}
Class for interacting with SPI.
Construct an object for managing a SPI peripheral. spi_num must be 1 or 2; see the table above for pinout information.
Configure the baudrate of the given SPI port and set up the header pins appropriately.
Parameters:
freq: one of the SPIFrequency values, given below.
endianness: either LSBFIRST (little-endian) or MSBFIRST (big-endian).
mode: one of 0, 1, 2, or 3, and specifies which SPI mode is used. The mode number determines a combination of polarity and phase according to the following table:
Mode |
Polarity |
Phase |
---|---|---|
0 |
0 |
0 |
1 |
0 |
1 |
2 |
1 |
0 |
3 |
1 |
1 |
For more information on polarity and phase, see the external references, below.
Writes data into the port buffer to be transmitted as soon as possible, where length is the number of bytes to send from data. Returns the last byte shifted back from slave.
The possible SPI speeds are configured using the SPIFrequency enum:
HardwareSPI definitions.
Defines the possible SPI communication speeds.
Values:
18 MHz
9 MHz
4.5 MHz
2.25 MHZ
1.125 MHz
562.500 KHz
281.250 KHz
140.625 KHz
The number of SPI frequencies.