Spi H

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

/*

* CommunicationSPI.h
*
* Created: 19/08/2015 17:04:21
* Author: FARAON
*/
//SPI pins
#define SPI_PORT PORTB
#define DDR_SCK
PB5
#define DDR_MISO PB4
#define DDR_MOSI PB3
#define DDR_SS
PB0
#define DDR_SPI
DDRB
//SPI Data Modes
#define SPI_MODE0 0x00
#define SPI_MODE1 0x04
#define SPI_MODE2 0x08
#define SPI_MODE3 0x0C
#define SPI_MODE_MASK
0x0C // CPOL = bit 3, CPHA = bit 2 on SPCR
#define SPI_CLOCK_MASK
0x03 // SPR1 = bit 1, SPR0 = bit 0 on SPCR
#define SPI_2XCLOCK_MASK 0x01 // SPI2X = bit 0 on SPSR
//Commands control SPI
#define SS_LOW
PORTB&=~(1<<PB2)
#define SS_HIGH
PORTB|=(1<<PB2)
//SPI Modes
#define SPI_MASTER 0x00
#define SPI_SLAVE 0x01
#include <avr/io.h>
#include <stdint.h>
void spi_init(uint8_t spiMode);
char spi_transferc(unsigned char c);
int8_t spi_transfern(int8_t n);

spi.h.txt[22/08/2016 22:28:25]

You might also like