Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
learn:courses:unit-4-2:start [2017/03/21 22:43] – [6.4. UART Software] Marthalearn: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 === +[[{}/learn/courses/unit-4-1/start|Back to Unit Part 1]]
-  * [[https://reference.digilentinc.com/learn/courses/unit-4-lab4c/start|Lab 4c]] +
-  * [[https://reference.digilentinc.com/learn/courses/unit-4-lab4d/start|Lab 4d]]+
  
 +  * [[/learn/courses/unit-4-lab4a/start|Lab 4a]]
 +  * [[/learn/courses/unit-4-lab4b/start|Lab 4b]]
 +  * [[/learn/courses/unit-4-lab4c/start|Lab 4c]]
 +  * [[/learn/courses/unit-4-lab4d/start|Lab 4d]]
 === Download This Document === === Download This Document ===
-  * {{ :learn:courses:unit-4-2:unit_4_part_2.pdf |Unit 4 Part 2 PDF}}+{{ :learn:courses:unit-4-2:unit_4_part_2.pdf |Unit 4 Part 2 PDF}}
  
 ===== 1. Introduction ===== ===== 1. Introduction =====
Line 14: Line 16:
  
 ===== 2. Objectives: ===== ===== 2. Objectives: =====
-  Program the PIC32MX370 to use the Universal Asynchronous Receiver Transmitter ([[https://en.wikipedia.org/wiki/Universal_asynchronous_receiver/transmitter|UART]]) serial communications to display data on a computer using a terminal emulation program. +  Program the PIC32MX370 to use the Universal Asynchronous Receiver Transmitter ([[https://en.wikipedia.org/wiki/Universal_asynchronous_receiver/transmitter|UART]]) serial communications to display data on a computer using a terminal emulation program. 
-  Control the stepper motor speed and direction of rotation using commands entered from a [[https://en.wikipedia.org/wiki/Terminal_emulator|terminal emulation]] program. +  Control the stepper motor speed and direction of rotation using commands entered from a [[https://en.wikipedia.org/wiki/Terminal_emulator|terminal emulation]] program. 
-  Display serial communications on the LCD and PC terminal.+  Display serial communications on the LCD and PC terminal.
  
 ---- ----
  
 ===== 3. Basic Knowledge: ===== ===== 3. Basic Knowledge: =====
-  How to map PIC32MX370 I/O pins to special function registers. +  How to map PIC32MX370 I/O pins to special function registers. 
-  How to initialize special functions using the PLIB functions. +  How to initialize special functions using the PLIB functions. 
  
 ---- ----
Line 29: Line 31:
 ===== 4. Unit Equipment List ===== ===== 4. Unit Equipment List =====
 ==== 4.1. Hardware ==== ==== 4.1. Hardware ====
-  [[http://store.digilentinc.com/basys-mx3-pic32mx-trainer-board-recommended-for-embedded-systems-courses/|Basys MX3 trainer board]] +  [[https://digilent.com/shop/basys-mx3-pic32mx-trainer-board-for-embedded-systems-courses/|Basys MX3 trainer board]] 
-  2 [[http://store.digilentinc.com/usb-a-to-micro-b-cable/|Micro USB cables]] +  2 [[https://digilent.com/shop/usb-a-to-micro-b-cable/|Micro USB cables]] 
-  Workstation computer running Windows 10 or higher, MAC OS, or Linux +  Workstation computer running Windows 10 or higher, MAC OS, or Linux 
-  4-wire stepper motor (Lab 4b only) +  - [[https://digilent.com/shop/stepper-motor/|4-wire stepper motor]] (Lab 4b only) 
-  [[http://store.digilentinc.com/5v-2-5a-switching-power-supply/|5V, 2.5A DC power supply]] (Lab 4b only)+  [[https://digilent.com/shop/5v-4a-switching-power-supply/|5V, 4A DC power supply]] (Lab 4b only)
  
 In addition, we suggest the following instruments: In addition, we suggest the following instruments:
-  [[http://store.digilentinc.com/analog-discovery-2-100msps-usb-oscilloscope-logic-analyzer-and-variable-power-supply/|Digilent Analog Discovery 2]]+  [[https://digilent.com/shop/analog-discovery-2-100ms-s-usb-oscilloscope-logic-analyzer-and-variable-power-supply/|Digilent Analog Discovery 2]]
  
 ==== 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:
-  [[http://www.microchip.com/mplab/mplab-x-ide|Microchip MPLAB X® v3.35 or higher]] +  [[http://www.microchip.com/mplab/mplab-x-ide|Microchip MPLAB X® v3.35 or higher]] 
-  [[http://www.microchip.com/SWLibraryWeb/product.aspx?product=PIC32%20Peripheral%20Library|PLIB Peripheral Library]] +  [[http://www.microchip.com/SWLibraryWeb/product.aspx?product=PIC32%20Peripheral%20Library|PLIB Peripheral Library]] 
-  [[http://www.microchip.com/xcdemo/xcpluspromo.aspx|XC32 Cross Compiler] +  [[http://www.microchip.com/xcdemo/xcpluspromo.aspx|XC32 Cross Compiler] 
-  [[http://store.digilentinc.com/waveforms-2015-download-only/|WaveForms 2015]] +  [[https://digilent.com/shop/software/digilent-waveforms/|WaveForms]] 
-  [[http://www.putty.org/|PuTTY Terminal Emulator]]+  [[http://www.putty.org/|PuTTY Terminal Emulator]]
  
 ---- ----
  
 ===== 5. Project Takeaways ===== ===== 5. Project Takeaways =====
-  Understanding of the basics of telecommunications. +  Understanding of the basics of telecommunications. 
-  Understanding of requirements and implementations of asynchronous communications.  +  Understanding of requirements and implementations of asynchronous communications.  
-  Application of asynchronous communications+  Application of asynchronous communications
     * 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://www.techopedia.com/definition/12829/human-machine-interface-hmi|human-machine interface]] (HMI).     * How to use the UART for diagnostics and as a [[https://www.techopedia.com/definition/12829/human-machine-interface-hmi|human-machine interface]] (HMI).
-  How to recognize the handshaking methods used in a communications protocol. +  How to recognize the handshaking methods used in a communications protocol. 
-  How to setup the Analog Discovery 2 to display UART waveforms.+  How to setup the Analog Discovery 2 to display UART waveforms.
  
  
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://www.cse.wustl.edu/~jain/cis677-96/ftp/e_6com2.pdf|parity bit]] is used for error detection and can be set for even parity or odd parity. For even parity, the parity bit is set high if the number of ones in the preceding eight data bits are odd, thus making the total number of 1’s in the data plus parity bit even. Conversely, for odd parity, the parity bit is set high if the number of ones in the 8 data is even. The data byte is terminated with one or more successive stop bits. Stop bits are always a logic 1 or high voltage level. If the signal remains high for longer than one symbol period, the stop bit can be thought of as the stop or idle period and the communications signal may remain in the idle condition an arbitrarily long period of time.   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://www.cse.wustl.edu/~jain/cis677-96/ftp/e_6com2.pdf|parity bit]] is used for error detection and can be set for even parity or odd parity. For even parity, the parity bit is set high if the number of ones in the preceding eight data bits are odd, thus making the total number of 1’s in the data plus parity bit even. Conversely, for odd parity, the parity bit is set high if the number of ones in the 8 data is even. The data byte is terminated with one or more successive stop bits. Stop bits are always a logic 1 or high voltage level. If the signal remains high for longer than one symbol period, the stop bit can be thought of as the stop or idle period and the communications signal may remain in the idle condition an arbitrarily long period of time.  
  
-{{ :learn:courses:unit-4-2:part2-fig-6-1.png?nolink&400 |Figure 6.1. Example of 115 kB asynchronous serial data stream with odd parity.}}+{{ :learn:courses:unit-4-2:part2-fig-6-1.png?nolink&700 |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.// //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<3:0>         | 0000 = RPD1\\ 0001 = RPG9\\ 0010 = RPB14\\ 0011 = RPD0\\ 0100 = RPD8\\ 0101 = RPB6\\ 0110 = RPD5\\ 0111 = RPB2\\ 1000 = RPF3<sup>(4)</sup>\\ 1001 = RPF13(3)\\ 1010 = Reserved\\ 1011 = RPF2<sup>(1)</sup>\\ 1100 = RPC2<sup>(3)</sup>\\ 1101 = RPE8<sup>(3)</sup>\\ 1110 = Reserved\\ 1111 = Reserved  |+| INT1            | INT1R            | INTR<3:0>         | 0000 = RPD1\\ 0001 = RPG9\\ 0010 = RPB14\\ 0011 = RPD0\\ 0100 = RPD8\\ 0101 = RPB6\\ 0110 = RPD5\\ 0111 = RPB2\\ 1000 = RPF3<sup>(4)</sup>\\ 1001 = RPF13<sup>(3)</sup>\\ 1010 = Reserved\\ 1011 = RPF2<sup>(1)</sup>\\ 1100 = RPC2<sup>(3)</sup>\\ 1101 = RPE8<sup>(3)</sup>\\ 1110 = Reserved\\ 1111 = Reserved  |
 | T3CK            | T3CKR            | T3CKR<3:0>        | :::                                                                                                                                                                                                                                                         | | T3CK            | T3CKR            | T3CKR<3:0>        | :::                                                                                                                                                                                                                                                         |
 | IC1             | IC1R             | IC1R<3:0>         | :::                                                                                                                                                                                                                                                         | | IC1             | IC1R             | IC1R<3:0>         | :::                                                                                                                                                                                                                                                         |
Line 105: Line 107:
 | OCFA            | OCFAR            | OCFAR<3:0>        | :::                                                                                                                                                                                                                                                         | | OCFA            | OCFAR            | OCFAR<3:0>        | :::                                                                                                                                                                                                                                                         |
  
----- 
  
-===== 7Background Information ===== +**Table 6.2PPS mapping of PIC32 port F pin 12 to UART 4 transmit adapted from [[http://ww1.microchip.com/downloads/en/DeviceDoc/60001185E.pdf|PIC32MX330/350/370/430/450/470]] Family Data SheetTable 12-2
-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 correctlyHowever, 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 wordWith synchronous communication, you would establish with your listener that you were speaking English, that you will be speaking words at measured intervals, and that you would utter a complete sentence, or paragraph, or extended soliloquy, before pausing to confirm understandingFurther, you would establish with your listener beforehand that any extraneous noises you make during the speech or between speeches (coughing, burping, and hiccupping) should be ignoredClearly the second approach is much faster, even though initializing communication may take slightly longer. In fact, by replacing the start, stop, and parity bits around individual words with start, stop, and control (processing instructions and error checking) sequences around large continuous data blocks, synchronous communication is about 30% faster than asynchronous communicationbefore any other factors are considered.+
  
-Synchronous vs. asynchronous communications pertain to the individual [[https://en.wikipedia.org/wiki/Symbol_rate|symbol]] or bit timing and is controlled at layer 1 in the OSI model. Synchronous serial communication describes a [[https://en.wikipedia.org/wiki/Serial_communication|serial communication]] [[https://en.wikipedia.org/wiki/Communications_protocol|protocol]] in which "data is sent in a continuous stream at a constant rate.”((https://en.wikipedia.org/wiki/Synchronous_serial_communication#cite_note-1))+^ 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<3:0>   | :::                                                                                                                                                                                                                                                                                               | 
 +| RPB15                | RPB15R    | RPB15R<3:0>  | :::                                                                                                                                                                                                                                                                                               | 
 +| RPD4                 | RPD4R     | RPD4R<3:0>   | :::                                                                                                                                                                                                                                                                                               | 
 +| RPB0                 | RPB0R     | RPB0R<3:0>   | :::                                                                                                                                                                                                                                                                                               | 
 +| RPE3                 | RPE3R     | RPE3R<3:0>   | :::                                                                                                                                                                                                                                                                                               | 
 +| RPB7                 | RPB7R     | RPB7R<3:0>   | :::                                                                                                                                                                                                                                                                                               | 
 +| RPB2                 | RPB2R     | RPB2R<3:0>   | :::                                                                                                                                                                                                                                                                                               | 
 +| RPF12<sup>(4)</sup>  RPF12R    | RPF12R<3:0>  | :::                                                                                                                                                                                                                                                                                               | 
 +| RPD12<sup>(4)</sup>  RPD12R    | RPD12R<3:0>  | :::                                                                                                                                                                                                                                                                                               | 
 +| RPF8<sup>(4)</sup>   | RPF8R     | RPF8R<3:0>   | :::                                                                                                                                                                                                                                                                                               | 
 +| RPC3<sup>(4)</sup>   | RPC3R     | RPC3R<3:0>   | :::                                                                                                                                                                                                                                                                                               | 
 +| RPE9<sup>(4)</sup>   | RPE9R     | RPE9R<3:0>   | :::                                                                                                                                                                                                                                                                                               |
  
-Synchronous communication requires that the [[https://en.wikipedia.org/wiki/Clock_signal|clocks]] in the transmitting and receiving devices are synchronized – running at the same rate – so the receiver can sample the signal at the same time intervals used by the transmitter. No start or stop bits are required. For this reason, "synchronous communication permits more information to be passed over a circuit per unit time" than [[https://en.wikipedia.org/wiki/Asynchronous_serial_communication|asynchronous serial communication]]. Over time the transmitting and receiving clocks will tend to drift apart.+  - 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 devices.  
 +  - This selection is not available when USBID functionality is used.
  
-==== 7.1. Asynchronous Digital Communications ==== 
-In telecommunications, asynchronous communication is transmission of data, generally without the use of an external clock signal, where data can be transmitted intermittently rather than in a steady stream. Any timing required to recover data from the communication symbols is encoded within the symbols. One characteristic of asynchronous communications is that data is formed in units of transmission with well-defined size (number of bits) and [[https://en.wikipedia.org/wiki/Symbol_rate|symbol rate]]. Since over time the transmitting and receiving clocks will tend to drift apart resynchronization is required. The resynchronization is accomplished using a “START” symbol while the units of transmission are framed between a START and STOP symbol. The timing between units of transmission is arbitrary depending on the application requirements. Unit 4 Part 2 along with Lab 4a and Lab 4b explore asynchronous communication concepts and applications further.  
  
-==== 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://en.wikipedia.org/wiki/Serial_communication|serial communication]] [[https://en.wikipedia.org/wiki/Communications_protocol|protocol]] in which "data is sent in a continuous stream at a constant rate." Synchronous communication requires that the [[https://en.wikipedia.org/wiki/Clock_signal|clocks]] in the transmitting and receiving devices are synchronized – running at the same rate – so the receiver can sample the signal at the same time intervals used by the transmitter. No START or STOP bits are required. The message framing is accomplished using a separate handshaking device select signal. The processor manages the data stream in units of transmission based on a pre-assigned number of bitsAll PIC32 processors can be configured for 816, or 32-bit transmission units. The net result is that synchronous communication permits more information to be passed over a circuit per unit time than [[https://en.wikipedia.org/wiki/Asynchronous_serial_communication|asynchronous serial communication]]+
  
-The synchronous communications circuit uses separate clock signal or embeds the clock signal inside the data bit waveformIn either case, the clock implements handshaking and indicates when the receiving device should sample the input to determine the symbol value. As such, each symbol can have differing and arbitrary periods As you will see in Lab 4d, the I2C protocol uses a 9-bit partition for each data byte (8 bits of information). The example explored in Lab 4c uses the SPI protocol, which segments the data stream into 8-bit data bytes+Listing B.3 and B.4 show the code for sending and receiving single character. These functions are non-blocking, unlike the “_mon_putc” function in Listing B.2. Hence, the calling function is responsible for verifying that the “putcU4” and “getcU4” functions have completed the requested action by returning a logical TRUE (non-zero value)Non-blocking communications allow the microprocessor to service other tasks that may have more critical timing requirements. In both the non-blocking and blocking functions, the completion of the task depends on the completion of some of the actionWhen sending data, the processor must wait until the UART has shifted out all the bits of the data byte. When receiving data, the processor must wait on the sending device. Both the “putcU4” and the “getcU4” can be implemented in a blocking fashion by simply calling the function in a while loop, such as //while(!putchU4(ch));//. 
 + 
 +The primitive functions provided by the code in Listing B.1 through Listing B.4 provide the building blocks of asynchronous communications and will be used to complete the application assignment for Labs 4a and 4b. 
 + 
 +---- 
 + 
 +===== 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__, 1st Edition, by [[file://\\us-pul-fs1\Digilent\Marketing\Work\Wiki Material\_RWALL\Unit 3\Embedded Computing and Mechatronics with the PIC32 Microcontroller, 1st Edition, by Kevin Lynch (Author), Nicholas Marchuk (Author), Matthew Elwin (Author), https:\www.amazon.com\Embedded-Computing-Mechatronics-PIC32-Microcontroller\dp\0124201652|Kevin Lynch]] (Author), [[https://www.amazon.com/s/ref=dp_byline_sr_book_2?ie=UTF8&text=Nicholas+Marchuk&search-alias=books&field-author=Nicholas+Marchuk&sort=relevancerank|Nicholas Marchuk]] (Author), [[https://www.amazon.com/s/ref=dp_byline_sr_book_3?ie=UTF8&text=Matthew+Elwin&search-alias=books&field-author=Matthew+Elwin&sort=relevancerank|Matthew Elwin]] (Author), [[https://www.amazon.com/Embedded-Computing-Mechatronics-PIC32-Microcontroller/dp/0124201652|https://www.amazon.com/Embedded-Computing-Mechatronics-PIC32-Microcontroller/dp/0124201652]]  
-  - “PIC32MX330/350/370/430/4450/470 32 Bit Microcontroller Datasheet (60001185E)”, [[http://ww1.microchip.com/downloads/en/DeviceDoc/60001185E.pdf|http://ww1.microchip.com/downloads/en/DeviceDoc/60001185E.pdf]]  
-  - Serial Protocols Compared, [[http://www.embedded.com/design/connectivity/4023975/Serial-Protocols-Compared|http://www.embedded.com/design/connectivity/4023975/Serial-Protocols-Compared]]  
   - [[http://ww1.microchip.com/downloads/en/DeviceDoc/60001185E.pdf|PIC32MX330/350/370/430/450/470]] Family Data Sheet    - [[http://ww1.microchip.com/downloads/en/DeviceDoc/60001185E.pdf|PIC32MX330/350/370/430/450/470]] Family Data Sheet 
 +  - “Using the USART in Asynchronous Mode”, [[http://ww1.microchip.com/downloads/en/DeviceDoc/usart.pdf|http://ww1.microchip.com/downloads/en/DeviceDoc/usart.pdf]]
 +  - “Asynchronous Communications with the PICmicro® USART”, [[http://ww1.microchip.com/downloads/en/AppNotes/00774a.pdf|http://ww1.microchip.com/downloads/en/AppNotes/00774a.pdf]] 
 +  - [[http://en.wikipedia.org/wiki/RS-232|RS-232]], [[http://en.wikipedia.org/wiki/RS-422|RS-422]], [[http://www.arcelect.com/RS423.htm|RS-423]], [[http://www.idc-online.com/technical_references/pdfs/data_communications/tutorial_2.pdf|RS-485]] Asynchronous communications
 +  - __Embedded Computing and Mechatronics with the PIC32 Microcontroller__, 1st Edition, by [[https://www.amazon.com/s/ref=dp_byline_sr_book_1?ie=UTF8&text=Kevin+Lynch&search-alias=books&field-author=Kevin+Lynch&sort=relevancerank|Kevin Lynch]] (Author), [[https://www.amazon.com/s/ref=dp_byline_sr_book_2?ie=UTF8&text=Nicholas+Marchuk&search-alias=books&field-author=Nicholas+Marchuk&sort=relevancerank|Nicholas Marchuk]] (Author), [[https://www.amazon.com/s/ref=dp_byline_sr_book_3?ie=UTF8&text=Matthew+Elwin&search-alias=books&field-author=Matthew+Elwin&sort=relevancerank|Matthew Elwin]] (Author), [[https://www.amazon.com/Embedded-Computing-Mechatronics-PIC32-Microcontroller/dp/0124201652|https://www.amazon.com/Embedded-Computing-Mechatronics-PIC32-Microcontroller/dp/0124201652]] 
 +  - “PIC32MX330/350/370/430/4450/470 32 Bit Microcontroller Datasheet (60001185E)”, [[http://ww1.microchip.com/downloads/en/DeviceDoc/60001185E.pdf|http://ww1.microchip.com/downloads/en/DeviceDoc/60001185E.pdf]] 
 +  - “Using the USART in Asynchronous Mode”, [[http://ww1.microchip.com/downloads/en/DeviceDoc/usart.pdf|http://ww1.microchip.com/downloads/en/DeviceDoc/usart.pdf]]
  
  
 ---- ----
  
-===== Appendix A: Unit 4 Parts Configuration ===== +===== Appendix A: Unit 4 Part 2 Parts Configuration ===== 
-{{ :learn:courses:unit-4-1:unit_4_-_photo_1.jpg?nolink&400 |Figure A.1. Unit 4 hardware and instrumentation configuration.}} +{{ :learn:courses:unit-4-2:part2-fig-a-1.png?nolink&700 |Figure A.1. PIC32 to FT232RQR IC schematic diagram.}} 
-//Figure A.1. Unit 4 hardware and instrumentation configuration.//+//Figure A.1. PIC32 to FT232RQR IC schematic diagram.// 
 + 
 +{{ :learn:courses:unit-4-2:unit_4_-_photo_1.jpg?nolink&400 |Figure A.2. Unit 4 hardware and instrumentation configuration.}} 
 +//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/wiki/Morse_code|Morse code]] [[http://en.wikipedia.org/wiki/Telegraphy|telegraphy]]  +==== Listing B.1C Function that Initializes PF12 and PF13 to UART 4 ==== 
-  * [[http://en.wikipedia.org/wiki/RS-232|RS-232]][[http://en.wikipedia.org/wiki/RS-422|RS-422]][[http://www.arcelect.com/RS423.htm|RS-423]][[http://www.idc-online.com/technical_references/pdfs/data_communications/tutorial_2.pdf|RS-485]] Asynchronous communications (Project 7+<code
-  * [[http://www.computer-solutions.co.uk/info/Embedded_tutorials/can_tutorial.htm|CAN]] [[http://en.wikipedia.org/wiki/CAN_bus|Controller Area Network]] +void uart_init(unsigned int baud, int parity) 
-  * [[https://en.wikipedia.org/wiki/Local_Interconnect_Network|LIN]] Local Interconnect Network +
-  * [[http://www.best-microcontroller-projects.com/i2c-tutorial.html|I²C]] [[http://en.wikipedia.org/wiki/I%C2%B2C|Inter-Integrated Circuit]] +// The next two statements map the PPS IO pins to the UART 4 Tx and Rx 
-  * [[http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus|SPI]] [[http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus|Serial Peripheral Interface]] +   RPF12R = 0x02;  // Mapping U4TX to RPF12; 
-  * [[http://en.wikipedia.org/wiki/High-Level_Data_Link_Control|SDLC/HDLC]] High Level Data Link Control ([[http://www.ite.org/standards/atc/its_cabinet_v01.02.17a.doc|Traffic Control]]+   U4RXR = 0x09;   // Mapping U4RX to RPF13 
-  [[http://www.maxim-ic.com/products/1-wire/flash/overview/index.cfm|1-wire]] [[https://en.wikipedia.org/wiki/1-Wire|i-Button]] + 
-  * [[http://en.wikipedia.org/wiki/ARINC_818|ARINC 818]] Avionics Digital Video Bus +   UARTConfigure(UART4UART_ENABLE_PINS_TX_RX_ONLY ); 
-  * [[http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=2680&dDocName=en537044|USB]] [[http://en.wikipedia.org/wiki/Universal_Serial_Bus|Universal Serial Bus]] (moderate-speed, for connecting peripherals to computers+   UARTSetDataRate(UART4GetPeripheralClock()baud); // Set UART data rate 
-  * [[http://en.wikipedia.org/wiki/FireWire|FireWire]] IEEE 1394 +// Note the need to specify the UART number twice in the following statement 
-  * [[http://en.wikipedia.org/wiki/Ethernet|Ethernet]] IEEE 802.3 +   UARTEnable(UART4, UART_ENABLE_FLAGS(UART_ENABLE | UART4 | UART_RX UART_TX));   
-  [[http://en.wikipedia.org/wiki/Fibre_Channel|Fiber Channel]] (high-speed, for connecting computers to mass storage devices) +   switch(parity
-  [[http://en.wikipedia.org/wiki/InfiniBand|InfiniBand]] (very high speed, broadly comparable in scope to PCI+   { 
-  [[http://en.wikipedia.org/wiki/MIDI|MIDI]] control of electronic musical instruments +       case NO_PARITY: 
-  [[http://en.wikipedia.org/wiki/DMX512|DMX512]] control of theatrical lighting +           UARTSetLineControl(UART4, UART_DATA_SIZE_8_BITS UART_PARITY_NONE |\ 
-  * [[http://en.wikipedia.org/wiki/SDI-12|SDI-12]] industrial sensor protocol +                              UART_STOP_BITS_1); 
-  * [[http://en.wikipedia.org/wiki/SpaceWire|SpaceWire]] Spacecraft communication network+           break; 
 +       case ODD_PARITY
 +           UARTSetLineControl(UART4, UART_DATA_SIZE_8_BITS UART_PARITY_ODD |\   
 +                              UART_STOP_BITS_1); 
 +           break; 
 +       case EVEN_PARITY: 
 +           UARTSetLineControl(UART4, UART_DATA_SIZE_8_BITS UART_PARITY_EVEN |
 +                              UART_STOP_BITS_1); 
 +           break; 
 +   } 
 +   printf("\n\rUART Serial Port 4 ready\n\n\r"); 
 +</code> 
 + 
 +==== Listing B.2C code to allow the “printf” output to be redirected to UART 4 ====  
 +<code> 
 +void _mon_putc(char c
 +
 +   while(!UARTTransmitterIsReady(UART4)); 
 +   UARTSendDataByte(UART4, c); 
 +} /* End of _mon_putc */ 
 +</code> 
 + 
 +==== Listing B.3C Code for Sending a Single Character to UART 4 ==== 
 +<code> 
 +BOOL putcU4( int ch
 +
 +UART_DATA c; 
 +BOOL done = FALSE; 
 +   c.data8bit = (char) ch; 
 +   if(UARTTransmitterIsReady(UART4)) 
 +   { 
 +    UARTSendDataByte(UART4, c.data8bit); 
 + done = TRUE; 
 +   } 
 +  return done; 
 +} /* End of putU4 */ 
 +</code> 
 + 
 +==== Listing B.4C Code for Receiving a Single Character from UART 4 ==== 
 +<code> 
 +BOOL getcU4( char *ch) 
 +
 +UART_DATA c; 
 +BOOL done = FALSE; 
 +   if(UARTReceivedDataIsAvailable(UART4)) /* wait for new char to arrive */ 
 +   { 
 +       c = UARTGetData(UART4); /* read the char from receive buffer */ 
 +       *ch = (c.data8bit); 
 +       done = TRUE; /* Return new data available flag */ 
 +   } 
 +   return done;           /* Return new data not available flag */ 
 +}/* End of getU4 */ 
 +</code> 
 + 
 +----
  
 +===== Appendix C: Common Definitions =====
 +  - UART: A Universal Asynchronous Receiver/Transmitter, abbreviated UART, is a type of “asynchronous receiver/transmitter,” a piece of computer hardware that translates data between parallel and serial forms. UARTs are commonly used in conjunction with communications standards such as [[http://en.wikipedia.org/wiki/Electronic_Industries_Alliance|EIA]], [[http://en.wikipedia.org/wiki/RS-232|RS-232]], [[http://en.wikipedia.org/wiki/RS-422|RS-422]], or [[http://en.wikipedia.org/wiki/RS-485|RS-485]] that describe physical layers. 
 +  - 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.
  
 ---- ----
 +[[{}/learn/courses/unit-4-1/start|Back to Unit 4 Part 1]]
 +[[{}/learn/courses/unit-4-lab4a/start|Go to Lab 4a]]
 +[[{}/learn/courses/unit-4-lab4b/start|Go to Lab 4b]]
 +[[{}/learn/courses/unit-4-lab4c/start|Go to Lab 4c]]
 +[[{}/learn/courses/unit-4-lab4d/start|Go to Lab 4d]]
 +[[{}/learn/courses/unit-5/start|Go to Unit 5]]
  
 {{tag>reference learn microprocessor courses basys-mx3}} {{tag>reference learn microprocessor courses basys-mx3}}