PIC24 Support Libraries
lib
include
pic24_spi.h
Go to the documentation of this file.
1
/* Standard copyright does not go in this file because
2
* of the use of Microchip provided macros, see comments below.
3
*/
4
5
6
// Documentation for this file. If the \file tag isn't present,
7
// this file won't be documented.
8
/** \file
9
* SPI module support functions.
10
*/
11
12
#pragma once
13
14
#include <stdint.h>
15
#include "
pic24_chip.h
"
16
17
/*
18
The following macros are a subset of the AND/OR macros found in the
19
the MPLAB C30/src/peripheral_24F/spi.h file and placed
20
in this header for use solely and exclusively on Microchip
21
PICmicro Microcontroller products as
22
specified in the MPLAB C30/src/peripheral_24F/spi.h header.
23
*/
24
25
/* SPIXCON1: SPIx CONTROL REGISTER 1 */
26
#define DISABLE_SCK_PIN 0x1000
/* SCK pin is not used by module */
27
#define ENABLE_SCK_PIN 0x0000
/* SCK pin is used by module */
28
#define SCK_PIN_MASK (~DISABLE_SCK_PIN)
29
30
#define DISABLE_SDO_PIN 0x0800
/* SDO pin is not used by module */
31
#define ENABLE_SDO_PIN 0x0000
/* SDO pin is used by module */
32
#define SDO_PIN_MASK (~DISABLE_SDO_PIN)
33
34
#define SPI_MODE16_ON 0x0400
/* Communication is word wide */
35
#define SPI_MODE8_ON 0x0000
/* Communication is byte wide */
36
#define SPI_MODE_MASK (~SPI_MODE16_ON)
37
38
#define SPI_SMP_ON 0x0200
/* Input data sampled at end of data output time */
39
#define SPI_SMP_OFF 0x0000
/* Input data sampled at middle of data output time */
40
#define SPI_SMP_MASK (~SPI_SMP_ON)
41
42
#define SPI_CKE_ON 0x0100
/* Transmit happens from active clock state to idle clock state*/
43
#define SPI_CKE_OFF 0x0000
/* Transmit happens on transition from idle clock state to active clock state */
44
#define SPI_CKE_MASK (~SPI_CKE_ON)
45
46
#define SLAVE_ENABLE_ON 0x0080
/* Slave Select enbale */
47
#define SLAVE_ENABLE_OFF 0x0000
/* Slave Select not used by module */
48
#define SLAVE_ENABLE_MASK (~SLAVE_ENABLE_ON)
49
50
#define CLK_POL_ACTIVE_LOW 0x0040
/* Idle state for clock is high, active is low */
51
#define CLK_POL_ACTIVE_HIGH 0x0000
/* Idle state for clock is low, active is high */
52
#define CLK_POL_ACTIVE_MASK (~CLK_POL_ACTIVE_LOW)
53
54
#define MASTER_ENABLE_ON 0x0020
/* Master Mode */
55
#define MASTER_ENABLE_OFF 0x0000
/* Slave Mode */
56
#define MASTER_ENABLE_MASK (~MASTER_ENABLE_ON)
57
58
#define SEC_PRESCAL_1_1 0x001c
/* Secondary Prescale 1:1 */
59
#define SEC_PRESCAL_2_1 0x0018
/* Secondary Prescale 2:1 */
60
#define SEC_PRESCAL_3_1 0x0014
/* Secondary Prescale 3:1 */
61
#define SEC_PRESCAL_4_1 0x0010
/* Secondary Prescale 4:1 */
62
#define SEC_PRESCAL_5_1 0x000c
/* Secondary Prescale 5:1 */
63
#define SEC_PRESCAL_6_1 0x0008
/* Secondary Prescale 6:1 */
64
#define SEC_PRESCAL_7_1 0x0004
/* Secondary Prescale 7:1 */
65
#define SEC_PRESCAL_8_1 0x0000
/* Secondary Prescale 8:1 */
66
#define SEC_PRESCAL_MASK (~SEC_PRESCAL_1_1)
67
68
#define PRI_PRESCAL_1_1 0x0003
/* Primary Prescale 1:1 */
69
#define PRI_PRESCAL_4_1 0x0002
/* Primary Prescale 4:1 */
70
#define PRI_PRESCAL_16_1 0x0001
/* Primary Prescale 16:1 */
71
#define PRI_PRESCAL_64_1 0x0000
/* Primary Prescale 64:1 */
72
#define PRI_PRESCAL_MASK (~PRI_PRESCAL_1_1)
73
74
/* SPIxSTAT REGISTER */
75
#define SPI_ENABLE 0x8000
/* Enable module */
76
#define SPI_DISABLE 0x0000
/* Disable module */
77
#define SPI_ENBL_DSBL_MASK (~SPI_ENABLE)
78
79
#define SPI_IDLE_STOP 0x2000
/* Discontinue module operation in idle mode */
80
#define SPI_IDLE_CON 0x0000
/* Continue module operation in idle mode */
81
#define SPI_IDLE_MASK (~SPI_IDLE_STOP)
82
83
#define SPI_RX_OVFLOW 0x0040
84
#define SPI_RX_OVFLOW_CLR 0x0000
/* Clear receive overflow bit */
85
86
/* SPIxCON2: SPIx CONTROL REGISTER 2 */
87
#define FRAME_ENABLE_ON 0x8000
/* Frame SPI support enable */
88
#define FRAME_ENABLE_OFF 0x0000
/* Frame SPI support Disable */
89
#define FRAME_ENABLE_MASK (~FRAME_ENABLE_ON)
90
91
#define FRAME_SYNC_INPUT 0x4000
/* Frame sync pulse Input (slave) */
92
#define FRAME_SYNC_OUTPUT 0x0000
/* Frame sync pulse Output (master)*/
93
#define FRAME_SYNC_MASK (~FRAME_SYNC_INPUT)
94
95
#define FRAME_SYNC_ACTIVE_HIGH 0x2000
/* Frame sync pulse Input (slave) */
96
#define FRAME_SYNC_ACTIVE_LOW 0x0000
/* Frame sync pulse Output (master)*/
97
#define FRAME_SYNC_POL_MASK (~FRAME_SYNC_ACTIVE_HIGH)
98
99
#define SPI_FRM_PULSE_FIRST_CLK 0x0002
/* frame pulse coincides with the first bit clock */
100
#define SPI_FRM_PULSE_PREV_CLK 0x0000
/* frame pulse precedes the first bit clock */
101
#define SPI_FRM_PULSE_MASK (~SPI_FRM_PULSE_FIRST_CLK)
102
103
#define SPI_ENH_BUFF_ENABLE 0x0001
/* enable enhanced buffer */
104
#define SPI_ENH_BUFF_DISABLE 0x0000
/* disable enhanced buffer */
105
#define SPI_ENH_BUFF_MASK (~SPI_ENH_BUFF_ENABLE)
106
107
// Only include if this UART exists.
108
#if (NUM_SPI_MODS >= 1)
109
uint16_t
ioMasterSPI1
(uint16_t u16_c);
110
#endif
111
112
113
#if (NUM_SPI_MODS >= 2)
114
uint16_t ioMasterSPI2(uint16_t u16_c);
115
#endif
ioMasterSPI1
uint16_t ioMasterSPI1(uint16_t u16_c)
Definition:
pic24_spi.c:67
pic24_chip.h
Generated by
1.8.13