Basic Library
Digital I/O
Analog I/O
Advanced I/O
Time
Math
Trigonometry
Random Numbers
Bits and Bytes
Interrupts
Serial Comm.
Standard Library
Ethernet
Servo Motor
Stepping Motor
Character LCD
SPI
I2C (Wire)
SD Card
SD (File Operations)
Periodic Operation
Clock (RTC)
PPG (Pulse Generator)
WiFiEsp
ICS (Serial Servo)
FreeRTOS Tips
SPI
This library provides SPI communications, enabling communications with two or more microcontrollers, with the GR-ROSE board as the master device. To use this library, specify #include <spi.h>
.
SPISettings
- Description
- Each SPI device can be configured once as an SPISettings object.
- Syntax
- SPISettings mySetting(speed, dataOrder, datamode)
- Parameters
- speed: The speed of the communication
dataOrder: MSBFIRST or LSBFIRST
dataMode: SPI_MODE0, SPI_MODE1, SPI_MODE2, or SPI_MODE3 - Returns
- None
begin
- Description
- Initializes the SPI bus by setting SCK, MOSI low and SS to outputs, pulling SCK and MOSI low, and SS high.
- Syntax
- SPI.begin()
- Parameters
- None
- Returns
- None
end
- Description
- Disables the SPI bus, and returns the pin to a general I/O port.
- Syntax
- SPI.end()
- Parameters
- None
- Returns
- None
beginTransaction()
- Description
- Initializes the SPI bus using the defined SPISettings.
- Syntax
- SPI.beginTransaction(mySettings)
- Parameters
- mySettings: The chosen settings according to SPISettings
- Returns
- None
endTransaction()
- Description
- Stop using the SPI bus. Normally, this is called after de-asserting the chip select, to allow other libraries to use the SPI bus.
- Syntax
- SPI.endTransaction()
- Parameters
- None
- Returns
- None
setBitOrder
- Description
- Sets the order of the bits shifted out of and into the SPI bus.
- Syntax
- SPI.setBitOrder(bitOrder)
- Parameters
- bitOrder: Bit order, either LSBFIRST or MSBFIRST. Default is MSBFIRST
- Returns
- None
setClockDivider
- Description
- Sets the SPI clock divider relative to the system clock.
- Syntax
- SPI.setClockDivider(divider)
- Parameters
- divider: Set one of the following:
SPI_CLOCK_DIV: 30MHz
SPI_CLOCK_DIV4: 15MHz
SPI_CLOCK_DIV6: 10MHz
SPI_CLOCK_DIV8: 7.5MHz
SPI_CLOCK_DIV10: 6MHz
SPI_CLOCK_DIV12: 5MHz
SPI_CLOCK_DIV14: 4.3MHz
SPI_CLOCK_DIV16: 3.75MHz(default)
SPI_CLOCK_DIV20: 3MHz
SPI_CLOCK_DIV30: 2MHz
SPI_CLOCK_DIV60: 1MHz - Returns
- None
setDataMode
- Description
- Sets the SPI data mode: That is, clock polarity and phase.
- Syntax
- SPI.setDataMode(mode)
- Parameters
- mode: Set one of the following. Default is Mode 0. SDMMC is not available in Modes 2 and 3.
SPI_MODE0: Clock is low during idling, samples data at rising edge
SPI_MODE1: Clock is low during idling, samples data at falling edge
SPI_MODE2: Clock is high during idling, samples data at rising edge
SPI_MODE3: Clock is high during idling, samples data at falling edge - Returns
- None
transfer
- Description
- Transfers one byte over the SPI bus, both sending and receiving.
- Syntax
- SPI.transfer(value)
- Parameters
- value: A byte of data
- Returns
- The byte read from the bus.
Sample Program
#include <Arduino.h>
#include <SPI.h>
void setup(){
SPI.begin();
}
void loop(){
//write
SPI.transfer(0x55);
//read
uint8_t data = SPI.transfer(0xff);
}