User Manual

12. Orangutan SPI Master Functions
This section of the library provides commands for using the AVR’s Serial Peripheral Interface (SPI) module in
master mode to communicate with slave SPI devices.
SPI is a synchronous communication protocol where the basic transaction consists of the master pulsing the SPI
clock (SCK) line 8 times while bits are simultaneously exchanged between the (selected) slave and the master on
the Master-in/Slave-out (MISO) and Master-out/Slave-in (MOSI) lines. There is no way for the master to send a
byte without receiving one, and there is no way for the master to receive a byte without sending one.
The functions in this section will automatically configure the MOSI and SCK lines as outputs and the MISO line
as an input.
The AVR’s SPI module is designed so that if the SS pin is an input and it reads low (0 V), then the SPI module
will automatically go in to slave mode (the MSTR bit in SPCR will become zero) and all SPI transmission
functions in this library will return a result of zero. Therefore, it is recommended to make SS an output before
doing SPI master communication. If SS is an input, then the SPI initialization routine in this library will enable
the pull-up resistor on that line.
The Orangutan LV, Orangutan SV, Baby Orangutan, and 3pi robot are based on the ATmega48/168/328 line of
AVR processors, so SS is pin PB2, MOSI is PB3, MISO is PB4, and SCK is PB5.
The Orangutan SVP and Orangutan X2 are based on the AVR ATmega324/644/1284 line of AVR processors,
so SS is pin PB4, MOSI is PB5, MISO is PB6, and SCK is PB7. The Orangutan SVP and X2 are both
aided by auxiliary microcontrollers that are slave SPI peripherals. The functions in this class are used by the
OrangutanSVP (see Section 13) and OrangutanX2 (see Section 15) classes to communicate with these auxiliary
microcontrollers.
Pololu AVR Library Command Reference © 2001–2015 Pololu Corporation
12. Orangutan SPI Master Functions Page 45 of 65