My favorites
▼
|
Sign in
rocketnumbernine
Open source project code from www.rocketnumbernine.com
Project Home
Downloads
Issues
Source
Checkout
Browse
Changes
Source path:
svn
/
trunk
/
AVR
/
spi
/
spi.h
r13
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*
* Copyright (c) 2009 Andrew Smallbone <andrew@rocketnumbernine.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#ifndef _spi_h__
#define _spi_h__
#include <avr/io.h>
#ifdef __cplusplus
extern "C"{
#endif
// create alias for the different SPI chip pins - code assumes all on port B
#if (defined(__AVR_AT90USB82__) || defined(__AVR_AT90USB162__))
#define SPI_SS_PIN PORTB0
#define SPI_SCK_PIN PORTB1
#define SPI_MOSI_PIN PORTB2
#define SPI_MISO_PIN PORTB3
#elif (defined(__AVR_ATmega48__) || defined(_AVR_ATmega88__) || defined(__AVR_ATmega168__) || defined(__AVR_ATmega328__) || defined(__AVR_ATmega328P__))
#define SPI_SS_PIN PORTB2
#define SPI_SCK_PIN PORTB5
#define SPI_MOSI_PIN PORTB3
#define SPI_MISO_PIN PORTB4
#else
#error unknown processor - add to spi.h
#endif
// 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);
#ifdef __cplusplus
} // extern "C"
#endif
#endif
Show details
Hide details
Change log
r2
by and...@rocketnumbernine.com on Feb 24, 2010
Diff
initial version
Go to:
/trunk/AVR
/trunk/AVR/spi
/trunk/AVR/spi/Arduino
/trunk/AVR/spi/Arduino/DS1305
.../AVR/spi/Arduino/DS1305/ds1305.c
.../AVR/spi/Arduino/DS1305/ds1305.h
.../spi/Arduino/DS1305/keywords.txt
/trunk/AVR/spi/Arduino/SPI
/trunk/AVR/spi/Arduino/SPI/examples
...rduino/SPI/examples/DS1305_Alarm
...es/DS1305_Alarm/DS1305_Alarm.pde
...PI/examples/MAX6675_Thermocouple
...ocouple/MAX6675_Thermocouple.pde
...Arduino/SPI/examples/MCP3201_ADC
...ples/MCP3201_ADC/MCP3201_ADC.pde
...Arduino/SPI/examples/MasterSlave
...ples/MasterSlave/MasterSlave.pde
...VR/spi/Arduino/SPI/examples/Test
...duino/SPI/examples/Test/Test.pde
...AVR/spi/Arduino/SPI/keywords.txt
/trunk/AVR/spi/Arduino/SPI/spi.c
/trunk/AVR/spi/Arduino/SPI/spi.h
/trunk/AVR/spi/Makefile
/trunk/AVR/spi/Makefile.mf
/trunk/AVR/spi/ds1305.c
/trunk/AVR/spi/ds1305.h
/trunk/AVR/spi/readme.txt
/trunk/AVR/spi/spi-test-adc.c
...k/AVR/spi/spi-test-masterslave.c
/trunk/AVR/spi/spi-test-rtc.c
/trunk/AVR/spi/spi.c
/trunk/AVR/spi/spi.h
Project members,
sign in
to write a code review
Older revisions
All revisions of this file
File info
Size: 3427 bytes, 94 lines
View raw file
Powered by
Google Project Hosting