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