WebbotLib AVR library
WebbotLib It just does it
  C++ documentation  C documentation

spiUart.h

Allows you to simulate an SPI interface using a hardware UART that provides this ability.
This is useful when your hardware doesn't provide hardware SPI or if you want additional SPI interfaces.
Note that the hardware only supports master mode.
The ATMega8 and ATMega32 DO NOT provide this ability whereas the ATMega168, ATMega328P, ATMega640, ATMega2560 and ATMega2561 DO.
The transmit output of the UART corresponds to MOSI pin, the receive input of the UART corresponds to the MISO pin. The SCLK clock output comes from the XCK pin of the relevant UART.
To define UART2 to be used as an SPI master then:-
#include "spiUart.h"
SPI_UART spi = MAKE_UART_SPI(device_list, UART2);
Checking the datasheet for the ATMega640, or look at 'dev/ATMega640.h' in this library, then you will see that the clock pin for UART2 (XCK2) is on H2.
Once defined you can use the same functions as described in spi.h.

Valid XHTML 1.0 Transitional