void SPI_SlaveInit(void)
{
DDRB |= (1<<PORTB4);//Set MISO to output
SPCR = (1<<SPE);
}
char SPI_SlaveReceive(void)
{
char data;
while(!(SPSR & (1<<SPIF)))
{}
data = SPDR;
SPDR = 0;
return data;
}
void SPI_SlaveSend(char data)
{
SPDR = data;
while(!(SPSR & (1<<SPIF)))
{}
SPDR = 0;
}
A collection of my projects in the areas of physics, electronics and information science.
AdSense
Sunday, 26 May 2013
ATMega - Hardware SPI
(Deutsche Version) SPI communication can be very useful (e.g. to expand an Raspberry PI with ATMegas). To use the built in SPI Interface of an ATMega8, I hardly found any information. Here is the code which I finally found after a long time of researching:
Labels:
ATMega
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment