1 | #ifndef __SPI_MASTER_H
|
---|
2 | #define __SPI_MASTER_H
|
---|
3 | //-----------------------------------------------------------------------------
|
---|
4 |
|
---|
5 | #include "typedefs.h"
|
---|
6 | #include "application.h"
|
---|
7 | #include "usart.h"
|
---|
8 | //-----------------------------------------------------------------------------
|
---|
9 |
|
---|
10 | // Port Definitions
|
---|
11 | #define SPI_PRT PORTB
|
---|
12 | #define SPI_DDR DDRB
|
---|
13 |
|
---|
14 | // Bit Definitions
|
---|
15 | #define SPI_SCLK PB7
|
---|
16 | #define SPI_MOSI PB5
|
---|
17 | #define SPI_MISO PB6
|
---|
18 | // #define SPI_SS PB4 // not in this application!!! danger
|
---|
19 | #define SPI_E_CS PB4 //device 0
|
---|
20 | #define SPI_AD_CS PD3 //device 1
|
---|
21 | #define SPI_M_CS PD4 //device 2
|
---|
22 | #define SPI_A_CS PD5 //device 3
|
---|
23 |
|
---|
24 | #define SPI_READ_BUFFER_SIZE 16
|
---|
25 | #define SPI_WRITE_BUFFER_SIZE 16
|
---|
26 |
|
---|
27 | #define SPI_MAX_SLAVE_INDEX 2
|
---|
28 | #define SPI_MAX_CLOCK_INDEX 6
|
---|
29 |
|
---|
30 | //-----------------------------------------------------------------------------
|
---|
31 |
|
---|
32 | extern volatile U08 spi_clock_index;
|
---|
33 | extern volatile U08 spi_cpol;
|
---|
34 | extern volatile U08 spi_cpha;
|
---|
35 | extern volatile U08 spi_dord;
|
---|
36 | extern volatile U08 SPI_DEVICE_SS[4];
|
---|
37 | extern volatile BOOL SPI_DEVICE_ACTIVE_HIGH[4];
|
---|
38 |
|
---|
39 | extern volatile U08 spi_read_buffer[SPI_READ_BUFFER_SIZE];
|
---|
40 | extern volatile U08 spi_write_buffer[SPI_WRITE_BUFFER_SIZE];
|
---|
41 | //-----------------------------------------------------------------------------
|
---|
42 |
|
---|
43 | void spi_init(void);
|
---|
44 | void spi_transfer(U08 bytes, U08 device);
|
---|
45 | U08 spi_transfer_byte(U08 data);
|
---|
46 | void spi_set_clock_index(U08 clock_index);
|
---|
47 | void spi_set_dord(U08 dord);
|
---|
48 | void spi_set_cpol(U08 cpol);
|
---|
49 | void spi_set_cpha(U08 cpha);
|
---|
50 | void spi_setup(void);
|
---|
51 | void spi_transfer_string(U08 length, U08* addr, U08 device);
|
---|
52 | //-----------------------------------------------------------------------------
|
---|
53 |
|
---|
54 | #endif
|
---|