Hardware Reference
In-Depth Information
CPOL is short for Clock Polarity and tells the device if the clock is active on
a logical 1 or a logical 0. CPHA is short for Clock Phase and tells the device if
data should be captured on a rising edge (going from 0 to 1) or a falling edge
(going from 1 to 0).
Finally, the clock divider function, setClockDivider() , is used to set the
clock frequency in relation to the system clock.
SPI.setClockDivider(divider);
For AVR-based systems like the Arduino Uno, the divider parameter is a
numerical value: 2, 4, 8, 16, 32, 64, or 128. These values are available as constants:
SPI_CLOCK_DIV2
SPI_CLOCK_DIV4
SPI_CLOCK_DIV8
SPI_CLOCK_DIV16
SPI_CLOCK_DIV32
SPI_CLOCK_DIV64
SPI_CLOCK_DIV128
By default, AVR systems using a system clock of 16 MHz use a divider of 4,
SPI_CLOCK_DIV4 , resulting in an SPI bus frequency of 4 MHz.
NOTE The Arduino Due has more advanced SPI features that are explained in the
section “SPI on the Arduino Due.”
To send and receive data on the SPI bus, use transfer() .
result = SPI.transfer(val);
This function takes a byte as a parameter, the byte to send on the SPI bus. It
returns a byte, the byte of data received on the SPI bus. transfer() sends and
receives only a single byte per call; to receive more data, call this function as
many times as needed.
SPI on the Arduino Due
The Arduino Due is not an AVR device but uses Atmel's SAM3X8E: a micro-
controller based on ARM's Cortex-ME design. It is a more powerful device and
has advanced SPI functionality.
The SPI library is almost the same on AVR devices and ARM-powered devices,
but changes slightly. When calling an SPI function, you must also add the SS
pin that will be used.
 
Search WWH ::




Custom Search