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-5:start [2017/03/24 12:58] – [Listing 7.1. Initialization of INT1] Marthalearn:courses:unit-5:start [2021/10/13 15:17] (current) Arthur Brown
Line 1: Line 1:
 ====== Unit 5: IrDA Communications Protocols ====== ====== Unit 5: IrDA Communications Protocols ======
 +[[{}/learn/courses/unit-4-1/start|Back to Unit 4 Part 1]]
 +[[{}/learn/courses/unit-4-2/start|Back to Unit 4 Part 2]]
 +
 === Unit 5 Lab === === Unit 5 Lab ===
-  * [[https://reference.digilentinc.com/learn/courses/unit-5-lab5a/start|Lab 5a]]+  * [[/learn/courses/unit-5-lab5a/start|Lab 5a]]
  
  
 === Download This Document === === Download This Document ===
-  * {{ :learn:courses:unit-5:unit_5.pdf |Unit 5 PDF}}+{{ :learn:courses:unit-5:unit_5.pdf |Unit 5 PDF}}
  
 ===== 1. Introduction ===== ===== 1. Introduction =====
Line 18: Line 21:
  
 ===== 2. Objectives: ===== ===== 2. Objectives: =====
-  Identify the IrDA protocol by capturing the bit stream on the IR_RX pin using the Analog Discovery 2. +  Identify the IrDA protocol by capturing the bit stream on the IR_RX pin using the Analog Discovery 2. 
-  Develop a C function that executes an algorithm to decode the IrDA bit stream. +  Develop a C function that executes an algorithm to decode the IrDA bit stream. 
-  Display the received codes on the LCD and send to the UART communications port.+  Display the received codes on the LCD and send to the UART communications port.
  
  
Line 26: Line 29:
  
 ===== 3. Basic Knowledge: ===== ===== 3. Basic Knowledge: =====
-  How to configure I/O pins on a Microchip® PIC32 PPS microprocessor.  +  How to configure I/O pins on a Microchip® PIC32 PPS microprocessor.  
-  How to configure the Analog Discovery 2 to display logic traces. +  How to configure the Analog Discovery 2 to display logic traces. 
-  How to implement the design process for embedded processor based systems.+  How to implement the design process for embedded processor based systems.
    
  
Line 36: Line 39:
 ===== 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]] 
