1
0
mirror of synced 2024-11-22 01:04:24 +01:00
avr_demo/tpic6b595_spi/spi.c
2011-11-20 19:11:58 +02:00

27 lines
521 B
C

/*
* spi.c
*
* Copyright 2011 Mika Tuupola
*
* Licensed under the MIT license:
* http://www.opensource.org/licenses/mit-license.php
*
*/
#include "digital.h"
#include "spi.h"
void spi_init(void) {
pin_mode(SPI_SCK, OUTPUT);
pin_mode(SPI_MOSI, OUTPUT);
pin_mode(SPI_SS, OUTPUT); /* Must be output in Master mode. */
spi_set_msb();
spi_set_master();
spi_enable();
}
uint8_t spi_transfer(volatile uint8_t data) {
SPDR = data;
loop_until_bit_is_set(SPSR, SPIF);
return SPDR;
}