-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspi.h
56 lines (46 loc) · 1.59 KB
/
spi.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*
* spi.h
*
* Created on: 24-Jan-2009
* Author: Neil MacMillan
*
* Macros and prototypes for using the AVR as an SPI master.
*
* References:
* Engelke, Stefan. AVR-Lib/SPI. http://www.tinkerer.eu/AVRLib/SPI
* Tanner, Justin. LED Wheel: Code. http://webhome.csc.uvic.ca/~mcheng/samples/led_wheel/wheel_demo.zip
* Atmel. AT90USB1287 Hardware Manual. http://www.atmel.com/dyn/resources/prod_documents/doc7593.pdf
*
* All the hard work for this was done by [Engelke].
*/
#ifndef SPI_H_
#define SPI_H_
#include <stdio.h>
#include <avr/io.h>
#include <stdlib.h>
void SPI_SetCS(void);
void SPI_ClrCS(void);
/**
* Initialize the SPI port as a master.
* This function must be called once before using the SPI interface.
*/
void SPI_Init(void);
/**
* Write a block of data to the slave, and read the data returned from the slave into a buffer.
* The data and buffer memory blocks must be the same length.
* \param data A pointer to the contiguous memory block to write to the slave.
* \param buffer A pointer to the contiguous memory block to which the SPI data are to be written.
* \param len The length of the memory blocks, in bytes.
*/
void SPI_ReadWrite_Block (uint8_t * data, uint8_t * buffer, uint8_t len);
/**
* Write a block to the slave.
* \param data A pointer to the contiguous memory block to write to the slave.
* \param len The length of the block to write, in bytes.
*/
void SPI_Write_Block (uint8_t * data, uint8_t len);
/**
* Write a byte to the slave, and get the return byte from the slave.
*/
uint8_t SPI_Write_Byte (uint8_t data);
#endif /* SPI_H_ */