pyrorf/spi.c
2019-09-09 01:41:42 +02:00

20 lines
319 B
C

#include "spi.h"
#include <util/delay.h>
void spi_init_master() {
SPI_PORT |= _BV(SCK_PIN);
SPI_DDR |= _BV(MOSI_PIN) | _BV(SCK_PIN) | _BV(SS_PIN);
SPCR = _BV(SPE) | _BV(MSTR) | _BV(SPR1)| _BV(SPR0);
}
uint8_t spi_transfer(uint8_t b) {
SPDR = b;
while (!(SPSR & _BV(SPIF)));
return SPDR;
}