//
// SPI Slave Example
// By PEK '2006
//
// Compiler: GCC
// MCU: ATTiny26
// Clock: 1 MHz
//

#define F_CPU 1000000

#include <avr/io.h>

// Main
int main(void)
{
	uint8_t uOut = 0x55;	// Byte to send
	uint8_t uIn;	// Byte to receive

	// Setup Ports
	PORTB = 0x00;
	DDRB = _BV(PB1);	// MISO as output

	// Setup SPI
	USICR = _BV(USIWM0) | _BV(USICS1);	// SPI-mode, external clock on positive edge

	while(1)
	{
		USIDR = uOut;	// Set byte to send
		while(!(USISR & _BV(USIOIF)));	// Wait for transmission
		uIn = USIDR;	// Copy received byte
		USISR = _BV(USIOIF);	// Clear interrupt flag

		uOut = ~uIn;	// Next byte to send
	}

	return 1;
}


