2011-02-09 02:32:24 +02:00
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
#include <avr/io.h>
|
|
|
|
|
2011-02-10 12:19:55 +02:00
|
|
|
#include "board.h"
|
2011-02-09 02:32:24 +02:00
|
|
|
#include "spi.h"
|
|
|
|
|
|
|
|
|
|
|
|
void spi_begin(void)
|
|
|
|
{
|
|
|
|
CLR(nSS);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
uint8_t spi_io(uint8_t v)
|
|
|
|
{
|
|
|
|
// while (!(UCSR1A & 1 << UDRE1));
|
|
|
|
UDR1 = v;
|
|
|
|
while (!(UCSR1A & 1 << RXC1));
|
|
|
|
return UDR1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void spi_end(void)
|
|
|
|
{
|
|
|
|
// while (!(UCSR1A & 1 << TXC1));
|
|
|
|
SET(nSS);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void spi_init(void)
|
|
|
|
{
|
2011-02-11 01:49:23 +02:00
|
|
|
SET(nSS);
|
2011-02-09 02:32:24 +02:00
|
|
|
OUT(SCLK);
|
|
|
|
OUT(MOSI);
|
|
|
|
OUT(nSS);
|
|
|
|
IN(MISO);
|
|
|
|
|
|
|
|
UBRR1 = 0; /* set bit rate to zero to begin */
|
|
|
|
UCSR1C = 1 << UMSEL11 | 1 << UMSEL10;
|
|
|
|
/* set MSPI, MSB first, SPI data mode 0 */
|
|
|
|
UCSR1B = 1 << RXEN1 | 1 << TXEN1;
|
|
|
|
/* enable receiver and transmitter */
|
|
|
|
UBRR1 = 0; /* reconfirm the bit rate */
|
|
|
|
}
|