LTlib LaurTec Library
4.0.1
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.1
5
Created on Date : 09/03/2016
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
#ifdef SPI_MODULE_TYPE_2
106
void
SPI2_open (
unsigned
char
device_type);
107
#endif
108
117
void
SPI1_close
(
void
);
118
#ifdef SPI_MODULE_TYPE_2
119
void
SPI2_close (
void
);
120
#endif
121
133
void
SPI1_baudrate
(
unsigned
char
baudrate);
134
#ifdef SPI_MODULE_TYPE_2
135
void
SPI2_baudrate (
unsigned
char
baudrate);
136
#endif
137
138
150
void
SPI1_mode
(
unsigned
char
communication_mode);
151
#ifdef SPI_MODULE_TYPE_2
152
void
SPI2_mode (
unsigned
char
communication_mode);
153
#endif
154
165
signed
char
SPI1_write_byte
(
unsigned
char
byte_to_send);
166
#ifdef SPI_MODULE_TYPE_2
167
signed
char
SPI2_write_byte (
unsigned
char
byte_to_send);
168
#endif
169
180
unsigned
char
SPI1_read_byte
(
void
);
181
#ifdef SPI_MODULE_TYPE_2
182
unsigned
char
SPI2_read_byte (
void
);
183
#endif
184
185
196
#define SPI1_check_data_ready() (SSPSTATbits.BF)
197
#ifdef SPI_MODULE_TYPE_2
198
#define SPI2_check_data_ready() (SSP2STATbits.BF)
199
#endif
200
201
211
#define SPI1_check_bus_collision() (SSPCON1bits.WCOL)
212
#ifdef SPI_MODULE_TYPE_2
213
#define SPI2_check_bus_collision() (SSP2CON1bits.WCOL)
214
#endif
215
225
#define SPI1_check_buffer_overflow() (SSPCON1bits.SSPOV)
226
#ifdef SPI_MODULE_TYPE_2
227
#define SPI2_check_buffer_overflow() (SSP2CON1bits.SSPOV)
228
#endif
229
239
#define SPI1_is_TX_over() (PIR1bits.SSPIF)
240
#ifdef SPI_MODULE_TYPE_2
241
#define SPI2_is_TX_over() (PIR3bits.SSP2IF)
242
#endif
243
244
#endif
LTlib_v_4.0.1
inc
module_SPI.h
Generated on Sat Mar 12 2016 11:01:40 for LTlib LaurTec Library by
1.8.3.1