//
// SPI in Master mode
// By PEK '2006
//
// Compiler: GCC
// MCU: ATMega48
//

#define F_CPU 1000000

#include <avr/io.h>
#include <util/delay.h>


int main(void)
{	
	// Initiate Ports
	PORTB = 0x00;	// SS low
	DDRB = 0x2C;	// MOSI, SCK and SS as output

	// Initiate SPI
	PRR = ~_BV(PRSPI);	// Enable power to SPI
	SPCR = _BV(SPE) | _BV(MSTR);	// Enable SPI, Master, clk=f/4 etc.
	
	while(1)
	{
		SPDR = 0x55; 	// Send 0x55
		while(!(SPSR & _BV(SPIF)));	// Wait for sending to complete

		_delay_ms(100);
	}
	
	return 1;
}

