PIC24 Support Libraries
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
pic24_uart.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 
31 #ifndef _PIC24_UART1_H_
32 #define _PIC24_UART1_H_
33 
34 #include <stdint.h>
35 #include "pic24_chip.h"
36 #include "pic24_libconfig.h"
37 #include "pic24_util.h"
38 
39 // Only include if this UART module exists.
40 #if (NUM_UART_MODS >= 1)
41 
42 // Documentation for this file. If the \file tag isn't present,
43 // this file won't be documented.
44 // Note: place this comment below the #if NUM_UART_MODS so Doxygen
45 // will only see it once.
46 /** \file
47  * This file contains routines which configure and
48  * use the UARTs on the PIC. See \ref pic24_serial.h
49  * for higher-level routines, which should typically
50  * be called by the user rather than these routines.
51  */
52 
53 
54 /** Determine if a character is available in the UART's
55  * receive buffer.
56  * \return True (1) if character is available, 0 if not.
57  */
58 #define IS_CHAR_READY_UART1() U1STAbits.URXDA
59 
60 /** Determine if a the transmit buffer is full.
61  * \return True (1) if the transmit buffer if full,
62  * false (0) if not.
63  */
64 #define IS_TRANSMIT_BUFFER_FULL_UART1() U1STAbits.UTXBF
65 
66 /** Determines if all characters placed in the UART have been sent.
67  * Returns 1 if the last transmission has completed, or 0 if a transmission
68  * is in progress or queued in the transmit buffer.
69  * \return True (1) if the last transmission has completed, 0 if not.
70  */
71 #define IS_TRANSMIT_COMPLETE_UART1() U1STAbits.TRMT
72 
73 /** Waits until all characters placed in the UART have been sent. */
74 inline static void WAIT_UNTIL_TRANSMIT_COMPLETE_UART1() {
76  doHeartbeat();
77 }
78 
79 void outChar1(uint8_t u8_c);
80 uint8_t inChar1(void);
81 void configUART1(uint32_t u32_baudRate);
82 uint8_t isCharReady1(void);
83 void checkRxErrorUART1(void); //check for UART RX error
84 
85 #endif // #if (NUM_UART_MODS >= 1)
86 #endif // #ifndef _PIC24_UART1_H_
87 
88 
89 
90 
91 
92 
93 
94 
95 /*
96  * "Copyright (c) 2008 Robert B. Reese, Bryan A. Jones, J. W. Bruce ("AUTHORS")"
97  * All rights reserved.
98  * (R. Reese, reese_AT_ece.msstate.edu, Mississippi State University)
99  * (B. A. Jones, bjones_AT_ece.msstate.edu, Mississippi State University)
100  * (J. W. Bruce, jwbruce_AT_ece.msstate.edu, Mississippi State University)
101  *
102  * Permission to use, copy, modify, and distribute this software and its
103  * documentation for any purpose, without fee, and without written agreement is
104  * hereby granted, provided that the above copyright notice, the following
105  * two paragraphs and the authors appear in all copies of this software.
106  *
107  * IN NO EVENT SHALL THE "AUTHORS" BE LIABLE TO ANY PARTY FOR
108  * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
109  * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE "AUTHORS"
110  * HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
111  *
112  * THE "AUTHORS" SPECIFICALLY DISCLAIMS ANY WARRANTIES,
113  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
114  * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
115  * ON AN "AS IS" BASIS, AND THE "AUTHORS" HAS NO OBLIGATION TO
116  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
117  *
118  * Please maintain this header in its entirety when copying/modifying
119  * these files.
120  *
121  *
122  */
123 
124 
125 #ifndef _PIC24_UART2_H_
126 #define _PIC24_UART2_H_
127 
128 #include <stdint.h>
129 #include "pic24_chip.h"
130 #include "pic24_libconfig.h"
131 #include "pic24_util.h"
132 
133 // Only include if this UART module exists.
134 #if (NUM_UART_MODS >= 2)
135 
136 // Documentation for this file. If the \file tag isn't present,
137 // this file won't be documented.
138 // Note: place this comment below the #if NUM_UART_MODS so Doxygen
139 // will only see it once.
140 /** \file
141  * This file contains routines which configure and
142  * use the UARTs on the PIC. See \ref pic24_serial.h
143  * for higher-level routines, which should typically
144  * be called by the user rather than these routines.
145  */
146 
147 
148 /** Determine if a character is available in the UART's
149  * receive buffer.
150  * \return True (1) if character is available, 0 if not.
151  */
152 #define IS_CHAR_READY_UART2() U2STAbits.URXDA
153 
154 /** Determine if a the transmit buffer is full.
155  * \return True (1) if the transmit buffer if full,
156  * false (0) if not.
157  */
158 #define IS_TRANSMIT_BUFFER_FULL_UART2() U2STAbits.UTXBF
159 
160 /** Determines if all characters placed in the UART have been sent.
161  * Returns 1 if the last transmission has completed, or 0 if a transmission
162  * is in progress or queued in the transmit buffer.
163  * \return True (1) if the last transmission has completed, 0 if not.
164  */
165 #define IS_TRANSMIT_COMPLETE_UART2() U2STAbits.TRMT
166 
167 /** Waits until all characters placed in the UART have been sent. */
168 inline static void WAIT_UNTIL_TRANSMIT_COMPLETE_UART2() {
169  while (!IS_TRANSMIT_COMPLETE_UART2())
170  doHeartbeat();
171 }
172 
173 void outChar2(uint8_t u8_c);
174 uint8_t inChar2(void);
175 void configUART2(uint32_t u32_baudRate);
176 uint8_t isCharReady2(void);
177 void checkRxErrorUART2(void); //check for UART RX error
178 
179 #endif // #if (NUM_UART_MODS >= 2)
180 #endif // #ifndef _PIC24_UART2_H_
181 
182 
183 
184 
185 
186 
187 
188 
189 /*
190  * "Copyright (c) 2008 Robert B. Reese, Bryan A. Jones, J. W. Bruce ("AUTHORS")"
191  * All rights reserved.
192  * (R. Reese, reese_AT_ece.msstate.edu, Mississippi State University)
193  * (B. A. Jones, bjones_AT_ece.msstate.edu, Mississippi State University)
194  * (J. W. Bruce, jwbruce_AT_ece.msstate.edu, Mississippi State University)
195  *
196  * Permission to use, copy, modify, and distribute this software and its
197  * documentation for any purpose, without fee, and without written agreement is
198  * hereby granted, provided that the above copyright notice, the following
199  * two paragraphs and the authors appear in all copies of this software.
200  *
201  * IN NO EVENT SHALL THE "AUTHORS" BE LIABLE TO ANY PARTY FOR
202  * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
203  * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE "AUTHORS"
204  * HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
205  *
206  * THE "AUTHORS" SPECIFICALLY DISCLAIMS ANY WARRANTIES,
207  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
208  * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
209  * ON AN "AS IS" BASIS, AND THE "AUTHORS" HAS NO OBLIGATION TO
210  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
211  *
212  * Please maintain this header in its entirety when copying/modifying
213  * these files.
214  *
215  *
216  */
217 
218 
219 #ifndef _PIC24_UART3_H_
220 #define _PIC24_UART3_H_
221 
222 #include <stdint.h>
223 #include "pic24_chip.h"
224 #include "pic24_libconfig.h"
225 #include "pic24_util.h"
226 
227 // Only include if this UART module exists.
228 #if (NUM_UART_MODS >= 3)
229 
230 // Documentation for this file. If the \file tag isn't present,
231 // this file won't be documented.
232 // Note: place this comment below the #if NUM_UART_MODS so Doxygen
233 // will only see it once.
234 /** \file
235  * This file contains routines which configure and
236  * use the UARTs on the PIC. See \ref pic24_serial.h
237  * for higher-level routines, which should typically
238  * be called by the user rather than these routines.
239  */
240 
241 
242 /** Determine if a character is available in the UART's
243  * receive buffer.
244  * \return True (1) if character is available, 0 if not.
245  */
246 #define IS_CHAR_READY_UART3() U3STAbits.URXDA
247 
248 /** Determine if a the transmit buffer is full.
249  * \return True (1) if the transmit buffer if full,
250  * false (0) if not.
251  */
252 #define IS_TRANSMIT_BUFFER_FULL_UART3() U3STAbits.UTXBF
253 
254 /** Determines if all characters placed in the UART have been sent.
255  * Returns 1 if the last transmission has completed, or 0 if a transmission
256  * is in progress or queued in the transmit buffer.
257  * \return True (1) if the last transmission has completed, 0 if not.
258  */
259 #define IS_TRANSMIT_COMPLETE_UART3() U3STAbits.TRMT
260 
261 /** Waits until all characters placed in the UART have been sent. */
262 inline static void WAIT_UNTIL_TRANSMIT_COMPLETE_UART3() {
263  while (!IS_TRANSMIT_COMPLETE_UART3())
264  doHeartbeat();
265 }
266 
267 void outChar3(uint8_t u8_c);
268 uint8_t inChar3(void);
269 void configUART3(uint32_t u32_baudRate);
270 uint8_t isCharReady3(void);
271 void checkRxErrorUART3(void); //check for UART RX error
272 
273 #endif // #if (NUM_UART_MODS >= 3)
274 #endif // #ifndef _PIC24_UART3_H_
275 
276 
277 
278 
279 
280 
281 
282 
283 /*
284  * "Copyright (c) 2008 Robert B. Reese, Bryan A. Jones, J. W. Bruce ("AUTHORS")"
285  * All rights reserved.
286  * (R. Reese, reese_AT_ece.msstate.edu, Mississippi State University)
287  * (B. A. Jones, bjones_AT_ece.msstate.edu, Mississippi State University)
288  * (J. W. Bruce, jwbruce_AT_ece.msstate.edu, Mississippi State University)
289  *
290  * Permission to use, copy, modify, and distribute this software and its
291  * documentation for any purpose, without fee, and without written agreement is
292  * hereby granted, provided that the above copyright notice, the following
293  * two paragraphs and the authors appear in all copies of this software.
294  *
295  * IN NO EVENT SHALL THE "AUTHORS" BE LIABLE TO ANY PARTY FOR
296  * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
297  * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE "AUTHORS"
298  * HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
299  *
300  * THE "AUTHORS" SPECIFICALLY DISCLAIMS ANY WARRANTIES,
301  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
302  * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
303  * ON AN "AS IS" BASIS, AND THE "AUTHORS" HAS NO OBLIGATION TO
304  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
305  *
306  * Please maintain this header in its entirety when copying/modifying
307  * these files.
308  *
309  *
310  */
311 
312 
313 #ifndef _PIC24_UART4_H_
314 #define _PIC24_UART4_H_
315 
316 #include <stdint.h>
317 #include "pic24_chip.h"
318 #include "pic24_libconfig.h"
319 #include "pic24_util.h"
320 
321 // Only include if this UART module exists.
322 #if (NUM_UART_MODS >= 4)
323 
324 // Documentation for this file. If the \file tag isn't present,
325 // this file won't be documented.
326 // Note: place this comment below the #if NUM_UART_MODS so Doxygen
327 // will only see it once.
328 /** \file
329  * This file contains routines which configure and
330  * use the UARTs on the PIC. See \ref pic24_serial.h
331  * for higher-level routines, which should typically
332  * be called by the user rather than these routines.
333  */
334 
335 
336 /** Determine if a character is available in the UART's
337  * receive buffer.
338  * \return True (1) if character is available, 0 if not.
339  */
340 #define IS_CHAR_READY_UART4() U4STAbits.URXDA
341 
342 /** Determine if a the transmit buffer is full.
343  * \return True (1) if the transmit buffer if full,
344  * false (0) if not.
345  */
346 #define IS_TRANSMIT_BUFFER_FULL_UART4() U4STAbits.UTXBF
347 
348 /** Determines if all characters placed in the UART have been sent.
349  * Returns 1 if the last transmission has completed, or 0 if a transmission
350  * is in progress or queued in the transmit buffer.
351  * \return True (1) if the last transmission has completed, 0 if not.
352  */
353 #define IS_TRANSMIT_COMPLETE_UART4() U4STAbits.TRMT
354 
355 /** Waits until all characters placed in the UART have been sent. */
356 inline static void WAIT_UNTIL_TRANSMIT_COMPLETE_UART4() {
357  while (!IS_TRANSMIT_COMPLETE_UART4())
358  doHeartbeat();
359 }
360 
361 void outChar4(uint8_t u8_c);
362 uint8_t inChar4(void);
363 void configUART4(uint32_t u32_baudRate);
364 uint8_t isCharReady4(void);
365 void checkRxErrorUART4(void); //check for UART RX error
366 
367 #endif // #if (NUM_UART_MODS >= 4)
368 #endif // #ifndef _PIC24_UART4_H_
369 
370 
371 
372 
373 
374 
375 
376