Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
learn:courses:unit-4-2:start [2017/03/21 22:43] – [6.4. UART Software] Martha | learn:courses:unit-4-2:start [2021/10/13 22:27] (current) – Arthur Brown | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== Unit 4 Part 2: Communications - Asynchronous Serial Protocols ====== | ====== Unit 4 Part 2: Communications - Asynchronous Serial Protocols ====== | ||
- | === Unit 4 Part 2 Labs === | + | [[{}/ |
- | * [[https:// | + | |
- | * [[https:// | + | |
+ | * [[/ | ||
+ | * [[/ | ||
+ | * [[/ | ||
+ | * [[/ | ||
=== Download This Document === | === Download This Document === | ||
- | * {{ : | + | {{ : |
===== 1. Introduction ===== | ===== 1. Introduction ===== | ||
Line 14: | Line 16: | ||
===== 2. Objectives: ===== | ===== 2. Objectives: ===== | ||
- | | + | |
- | | + | |
- | | + | |
---- | ---- | ||
===== 3. Basic Knowledge: ===== | ===== 3. Basic Knowledge: ===== | ||
- | | + | |
- | | + | |
---- | ---- | ||
Line 29: | Line 31: | ||
===== 4. Unit Equipment List ===== | ===== 4. Unit Equipment List ===== | ||
==== 4.1. Hardware ==== | ==== 4.1. Hardware ==== | ||
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
In addition, we suggest the following instruments: | In addition, we suggest the following instruments: | ||
- | | + | |
==== 4.2. Software ==== | ==== 4.2. Software ==== | ||
The following programs must be installed on your development work station: | The following programs must be installed on your development work station: | ||
- | | + | |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
---- | ---- | ||
===== 5. Project Takeaways ===== | ===== 5. Project Takeaways ===== | ||
- | | + | |
- | | + | |
- | | + | |
* Knowledge of a PC terminal emulation program. | * Knowledge of a PC terminal emulation program. | ||
* How to develop a library of PIC32 software to provide bi-directional communications of single characters and strings of characters. | * How to develop a library of PIC32 software to provide bi-directional communications of single characters and strings of characters. | ||
* How to use the UART for diagnostics and as a [[https:// | * How to use the UART for diagnostics and as a [[https:// | ||
- | | + | |
- | | + | |
Line 71: | Line 73: | ||
Figure 6.1 shows a typical asynchronous transmission of two 8-bit data bytes. We see that the idle state of the transmit signal is a logic one, or a high voltage level. A START bit is signified by a high to low transition and remains low for one symbol time. The START bit is followed by eight data bits with the least significant bit being sent first. A logic zero is sent when the signal is a low voltage level for one symbol time. Similarly, a logic one is sent when the signal is a high voltage level for one symbol time. After the transmitting of the data there may be an optional parity bit. The [[http:// | Figure 6.1 shows a typical asynchronous transmission of two 8-bit data bytes. We see that the idle state of the transmit signal is a logic one, or a high voltage level. A START bit is signified by a high to low transition and remains low for one symbol time. The START bit is followed by eight data bits with the least significant bit being sent first. A logic zero is sent when the signal is a low voltage level for one symbol time. Similarly, a logic one is sent when the signal is a high voltage level for one symbol time. After the transmitting of the data there may be an optional parity bit. The [[http:// | ||
- | {{ : | + | {{ : |
//Figure 6.1. Example of 115 kB asynchronous serial data stream with odd parity.// | //Figure 6.1. Example of 115 kB asynchronous serial data stream with odd parity.// | ||
Line 96: | Line 98: | ||
^ Peripheral Pin ^ [pin name]R SFR ^ [pin name]R bits ^ [pin names]R Value to RPn Pin Selection | ^ Peripheral Pin ^ [pin name]R SFR ^ [pin name]R bits ^ [pin names]R Value to RPn Pin Selection | ||
- | | INT1 | INT1R | INTR< | + | | INT1 | INT1R | INTR< |
| T3CK | T3CKR | T3CKR< | | T3CK | T3CKR | T3CKR< | ||
| IC1 | IC1R | IC1R< | | IC1 | IC1R | IC1R< | ||
Line 105: | Line 107: | ||
| OCFA | OCFAR | OCFAR< | | OCFA | OCFAR | OCFAR< | ||
- | ---- | ||
- | ===== 7. Background Information ===== | + | **Table 6.2. PPS mapping |
- | The theory behind asynchronous and synchronous communication is essentially the same: Point B needs to know when a transmission from Point A begins, when it ends, and if it was processed correctly. However, the difference lies in how the transmission is broken down. Think of the difference in terms of a friendly chat. With asynchronous communication you would need to stop after every word to make sure the listener understood your meaning, and knew that you were about to speak the next word. With synchronous communication, | + | |
- | Synchronous vs. asynchronous communications pertain | + | ^ RPn Port Pin ^ RPnR SFR ^ RPnR bits ^ RPnR Value to Peripheral Seleciton |
+ | | RPD9 | RPD9R | RPD9R<3:0> | 0000 = No Connect\\ 0001 = $\overline{(U3RTS)}$\\ 0010 = U4TX\\ 0011 = REFCLKO\\ 0100 = U5TX\\ 0101 = Reserved\\ 0110 = Reserved\\ 0111 = $\overline{(SS1)}$\\ 1000 = SDO1\\ 1001 = Reserved\\ 1010 = Reserved\\ 1011 = OC5\\ 1100 = Reserved\\ 1101 = C1OUT\\ 1110 = Reserved\\ 1111 = Reserved | ||
+ | | RPG6 | RPG6R | RPG6R<3:0> | ::: | | ||
+ | | RPB8 | RPB8R | RPB8R< | ||
+ | | RPB15 | RPB15R | ||
+ | | RPD4 | RPD4R | RPD4R< | ||
+ | | RPB0 | RPB0R | RPB0R< | ||
+ | | RPE3 | RPE3R | RPE3R< | ||
+ | | RPB7 | RPB7R | RPB7R< | ||
+ | | RPB2 | RPB2R | RPB2R< | ||
+ | | RPF12< | ||
+ | | RPD12< | ||
+ | | RPF8< | ||
+ | | RPC3< | ||
+ | | RPE9< | ||
- | Synchronous communication requires that the [[https:// | + | - This selection is not available on 64-pin USB devices. |
+ | - This selection is only available on 100-pin General Purpose devices. | ||
+ | - This selection is not available on 64-pin General Purpose | ||
+ | - This selection is not available when USBID functionality is used. | ||
- | ==== 7.1. Asynchronous Digital Communications ==== | ||
- | In telecommunications, | ||
- | ==== 7.2. Synchronous Digital Communications ==== | + | The C language “printf” function will output text to UART 4 if the “mon_putc(char c)” function, as shown in Listing B.2, is added to the project. |
- | Synchronous serial communication describes a [[https:// | + | |
- | The synchronous communications circuit uses a separate clock signal or embeds | + | Listing B.3 and B.4 show the code for sending and receiving |
+ | |||
+ | The primitive functions provided by the code in Listing B.1 through Listing B.4 provide | ||
+ | |||
+ | ---- | ||
+ | |||
+ | ===== 7. Background Information ===== | ||
+ | See the general discussion concerning computer communications discussed in Unit 4 Part 1. | ||
---- | ---- | ||
===== 8. References ===== | ===== 8. References ===== | ||
- | - __Embedded Computing and Mechatronics with the PIC32 Microcontroller__, | ||
- | - “PIC32MX330/ | ||
- | - Serial Protocols Compared, [[http:// | ||
- [[http:// | - [[http:// | ||
+ | - “Using the USART in Asynchronous Mode”, [[http:// | ||
+ | - “Asynchronous Communications with the PICmicro® USART”, [[http:// | ||
+ | - [[http:// | ||
+ | - __Embedded Computing and Mechatronics with the PIC32 Microcontroller__, | ||
+ | - “PIC32MX330/ | ||
+ | - “Using the USART in Asynchronous Mode”, [[http:// | ||
---- | ---- | ||
- | ===== Appendix A: Unit 4 Parts Configuration ===== | + | ===== Appendix A: Unit 4 Part 2 Parts Configuration ===== |
- | {{ : | + | {{ : |
- | //Figure A.1. Unit 4 hardware and instrumentation configuration.// | + | //Figure A.1. PIC32 to FT232RQR IC schematic diagram.// |
+ | |||
+ | {{ : | ||
+ | //Figure A.2. Unit 4 hardware and instrumentation configuration.// | ||
---- | ---- | ||
- | ===== Appendix B: Partial List of Popular Serial Protocols | + | ===== Appendix B: Lab 4a and 4b UART Functions |
- | * [[http://en.wikipedia.org/ | + | ==== Listing B.1. C Function that Initializes PF12 and PF13 to UART 4 ==== |
- | | + | <code> |
- | * [[http:// | + | void uart_init(unsigned int baud, int parity) |
- | * [[https:// | + | { |
- | * [[http:// | + | // The next two statements map the PPS IO pins to the UART 4 Tx and Rx |
- | * [[http:// | + | RPF12R = 0x02; // |
- | * [[http://en.wikipedia.org/ | + | U4RXR = 0x09; // Mapping U4RX to RPF13 |
- | * [[http:// | + | |
- | * [[http:// | + | |
- | * [[http:// | + | |
- | * [[http://en.wikipedia.org/ | + | // Note the need to specify the UART number twice in the following statement |
- | * [[http://en.wikipedia.org/ | + | |
- | * [[http:// | + | |
- | | + | { |
- | * [[http://en.wikipedia.org/wiki/MIDI|MIDI]] control | + | case NO_PARITY: |
- | | + | |
- | * [[http:// | + | |
- | * [[http:// | + | |
+ | case ODD_PARITY: | ||
+ | UARTSetLineControl(UART4, | ||
+ | UART_STOP_BITS_1); | ||
+ | break; | ||
+ | case EVEN_PARITY: | ||
+ | | ||
+ | UART_STOP_BITS_1); | ||
+ | | ||
+ | } | ||
+ | | ||
+ | </code> | ||
+ | |||
+ | ==== Listing B.2. C code to allow the “printf” output to be redirected to UART 4 ==== | ||
+ | < | ||
+ | void _mon_putc(char c) | ||
+ | { | ||
+ | | ||
+ | | ||
+ | } /* End of _mon_putc | ||
+ | </code> | ||
+ | |||
+ | ==== Listing B.3. C Code for Sending a Single Character | ||
+ | < | ||
+ | BOOL putcU4( int ch) | ||
+ | { | ||
+ | UART_DATA c; | ||
+ | BOOL done = FALSE; | ||
+ | c.data8bit = (char) ch; | ||
+ | | ||
+ | { | ||
+ | | ||
+ | done = TRUE; | ||
+ | } | ||
+ | | ||
+ | } /* End of putU4 */ | ||
+ | </code> | ||
+ | |||
+ | ==== Listing B.4. C Code for Receiving a Single Character from UART 4 ==== | ||
+ | < | ||
+ | BOOL getcU4( char *ch) | ||
+ | { | ||
+ | UART_DATA c; | ||
+ | BOOL done = FALSE; | ||
+ | if(UARTReceivedDataIsAvailable(UART4)) / | ||
+ | { | ||
+ | c = UARTGetData(UART4); | ||
+ | *ch = (c.data8bit); | ||
+ | done = TRUE; /* Return new data available flag */ | ||
+ | } | ||
+ | | ||
+ | }/* End of getU4 */ | ||
+ | </code> | ||
+ | |||
+ | ---- | ||
+ | ===== Appendix C: Common Definitions ===== | ||
+ | - UART: A Universal Asynchronous Receiver/ | ||
+ | - Communications Speed: BAUD is a unit used to measure the speed of signaling or data transfer, equal to the number of pulses or bits per second, or //baud rate//. | ||
+ | - Data Rate: Typical data rates are multiples of 120 BAUD to 115.2 KB. | ||
+ | - Stop Bits: Only one is necessary for the receiving device. The sending device has the option of sending one or two minimum stop bits. | ||
+ | - Bus Idle: This is the nominal state of the data signal when no data is being transmitted. The idle condition is a logic level 1 (or high condition). The bus idle condition is an extension of stop bits; however, the period bus idle condition may be any time duration. | ||
+ | - Parity: Used for single bit error detection. | ||
+ | - None – no error checking | ||
+ | - Even parity refers to a parity checking mode in asynchronous communication systems in which an extra bit, called a parity bit, is set to one if there is an odd number of one bits in a one-byte data item. | ||
+ | - Odd parity refers to a parity checking mode in asynchronous communication systems in which an extra bit, called a parity bit, is set to one if there is an even number of one bits in a one-byte data item. | ||
+ | - Information direction: | ||
+ | - Simplex – communications is one direction only | ||
+ | - Full-duplex – bi-directional simultaneous asynchronous communications | ||
+ | - Half-duplex – bi-directional exclusive communications. Devices can send and receive, but not simultaneously. | ||
---- | ---- | ||
+ | [[{}/ | ||
+ | [[{}/ | ||
+ | [[{}/ | ||
+ | [[{}/ | ||
+ | [[{}/ | ||
+ | [[{}/ | ||
{{tag> | {{tag> |