diff options
Diffstat (limited to 'software/hhd70dongle/spi.c')
-rw-r--r-- | software/hhd70dongle/spi.c | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/software/hhd70dongle/spi.c b/software/hhd70dongle/spi.c index 0732716..0ffa1b9 100644 --- a/software/hhd70dongle/spi.c +++ b/software/hhd70dongle/spi.c @@ -29,19 +29,42 @@ * along with mur.sat. If not, see <http://www.gnu.org/licenses/>. * */ +#include "avr/io.h" + #include "spi.h" +#define SPI_DDR DDRB +#define SPI_PORT PORTB +#define SPI_PIN PINB +#define CS 0 +#define SCK 1 +#define MOSI 2 +#define MISO 3 +#define GDO2 4 +#define GDO0 5 +#define RE 6 +#define TE 7 + void spi_init(void) { - + SPI_PORT = 0; + SPI_DDR = (1<<MOSI)|(1<<SCK)|(1<<CS); + SPCR = (1<<SPE)|(1<<MSTR); +// SPSR = (1<<SPI2X); (4MHz vs. 8MHz) } void spi_write(char address, char* data, int len) { - } void spi_read(char address, char* data, int* len) { + PORTB |= (1<<CS); + + while(SPI_PIN & (1<<MISO)); /* wait for CC1101 to get ready... */ + + SPDR = 0x80; + while(!(SPSR & (1<<SPIF))); + PORTB &= ~(1<<CS); } |