Changeset - 469487d2238c
[Not reviewed]
default
0 1 0
kripperger@CL-SEC241-09.cedarville.edu - 13 years ago 2012-11-09 17:01:46
kripperger@CL-SEC241-09.cedarville.edu
spi work
1 file changed with 1 insertions and 1 deletions:
0 comments (0 inline, 0 general)
slave/slave/lib/spi.h
Show inline comments
 
/* 
 
 *
 
 *
 
 *
 
 *
 
 *
 
 */
 

	
 

	
 
#ifndef SPI_H_
 
#define SPI_H_
 

	
 
#include <avr/io.h>
 

	
 

	
 
#define SPI_SS_PIN PORTB4
 
#define SPI_SS_PIN PORTB4		//DEBUG //THIS IS WRONG FOR NOW...
 
#define SPI_SCK_PIN PORTB7
 
#define SPI_MOSI_PIN PORTB5
 
#define SPI_MISO_PIN PORTB6
 

	
 

	
 
// SPI clock modes
 
#define SPI_MODE_0 0x00 /* Sample (Rising) Setup (Falling) CPOL=0, CPHA=0 */
 
#define SPI_MODE_1 0x01 /* Setup (Rising) Sample (Falling) CPOL=0, CPHA=1 */
 
#define SPI_MODE_2 0x02 /* Sample (Falling) Setup (Rising) CPOL=1, CPHA=0 */
 
#define SPI_MODE_3 0x03 /* Setup (Falling) Sample (Rising) CPOL=1, CPHA=1 */
 

	
 
// data direction
 
#define SPI_LSB 1 /* send least significant bit (bit 0) first */
 
#define SPI_MSB 0 /* send most significant bit (bit 7) first */
 

	
 
// whether to raise interrupt when data received (SPIF bit received)
 
#define SPI_NO_INTERRUPT 0
 
#define SPI_INTERRUPT 1
 

	
 
// slave or master with clock diviser
 
#define SPI_SLAVE 0xF0
 
#define SPI_MSTR_CLK4 0x00 /* chip clock/4 */
 
#define SPI_MSTR_CLK16 0x01 /* chip clock/16 */
 
#define SPI_MSTR_CLK64 0x02 /* chip clock/64 */
 
#define SPI_MSTR_CLK128 0x03 /* chip clock/128 */
 
#define SPI_MSTR_CLK2 0x04 /* chip clock/2 */
 
#define SPI_MSTR_CLK8 0x05 /* chip clock/8 */
 
#define SPI_MSTR_CLK32 0x06 /* chip clock/32 */
 

	
 

	
 

	
 
// setup spi
 
void setup_spi(uint8_t mode,   // timing mode SPI_MODE[0-4]
 
	       int dord,             // data direction SPI_LSB|SPI_MSB
 
	       int interrupt,        // whether to raise interrupt on recieve
 
	       uint8_t clock); // clock diviser
 

	
 
// disable spi
 
void disable_spi(void);
 

	
 
// send and receive a byte of data (master mode)
 
uint8_t send_spi(uint8_t out);
 

	
 
// receive the byte of data waiting on the SPI buffer and
 
// set the next byte to transfer - for use in slave mode
 
// when interrupts are enabled.
 
uint8_t received_from_spi(uint8_t out);
 

	
0 comments (0 inline, 0 general)