You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
780 B

// SD Controller for Computer "Specialst"
// (c) 26-05-2013 vinxru (aleksey.f.morozov@gmail.com)
// Based on sources CC Dharmani, Chennai (India)
// 1 May 2013 vinxru
#ifndef F_CPU
#define F_CPU 16000000ULL
#endif
#include "spi.h"
#include <util/delay.h>
#include <avr/io.h>
#ifndef SPI2X
#define SPI2X 0
#endif
void spi_init(void)
{
DDRB = 0xF7; //
PORTB = 0xF7; //
SPCR = 0x52; // setup SPI: Master mode, MSB first, SCK phase low, SCK idle low
SPSR = 0x00;
}
uint8_t spi_transmit(uint8_t data)
{
SPDR = data;
while(!(SPSR & 0x80)); // Wait for transmission complete
return SPDR;
}
uint8_t spi_receive()
{
SPDR = 0xFF;
while(!(SPSR & 0x80)); // Wait for reception complete
return SPDR;
}
void spi_highSpeed()
{
SPCR = 0x50;
SPSR |= (1<<SPI2X);
_delay_ms(1);
}