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