1
0
mirror of synced 2024-11-24 10:14:25 +01:00
avr_demo/tpic6b595_spi/spi/spi.c

27 lines
531 B
C
Raw Normal View History

2011-11-20 18:11:58 +01:00
/*
* spi.c
*
* Copyright 2011 Mika Tuupola
*
* Licensed under the MIT license:
* http://www.opensource.org/licenses/mit-license.php
*
*/
2011-12-17 18:08:52 +01:00
#include "pins/digital.h"
#include "spi/spi.h"
2011-11-20 18:11:58 +01:00
void spi_init(void) {
2011-12-17 18:08:52 +01:00
pin_mode(SPI_SCLK, OUTPUT);
2011-11-20 18:11:58 +01:00
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;
}