Hardware Reference
In-Depth Information
Table 10-2. Clock Divider Settings with Resulting Speed
Command
Divide By
End Clock Speed
SPI_CLOCK_DIV2
2
8MHz
SPI_CLOCK_DIV4
4
4MHz
SPI_CLOCK_DIV8
8
2MHz
SPI_CLOCK_DIV16
16
1MHz
SPI_CLOCK_DIV32
32
500kHz
SPI_CLOCK_DIV64
64
250kHz
SPI_CLOCK_DIV128
128
125kHz
the atmel data sheet states that a minimum clock divider of 4 should be used. significant transmission
errors occur when attempting to communicate at 8Mhz.
Caution
SPI.setDataMode() : This determines how the clock is configured and read. The data lines are
sampled in relation to the clock cycle. This setting is similar to serial baud rate, and all devices
must be set the same for communication to take place. Table 10-3 shows the data modes and
when data is sampled in relation to the clock polarity. When mode0 is used, the clock will idle low,
and data will be sampled when the clock rises. Mode1 shares the same clock polarity as mode0,
with the sample happening when the clock falls to the idle state. Mode2 and mode3 mirror mode0
and mode1, but with the clock set to high when idle. Mode2 samples the data when the clock falls
and mode3 samples when the clock goes high. The default for the Arduino is mode0.
Table 10-3. SPI Data Transmission Modes
Command
Mode
Sample on Clock Edge
Clock Polarity When Idle
SPI_MODE0
0
Leading
Low
SPI_MODE1
1
Trailing
Low
SPI_MODE2
2
Leading
High
SPI_MODE3
3
Trailing
High
since the spi clock will remain idle for a majority of the time, even when transmitting, you should use mode0 or
mode1 if possible in power-conscious designs.
Note
SPI.transfer() : Calling this function and passing data will both send and receive 1 byte
over the SPI lines. This function will return the incoming byte from the active slave. This is a
full-duplex transfer; as one bit shifts out of the master, it is received by the slave, and the slave
simultaneously sends a bit to the master.
 
 
Search WWH ::




Custom Search