-  [[http://store.digilentinc.com/usb-a-to-micro-b-cable/|Standard USB A to micro-B cable]] +  [[https://digilent.com/shop/usb-a-to-micro-b-cable/|Standard USB A to micro-B cable]] 
-  * Workstation computer running Windows 10 or higher, MAC OS, or Linux+  - Ordered List ItemWorkstation computer running Windows 10 or higher, MAC OS, or Linux
  
 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 IrDA protocols. +  Understanding of the basics of IrDA protocols. 
-  Using instrumentation to characterize data streams. +  Using instrumentation to characterize data streams. 
-  Use processor external interrupts to decode signal timing patterns. +  Use processor external interrupts to decode signal timing patterns. 
-  Approaches to using state machines to process data.+  Approaches to using state machines to process data.
  
  
Line 84: Line 87:
 The Basys MX3 platform is equipped with a Rohm RPM973-H11 infrared communications module that provides the digital interface, as shown in Fig. 7.1. The three microprocessor control pins shown in Fig. 7.2 are the IR_TX, IR_RX, and the IR_PDOWN. The Rohm RPM973-H11 is in a low power mode whenever the IR_PDOWN control signal is in the high state. The IR_PDOWN must be in a low state to transmit or receive infrared signals. Both IR_TX and IR_RX are [[https://en.wikipedia.org/wiki/Logic_level|active low]] signals. The Basys MX3 platform is equipped with a Rohm RPM973-H11 infrared communications module that provides the digital interface, as shown in Fig. 7.1. The three microprocessor control pins shown in Fig. 7.2 are the IR_TX, IR_RX, and the IR_PDOWN. The Rohm RPM973-H11 is in a low power mode whenever the IR_PDOWN control signal is in the high state. The IR_PDOWN must be in a low state to transmit or receive infrared signals. Both IR_TX and IR_RX are [[https://en.wikipedia.org/wiki/Logic_level|active low]] signals.
  
-{{ :learn:courses:unit-5:fig-7-1.png?nolink&600 |Figure 7.1. RPM973-H11 block diagram.}}+{{ :learn:courses:unit-5:fig-7-1.png?nolink&500 |Figure 7.1. RPM973-H11 block diagram.}}
 //Figure 7.1. RPM973-H11 block diagram.// //Figure 7.1. RPM973-H11 block diagram.//
  
-{{ :learn:courses:unit-5:fig-7-2.png?nolink&400 |Figure 7.2. Schematic diagram of PIC32 connection to the RPM841-H11 Infrared Module.}}+{{ :learn:courses:unit-5:unit_5_fig_7_2.jpg?nolink&500 |Figure 7.2. Schematic diagram of PIC32 connection to the RPM841-H11 Infrared Module.}}
 //Figure 7.2. Schematic diagram of PIC32 connection to the RPM841-H11 Infrared Module.// //Figure 7.2. Schematic diagram of PIC32 connection to the RPM841-H11 Infrared Module.//
  
Line 97: Line 100:
 Figure 7.3 shows that the IR LED modulation for a 38 kHz carrier is determined as the inverse of the period between LED pulses. The LED is only on for about 2.4 μs out of the 26.3 μs carrier frequency period. The duty cycle of the LED is less than 10% resulting in lower power consumption. Figure 7.3 shows that the IR LED modulation for a 38 kHz carrier is determined as the inverse of the period between LED pulses. The LED is only on for about 2.4 μs out of the 26.3 μs carrier frequency period. The duty cycle of the LED is less than 10% resulting in lower power consumption.
  
-{{ :learn:courses:unit-5:fig-7-3.png?nolink&600 |Figure 7.3. IrDA 38 kHz carrier signal.}}+ 
 +{{ :learn:courses:unit-5:unit_5_fig_7_3.png?nolink |Figure 7.3. IrDA 38 kHz carrier signal.}}
 //Figure 7.3. IrDA 38 kHz carrier signal.// //Figure 7.3. IrDA 38 kHz carrier signal.//
  
 Figure 7.4 shows a complete IrDA message using the NEC protocol. The signal is low whenever an infrared light is detected. The NEC protocol message contains 32 bits organized in eight bit bytes sent with LSB first. After a 9 ms leader and a 4.5 ms gap, a 560 μs bit marker signals the start of the LSB of the first data byte, as shown in Fig. 7.5.    Figure 7.4 shows a complete IrDA message using the NEC protocol. The signal is low whenever an infrared light is detected. The NEC protocol message contains 32 bits organized in eight bit bytes sent with LSB first. After a 9 ms leader and a 4.5 ms gap, a 560 μs bit marker signals the start of the LSB of the first data byte, as shown in Fig. 7.5.   
  
-{{ :learn:courses:unit-5:fig-7-4.png?nolink&600 |Figure 7.4. Screen capture of a NEC IrDA control message.}}+ 
 +{{ :learn:courses:unit-5:unit_5_fig_7_4.png?nolink |Figure 7.4. Screen capture of a NEC IrDA control message.}}
 //Figure 7.4. Screen capture of a NEC IrDA control message.// //Figure 7.4. Screen capture of a NEC IrDA control message.//
  
 Figures 7.5 and 7.6 show expanded views of portions of the NEC IrDA protocol, showing the sync followed by three of the 24 data bits. Note that the differentiation between a ONE bit and a ZERO bit is the length of the gap following each 560 μs period of 38 kHz modulated infrared pulses. The last byte contains 9 pulse bursts to allow the last bit to be framed correctly. Figures 7.5 and 7.6 show expanded views of portions of the NEC IrDA protocol, showing the sync followed by three of the 24 data bits. Note that the differentiation between a ONE bit and a ZERO bit is the length of the gap following each 560 μs period of 38 kHz modulated infrared pulses. The last byte contains 9 pulse bursts to allow the last bit to be framed correctly.
  
-{{ :learn:courses:unit-5:fig-7-5.png?nolink&600 |Figure 7.5. Details of the message leader and first three data bits.}}+{{ :learn:courses:unit-5:unit_5_fig_7_5.png?nolink |Figure 7.5. Details of the message leader and first three data bits.}}
 //Figure 7.5. Details of the message leader and first three data bits.// //Figure 7.5. Details of the message leader and first three data bits.//
  
-{{ :learn:courses:unit-5:fig-7-6.png?nolink&600 |Figure 7.6. 38 kHz pulse burst timing representing two ZERO bits and a ONE bit.}}+ 
 +{{ :learn:courses:unit-5:unit_5_fig_7_6.png?nolink |Figure 7.6. 38 kHz pulse burst timing representing two ZERO bits and a ONE bit.}}
 //Figure 7.6. 38 kHz pulse burst timing representing two ZERO bits and a ONE bit.// //Figure 7.6. 38 kHz pulse burst timing representing two ZERO bits and a ONE bit.//
 +
  
 Figures in Reference 4 are reproduced below to illustrate the timing of the NEC protocol. The encoding of an NEC protocol message in Fig. 7.7 shows that the entire packet consists of two bytes of data: the address byte and the command byte. Each byte is followed by its [[https://en.wikipedia.org/wiki/Ones%27_complement|one’s complement]]. The consequence of this encoding is that although the time to transmit a ONE bit is twice that of transmitting a ZERO bit, the time to send any NEC encoded message is constant regardless of the value of the address and control bytes. Figures in Reference 4 are reproduced below to illustrate the timing of the NEC protocol. The encoding of an NEC protocol message in Fig. 7.7 shows that the entire packet consists of two bytes of data: the address byte and the command byte. Each byte is followed by its [[https://en.wikipedia.org/wiki/Ones%27_complement|one’s complement]]. The consequence of this encoding is that although the time to transmit a ONE bit is twice that of transmitting a ZERO bit, the time to send any NEC encoded message is constant regardless of the value of the address and control bytes.
Line 171: Line 178:
  
  
-==== 6.3. UART Hardware ==== +----
-The Basys MX3 processor board uses an FTDI USB to serial adaptor that interfaces directly with the PIC32MX370 UART pins, as shown in Fig. A.1, with the physical location of the UART USB connector shown in Fig. A.2. The UART_RX and UART_TX connect to the PIC32MX370 processor I/O pins RF12R and RF13R respectively. The result of this wiring will be discussed below in the UART Software section. When the USB cable is connected to both the PC and J10 of the Basys MX3 processor board, the PC software will automatically enumerate the connection to a COMM port. To determine which COMM port is enumerated, you will need to click on the Windows Start icon in the lower left corner followed by clicking on “Device Manager” and then on “Ports (COM & LPT).” You will then see a listing as “USB Serial Port (COM##)” where “##” is the COMM number used when you open the terminal emulation application.+
  
-==== 6.4UART Software ==== +==== Listing 7.2INT1 ISR ==== 
-As stated abovethe UART_TX and UART_RX connect to the PIC32MX370 processor I/O pins RF12R and RF13R respectively. Table 6.1 shows that port F, pin 13 is mapped to U4RX using the C program statement “U4RXR 0x09;”. Similarly, Table 6.2 shows that port F, pin 12 is mapped to U4TX using the C program statement “RPF12R 0x02;”. After the PPS pin mapping shown in Listing B.1, all serial communications will use UART 4. The complete function to initialize UART 4 is shown in Listing B.1.+<code> 
 +void __ISR(_EXTERNAL_1_VECTORIPL2SOFT) ext_int1_isr(void) 
 +
 +unsigned long t1_1;          // Current time of interrupt 
 +static unsigned long t2_1;    // Time of previous interrupt 
 +unsigned long dt_1;          // Time interval between edges 
 +unsigned int bitCount 0  // Number of decoded bits 
 +static int start_timing 0 // Time capture buffer has been initialized.
  
-**Table 6.1. PPS mapping of PIC32 port F pin 13 to UART 4 receive adapted from [[http://ww1.microchip.com/downloads/en/DeviceDoc/60001185E.pdf|PIC32MX330/350/370/430/450/470]] Family Data Sheet, Table 12-1.**+   t1_1 = ReadCoreTimer(); 
 +   if(!start_timing)        // Check for first interrupt after reset 
 +   { 
 +       t2_1 = t1_1;          // Initialize previous time on reset. 
 +       start_timing = 1
 +   } 
 +   else 
 +   { 
 +       dt_1 = t1_1 - t2_1;      // Compute time interval 
 +       bitCount = irda_nec(dt_1);  // Call decoding function 
 +       t2_1 = t1_1;             // Update time of last interrupt 
 +   } 
 +   IFS0bits.INT1IF = 0;      // Clear the interrupt flag 
 +
 +</code>
  
-^ 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<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>        | :::                                                                                                                                                                                                                                                         | + 
-| IC1             | IC1R             | IC1R<3:0>         | :::                                                                                                                                                                                                                                                         | +The core timer increments at the rate of a count for each 1/40,000,000 seconds or 0.0025 μs per count. Referring back to the NEC characterization figures, we find that the sync period should be reported 0.0045 seconds multiplied by 40,000,000 counts per second, or approximately 180000 core timer counts. When a ONE bit is encoded, the number of core timer counts since the last interrupt is (0.0025 – 0.00056seconds multiplied by 40,000,000 counts per second, or approximately 67000 core timer counts. When a ZERO bit is encoded, the number of core timer counts since the last interrupt is (0.00112 – 0.00056seconds multiplied by 40,000,000 counts per second, or approximately 22400 core timer counts. Since the accuracy of the crystals used to generate the IR pulses is unknown, 2% accuracy can be assumed and still allow for adequate discrimination between symbols. Table 7.2 lists the core timer count range for the NEC protocol symbols. 
-| $\overline{(U3CTS)}$     | U3CTSR           | U3CTSR<3:0>       | :::                                                                                                                                                                                                                                                         | + 
-U4RX            U4RXR            U4RXR<3:0>        | :::                                                                                                                                                                                                                                                         +**Table 7.2. Core timer count ranges.** 
-U5RX            U5RXR            U5RXR<3:0>        | :::                                                                                                                                                                                                                                                         +^ Symbol    ^ Minimum Core Timer Count  ^ Maximum Core Timer Count  ^ 
-$\overline{(SS2)}$        SS2R             | SS2R<3:0>         | :::                                                                                                                                                                                                                                                         | +Sync      176400                    183600                    
-| OCFA            | OCFAR            | OCFAR<3:0>        :::                                                                                                                                                                                                                                                         |+ONE bit   65660                     68340                     
 +Zero bit  21952                     22848                     |
  
  
-**Table 6.2. PPS 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 Sheet, Table 12-2+==== 7.4Encoding the NEC IrDA Protocol with the PIC32MX370 Processor ==== 
 +In order to encode an IrDA for the NEC protocol, the 38 kHz modulated bit stream must be generated. I chose to generate the 38 kHz pulsed signal using the PWM output of the PIC32 processor. Table 7.3 is a copy from the PIC32MX370 data sheet showing the PPS mapping of OC5 to Port B bit 7, which is connected to the IR_TX signal lineListing 7.3 is the code for the IrDA initialization.
  
-^ RPn Port Pin         ^ RPnR SFR  ^ RPnR bits    ^ RPnR Value to Peripheral Seleciton                                                                                                                                                                                                                                                                ^+**Table 7.3. PIC32MX370 PPS output mapping for bit 7 of Port B.** 
 +^ RPn Port Pin         ^ RPnR SFR  ^ RPnR bits    ^ RPnR Value to Peripheral Selection                                                                                                                                                                                                                                                                ^
 | 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  | | 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>   | :::                                                                                                                                                                                                                                                                                               | | RPG6                 | RPG6R     | RPG6R<3:0>   | :::                                                                                                                                                                                                                                                                                               |
Line 208: Line 238:
 | RPE9<sup>(4)</sup>   | RPE9R     | RPE9R<3:0>   | :::                                                                                                                                                                                                                                                                                               | | RPE9<sup>(4)</sup>   | RPE9R     | RPE9R<3:0>   | :::                                                                                                                                                                                                                                                                                               |
  
-  - This selection is not available on 64-pin USB devices.  +The 38 kHz carrier signal is generated by setting the Timer counter register equal to the PBCLOCK divided by 38000The PWM output is turned off by setting the OC5 reset time greater than the Timer periodThe 9% duty cycle 38 kHz signal is turned on by setting the OC5 reset time to the product of 0.09 times the Timer 2 periodGenerating the NEC sync signal and encoding the one’s and zero’s is just matter of turning the PWM on and off for the specific durationas specified by Reference 3.
-  - 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.  +
- +
- +
-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. +
- +
-Listing B.3 and B.4 show the code for sending and receiving a 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 byteWhen receiving data, the processor must wait on the sending device. Both the “putcU4” and the “getcU4” can be implemented in 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 ===== +
-  - [[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 Part 2 Parts 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. 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: Lab 4a and 4b UART Functions ===== +==== Listing 7.3IrDA Initialization ====
-==== Listing B.1C Function that Initializes PF12 and PF13 to UART 4 ====+
 <code> <code>
-void uart_init(unsigned int baud, int parity)+#define IRDA_38K_IDLE        264 
 +#define IRDA_38K_ON          23 
 +#define IRDA_38KHZ_PD        262 
 +void irda_init(void)
 { {
-// The next two statements map the PPS IO pins to the UART 4 Tx and Rx +int i; 
-   RPF12R 0x02 // Mapping U4TX to RPF12+// IrDA Power Down Control 
-   U4RXR 0x09  // Mapping U4RX to RPF13 +   TRISGCLR BIT_1      // Set IR_pdown as output()
- +   LATGCLR  BIT_1      // Set IR_pdown(0); 
-   UARTConfigure(UART4, UART_ENABLE_PINS_TX_RX_ONLY ); +   
-   UARTSetDataRate(UART4GetPeripheralClock(), baud); // Set UART data rate +// Set up IrDA TX interface 
-// Note the need to specify the UART number twice in the following statement +   PORTSetPinsDigitalOut(IOPORT_BBIT_7); // IR_TX 
-   UARTEnable(UART4, UART_ENABLE_FLAGS(UART_ENABLE | UART4 UART_RX UART_TX));   +   RPB7R = 0b00001011;     // Mapping OC5 to RPB7 
-   switch(parity) +// Enable OC5 for PWM operation    
-   +   OpenTimer2((T2_ON T2_SOURCE_INT T2_PS_1_1), IRDA_38KHZ_PD);    
-       case NO_PARITY: +   OpenOC5((OC_ON|OC_TIMER_MODE16|OC_TIMER2_SRC|OC_PWM_FAULT_PIN_DISABLE) 
-           UARTSetLineControl(UART4, UART_DATA_SIZE_8_BITS UART_PARITY_NONE |+           IRDA_38K_IDLE, IRDA_38K_IDLE)
-                              UART_STOP_BITS_1); +   
-           break+// Set up IrDA RX interface 
-       case ODD_PARITY: +   INT1R = 0b00000101;     // Mapping IrDA Rx to RPB6 --> INT1 
-           UARTSetLineControl(UART4UART_DATA_SIZE_8_BITS | UART_PARITY_ODD |\   +   PORTSetPinsDigitalIn(IOPORT_BBIT_6); // IR_RX 
-                              UART_STOP_BITS_1); +// Set up INT1 for negative edge triggering 
-           break+   IEC0bits.INT1IE = 0   // Disable INT1 
-       case EVEN_PARITY: +   IPC1bits.INT1IP = 2;    // Set Interrupt 1 for priority level 2 
-           UARTSetLineControl(UART4, UART_DATA_SIZE_8_BITS | UART_PARITY_EVEN |\ +   IPC1bits.INT1IS = 0   // Set Interrupt 1 for sub-priority level 0 
-                              UART_STOP_BITS_1)+   INTCONbits.INT1EP = 0 // Set for falling edge 
-           break+   IFS0bits.INT1IF = 0;    // Clear the INT1 interrupt flag 
-   } +   IEC0bits.INT1IE = 1   // Enable INT1 
-   printf("\n\rUART Serial Port 4 ready\n\n\r");+}
 </code> </code>
  
-==== Listing B.2. C 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.3. C 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.4. C Code for Receiving a Single Character from UART 4 ==== +===== 8References ===== 
-<code> +  - Remote Control, [[https://en.wikipedia.org/wiki/Remote_control|https://en.wikipedia.org/wiki/Remote_control]]  
-BOOL getcU4( char *ch) +  - Consumer IR, [[https://en.wikipedia.org/wiki/Consumer_IR|https://en.wikipedia.org/wiki/Consumer_IR]] 
-+  - Data Formats for IR Remote Control, [[http://www.vishay.com/docs/80071/dataform.pdf|http://www.vishay.com/docs/80071/dataform.pdf]]  
-UART_DATA c; +  - AN #157 Implementation of IR NEC Protocol, [[http://www.mcselec.com/index.php?option=com_content&task=view&id=223|http://www.mcselec.com/index.php?option=com_content&task=view&id=223]]  
-BOOL done FALSE; +  - Remote Control with IrDA® Transceivers, [[http://datasheet.octopart.com/TFBS4710-TT1-Vishay-datasheet-12514678.pdf|http://datasheet.octopart.com/TFBS4710-TT1-Vishay-datasheet-12514678.pdf]] 
-   if(UARTReceivedDataIsAvailable(UART4)) /* wait for new char to arrive *+  - SB –Projects NEC Protocol, [[http://www.sbprojects.com/knowledge/ir/nec.php|http://www.sbprojects.com/knowledge/ir/nec.php]]  
-   { +  - PIC32MX330/350/370/430/450/470 Data Sheet, [[http://ww1.microchip.com/downloads/en/DeviceDoc/60001185E.pdf|http://ww1.microchip.com/downloads/en/DeviceDoc/60001185E.pdf]]  
-       c = UARTGetData(UART4); /* read the char from receive buffer *+  Understanding Sony IR remote codes, LIRC files, and the Arduino library, [[http://www.righto.com/2010/03/understanding-sony-ir-remote-codes-lirc.html|http://www.righto.com/2010/03/understanding-sony-ir-remote-codes-lirc.html]] 
-       *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-2/start|Back to Unit 4 Part 2]]
 +[[{}/learn/courses/unit-5-lab5a/start|Go to Lab 5a]]
 +[[{}/learn/courses/unit-6/start|Go to Unit 6]]
  
 {{tag>reference learn microprocessor courses basys-mx3}} {{tag>reference learn microprocessor courses basys-mx3}}