Program to use the SPI in slave mode
#include
main()
{
char s[6];
int i;
/****************************************************************
* SPI Setup
*****************************************************************/
DDRS = DDRS | 0x10; /* MISO output */
SP0CR1 = 0x40; /* 0 1 0 0 0 0 0 0
| | | | | | | |
| | | | | | | \____ MSB first
| | | | | | \______ multiple bytes with SS asserted
| | | | | \________ 0 phase
| | | | \__________ 0 polarity
| | | \____________ Slave mode
| | \______________ not open drain
| \________________ Enable SPI
\__________________ No interrupts
*/
SP0CR2 = 0; /* Normal (not bi-directional) mode */
/****************************************************************
* End of SPI Setup
*****************************************************************/
i = 0;
while ((SP0SR & 0x80) == 0) ; /* Wait for transfer to finish */
s[i] = SP0DR; /* Read data from master */
i = i + 1;
while ((SP0SR & 0x80) == 0) ; /* Wait for transfer to finish */
s[i] = SP0DR; /* Read data from master */
i = i + 1;
while ((SP0SR & 0x80) == 0) ; /* Wait for transfer to finish */
s[i] = SP0DR; /* Read data from master */
i = i + 1;
while ((SP0SR & 0x80) == 0) ; /* Wait for transfer to finish */
s[i] = SP0DR; /* Read data from master */
i = i + 1;
while ((SP0SR & 0x80) == 0) ; /* Wait for transfer to finish */
s[i] = SP0DR; /* Read data from master */
i = i + 1;
s[i] = '\0'; /* Terminate string */
DBug12FNP->printf("%s\n",s);
}