# Maple Reference Documentation: SPI

- Function Reference
- Recommended Reading

The Maple has two SPI ports. The first has NSS on D10, MOSI on D11, MISO on D12, and SCK on D13. The second has NSS on D31, SCK on D32, MISO on D33, and MOSI on D34.

Each port can be configured at one of the following speeds:

`
- SPI_18MHZ
- SPI_9MHZ
- SPI_4_5MHZ
- SPI_2_25MHZ
- SPI_1_125MHZ
- SPI_562_500KHZ
- SPI_281_250KHZ
- SPI_140_625KHZ
`

## Funtion Reference

`HardwareSPI Spi(number)`
  This declaration must be included at the start of any sketch or program that uses the SPI interface. The argument `number` is either 1 or 2 and specifies which port to use.
`Spi.begin(freq, endianness, mode)`
`Spi.begin()`
  `begin()` is usually called in `setup()` to configure the baudrate of the given SPI port and to set up the header pins appropriately. `freq` is one of the set listed above; `endianness` is either `LSBFIRST` or `MSBFIRST`; `mode` is one of {0,1,2,3} and specifies which "SPI Mode" is used (see specification docs linked below).
  A default constructor with no arguments is provided for the lazy and has the arguments `(SPI_1_125MHZ, MSBFIRST, 0)`.
`Spi.send(data, size()`
  Writes data into the port buffer to be transmitted as soon as possible. `data` should be an array of type `byte`; `size` should be the result of `sizeof(data)`.

## Recommended Reading

- Wikipedia Article on Serial Peripheral Interface Bus (SPI)
- Arduino reference on SPI
- Hardcore SPI on Arduino by kik64
- STMicro documentation for STM32F103RB microcontroller:
  - All
  - Datasheet (pdf)
  - Reference Manual (pdf)

### About this Document

A more recent version of this document may be available from the LeafLabs website. Our documentation is versioned on github; you can track changes to the master branch at this link.

This documentation is released under a Creative Commons Attribution-Share Alike 3.0 license.

Translations are welcomed; give us a ping to make sure we aren't in the process of revising or editing first.