PIC24 Support Libraries
pic24_i2c.h
Go to the documentation of this file.
1 /*
2  * "Copyright (c) 2008 Robert B. Reese, Bryan A. Jones, J. W. Bruce ("AUTHORS")"
3  * All rights reserved.
4  * (R. Reese, reese_AT_ece.msstate.edu, Mississippi State University)
5  * (B. A. Jones, bjones_AT_ece.msstate.edu, Mississippi State University)
6  * (J. W. Bruce, jwbruce_AT_ece.msstate.edu, Mississippi State University)
7  *
8  * Permission to use, copy, modify, and distribute this software and its
9  * documentation for any purpose, without fee, and without written agreement is
10  * hereby granted, provided that the above copyright notice, the following
11  * two paragraphs and the authors appear in all copies of this software.
12  *
13  * IN NO EVENT SHALL THE "AUTHORS" BE LIABLE TO ANY PARTY FOR
14  * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
15  * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE "AUTHORS"
16  * HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
17  *
18  * THE "AUTHORS" SPECIFICALLY DISCLAIMS ANY WARRANTIES,
19  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
20  * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
21  * ON AN "AS IS" BASIS, AND THE "AUTHORS" HAS NO OBLIGATION TO
22  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
23  *
24  * Please maintain this header in its entirety when copying/modifying
25  * these files.
26  *
27  *
28  */
29 
30 #pragma once
31 
32 #include <stdint.h>
33 #include "pic24_chip.h"
34 
35 // Only include if this I2C Module exists.
36 #if (NUM_I2C_MODS >= 1)
37 
38 // Documentation for this file. If the \file tag is not present,
39 // this file will not be documented.
40 // Note: place this comment below the #if NUM_I2C_MODS so Doxygen
41 // will only see it once.
42 /** \file
43  * I<sup>2</sup>C support functions - these are split into two classes: primitive operations (start, stop,
44  * rstart, put, get) and transactions, which use the primitive operations to read/write
45  * multiple bytes.
46  *
47  * \note For simplicity, only functions supporting the first
48  * I<sup>2</sup>C module are listed. Chips with more than one
49  * module have similar functions defined for each module.
50  */
51 
52 
53 
54 
55 #ifndef I2C_ACK
56 # define I2C_ACK 0
57 #endif
58 #ifndef I2C_NAK
59 # define I2C_NAK 1
60 #endif
61 
62 #define I2C_WADDR(x) (x & 0xFE) //clear R/W bit of I2C addr
63 #define I2C_RADDR(x) (x | 0x01) //set R/W bit of I2C addr
64 
65 
66 //I2C Operations
67 void configI2C1(uint16_t u16_FkHZ);
68 void startI2C1(void);
69 void rstartI2C1(void);
70 void stopI2C1(void);
71 void putI2C1(uint8_t u8_val);
73 uint8_t getI2C1(uint8_t u8_ack2Send);
74 
75 //I2C Transactions
76 void write1I2C1(uint8_t u8_addr,uint8_t u8_d1);
77 void write2I2C1(uint8_t u8_addr,uint8_t u8_d1, uint8_t u8_d2);
78 void writeNI2C1(uint8_t u8_addr,uint8_t* pu8_data, uint16_t u16_cnt);
79 void read1I2C1(uint8_t u8_addr,uint8_t* pu8_d1);
80 void read2I2C1(uint8_t u8_addr,uint8_t* pu8_d1, uint8_t* pu8_d2);
81 void readNI2C1(uint8_t u8_addr,uint8_t* pu8_data, uint16_t u16_cnt);
82 
83 #endif // #if (NUM_I2C_MODS >= 1)
84 
85 
86 
87 
88 
89 /*
90  * "Copyright (c) 2008 Robert B. Reese, Bryan A. Jones, J. W. Bruce ("AUTHORS")"
91  * All rights reserved.
92  * (R. Reese, reese_AT_ece.msstate.edu, Mississippi State University)
93  * (B. A. Jones, bjones_AT_ece.msstate.edu, Mississippi State University)
94  * (J. W. Bruce, jwbruce_AT_ece.msstate.edu, Mississippi State University)
95  *
96  * Permission to use, copy, modify, and distribute this software and its
97  * documentation for any purpose, without fee, and without written agreement is
98  * hereby granted, provided that the above copyright notice, the following
99  * two paragraphs and the authors appear in all copies of this software.
100  *
101  * IN NO EVENT SHALL THE "AUTHORS" BE LIABLE TO ANY PARTY FOR
102  * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
103  * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE "AUTHORS"
104  * HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
105  *
106  * THE "AUTHORS" SPECIFICALLY DISCLAIMS ANY WARRANTIES,
107  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
108  * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
109  * ON AN "AS IS" BASIS, AND THE "AUTHORS" HAS NO OBLIGATION TO
110  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
111  *
112  * Please maintain this header in its entirety when copying/modifying
113  * these files.
114  *
115  *
116  */
117 
118 #pragma once
119 
120 #include <stdint.h>
121 #include "pic24_chip.h"
122 
123 // Only include if this I2C Module exists.
124 #if (NUM_I2C_MODS >= 2)
125 
126 // Documentation for this file. If the \file tag is not present,
127 // this file will not be documented.
128 // Note: place this comment below the #if NUM_I2C_MODS so Doxygen
129 // will only see it once.
130 /** \file
131  * I<sup>2</sup>C support functions - these are split into two classes: primitive operations (start, stop,
132  * rstart, put, get) and transactions, which use the primitive operations to read/write
133  * multiple bytes.
134  *
135  * \note For simplicity, only functions supporting the first
136  * I<sup>2</sup>C module are listed. Chips with more than one
137  * module have similar functions defined for each module.
138  */
139 
140 
141 
142 
143 #ifndef I2C_ACK
144 # define I2C_ACK 0
145 #endif
146 #ifndef I2C_NAK
147 # define I2C_NAK 1
148 #endif
149 
150 #define I2C_WADDR(x) (x & 0xFE) //clear R/W bit of I2C addr
151 #define I2C_RADDR(x) (x | 0x01) //set R/W bit of I2C addr
152 
153 
154 //I2C Operations
155 void configI2C2(uint16_t u16_FkHZ);
156 void startI2C2(void);
157 void rstartI2C2(void);
158 void stopI2C2(void);
159 void putI2C2(uint8_t u8_val);
160 uint8_t putNoAckCheckI2C2(uint8_t u8_val);
161 uint8_t getI2C2(uint8_t u8_ack2Send);
162 
163 //I2C Transactions
164 void write1I2C2(uint8_t u8_addr,uint8_t u8_d1);
165 void write2I2C2(uint8_t u8_addr,uint8_t u8_d1, uint8_t u8_d2);
166 void writeNI2C2(uint8_t u8_addr,uint8_t* pu8_data, uint16_t u16_cnt);
167 void read1I2C2(uint8_t u8_addr,uint8_t* pu8_d1);
168 void read2I2C2(uint8_t u8_addr,uint8_t* pu8_d1, uint8_t* pu8_d2);
169 void readNI2C2(uint8_t u8_addr,uint8_t* pu8_data, uint16_t u16_cnt);
170 
171 #endif // #if (NUM_I2C_MODS >= 2)
172 
173 
174 
175 
176 
void stopI2C1(void)
Definition: pic24_i2c.c:102
void putI2C1(uint8_t u8_val)
Definition: pic24_i2c.c:119
void configI2C1(uint16_t u16_FkHZ)
Definition: pic24_i2c.c:51
uint8_t putNoAckCheckI2C1(uint8_t u8_val)
Definition: pic24_i2c.c:141
void startI2C1(void)
Definition: pic24_i2c.c:70
void write1I2C1(uint8_t u8_addr, uint8_t u8_d1)
Definition: pic24_i2c.c:185
void rstartI2C1(void)
Definition: pic24_i2c.c:86
void write2I2C1(uint8_t u8_addr, uint8_t u8_d1, uint8_t u8_d2)
Definition: pic24_i2c.c:197
void writeNI2C1(uint8_t u8_addr, uint8_t *pu8_data, uint16_t u16_cnt)
Definition: pic24_i2c.c:211
uint8_t getI2C1(uint8_t u8_ack2Send)
Definition: pic24_i2c.c:159
void read2I2C1(uint8_t u8_addr, uint8_t *pu8_d1, uint8_t *pu8_d2)
Definition: pic24_i2c.c:240
void readNI2C1(uint8_t u8_addr, uint8_t *pu8_data, uint16_t u16_cnt)
Definition: pic24_i2c.c:254
unsigned char uint8_t
An abbreviation for an 8-bit unsigned integer.
Definition: dataXferImpl.h:194
void read1I2C1(uint8_t u8_addr, uint8_t *pu8_d1)
Definition: pic24_i2c.c:227