LTlib LaurTec Library
4.0.0 Beta
Open Source C Library for Microchip Microcontrollers based on XC8 Compiler
Main Page
Data Structures
Files
File List
Globals
All
Data Structures
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Macros
module_SPI.h
Go to the documentation of this file.
1
/*******************************************************************************
2
3
Author : Mauro Laurenti
4
Version : 1.0
5
Created on Date : 28/11/2015
6
Last update : 28/11/2015
7
8
CopyRight 2006-2015 all rights are reserved
9
10
********************************************************
11
SOFTWARE LICENSE AGREEMENT
12
********************************************************
13
14
The usage of the supplied software imply the acceptance of the following license.
15
16
The software supplied herewith by Mauro Laurenti (the Author) is intended for
17
use solely and exclusively on Microchip PIC Microcontroller (registered mark).
18
The software is owned by the Author, and is protected under applicable
19
copyright laws. All rights are reserved.
20
Any use in violation of the foregoing restrictions may subject the
21
user to criminal sanctions under applicable laws, as well as to civil liability
22
for the breach of the terms and conditions of this license.
23
Commercial use is forbidden without a written acknowledgement with the Author.
24
Personal or educational use is allowed if the application containing the
25
following software doesn't aim to commercial use or monetary earning of any kind.
26
27
THIS SOFTWARE IS PROVIDED IN AN "AS IS" CONDITION. NO WARRANTIES,
28
WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED
29
TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
30
PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE AUTHOR SHALL NOT,
31
IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR
32
CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
33
34
********************************************************
35
PURPOSES
36
********************************************************
37
38
This library contains all the functions that are handy for controlling
39
the SPI module
40
*******************************************************************************/
41
42
#ifndef LTLIB_SPI_MODULE_H
43
#define LTLIB_SPI_MODULE_H
44
45
#ifdef __XC8
46
#include <xc.h>
47
#endif
48
49
//*****************************************
50
// Library Test
51
//*****************************************
52
#include "
LTlib.h
"
53
54
#ifndef SPI_LIBRARY_SUPPORTED
55
#error (LTlib) The MCU you have selected is not supported by module_SPI library.
56
#endif
57
58
59
//*****************************************
60
// SPI module initialization
61
//*****************************************
62
#define SPI_SS_ENABLED 0b00000100
63
#define SPI_SS_DISABLED 0b00000101
64
#define SPI1_SS_PIN SPI_SS_DISABLED
65
#define SPI2_SS_PIN SPI_SS_DISABLED
66
67
68
//*****************************************
69
// SPI module constants
70
//*****************************************
71
72
#define SPI_MASTER_DEVICE 0x01
73
#define SPI_SLAVE_DEVICE 0x02
74
75
#define SPI_MODE_0 0x00
76
#define SPI_MODE_1 0x01
77
#define SPI_MODE_2 0x02
78
#define SPI_MODE_3 0x03
79
80
#define SPI_TIMER_OUT_CLK 0b00000011
81
#define SPI_CLK_OSC_64 0b00000010
82
#define SPI_CLK_OSC_16 0b00000001
83
#define SPI_CLK_OSC_4 0b00000000
84
85
86
#if (UART_CLOCK == 20000000)
87
#define SPI_CLK_312_KHZ 0b00000010
88
#define SPI_CLK_1250_KHZ 0b00000001
89
#define SPI_CLK_5000_KHZ 0b00000000
90
#endif
91
104
void
SPI1_open
(
unsigned
char
device_type);
105
void
SPI2_open
(
unsigned
char
device_type);
106
107
116
void
SPI1_close
(
void
);
117
void
SPI2_close
(
void
);
118
119
131
void
SPI1_baudrate
(
unsigned
char
baudrate);
132
void
SPI2_baudrate
(
unsigned
char
baudrate);
133
134
135
147
void
SPI1_mode
(
unsigned
char
communication_mode);
148
void
SPI2_mode
(
unsigned
char
communication_mode);
149
150
161
unsigned
char
SPI1_write_byte
(
unsigned
char
byte_to_send);
162
unsigned
char
SPI2_write_byte
(
unsigned
char
byte_to_send);
163
164
175
unsigned
char
SPI1_read_byte
(
void
);
176
unsigned
char
SPI2_read_byte
(
void
);
177
178
189
#define SPI1_check_data_ready() (SSPSTATbits.BF)
190
#define SPI2_check_data_ready() (SSP2STATbits.BF)
191
192
202
#define SPI1_check_bus_collision() (SSPCON1bits.WCOL)
203
#define SPI2_check_bus_collision() (SSP2CON1bits.WCOL)
204
205
215
#define SPI1_check_buffer_overflow() (SSPCON1bits.SSPOV)
216
#define SPI2_check_buffer_overflow() (SSP2CON1bits.SSPOV)
217
218
228
#define SPI1_is_TX_over() (PIR1bits.SSPIF)
229
#define SPI2_is_TX_over() (PIR3bits.SSP2IF)
230
231
232
#endif
LTlib_v_4.0.0
inc
module_SPI.h
Generated on Sun Feb 21 2016 13:52:59 for LTlib LaurTec Library by
1.8.3.1