SLAA202B February   2005  – December 2018 MSP430F149 , MSP430F149 , MSP430F2252-Q1 , MSP430F2252-Q1 , MSP430F2272-Q1 , MSP430F2272-Q1 , MSP430F2274 , MSP430F2274 , MSP430FG4619 , MSP430FG4619

 

  1.   Implementing IrDA With MSP430™ MCUs
    1.     Trademarks
    2. 1 Introduction
    3. 2 Hardware Description
      1. 2.1 Hardware Overview
      2. 2.2 Circuit Description
    4. 3 Software Description
      1. 3.1 Implementing IrPHY Layer Using Timer_A
        1. 3.1.1 Transmission
        2. 3.1.2 Reception
      2. 3.2 Implementing IrPHY Layer using USCI_A0
      3. 3.3 Implementing IrLAP
        1. 3.3.1 Discovery Services
        2. 3.3.2 Connect Services
        3. 3.3.3 Data Services
        4. 3.3.4 Disconnect Services
      4. 3.4 Implementing IrLMP
        1. 3.4.1 Discovery Services
        2. 3.4.2 Link Connect and Connect Services
        3. 3.4.3 Data Services
        4. 3.4.4 Disconnect Services
      5. 3.5 IAS Implementation
      6. 3.6 TTP Implementation
      7. 3.7 IrCOMM Implementation
      8. 3.8 Application Layer
    5. 4 PC Demonstration Application
    6. 5 IrDA Protocol Basics
      1. 5.1 Physical (IrPHY) Layer
      2. 5.2 Link Access Protocol (IrLAP) Layer
      3. 5.3 Link Management Protocol (IrLMP) Layer
      4. 5.4 Information Access Services (IAS)
      5. 5.5 Tiny Transfer Protocol (TTP)
      6. 5.6 IrCOMM
    7. 6 IrDA Communication Diagram
    8. 7 Frame Exchange Log
    9. 8 References
  2.   Revision History

PC Demonstration Application

The PC demonstration application supplied with this application report is provided as both C source code and as an executable single-file Win32 command line application. It has been decided to develop the software as a command line application to make it both easy to understand and also compatible with all common Windows-based C development systems such as Microsoft Visual C++ or Borland C++. The demonstration software requires at least Windows 2000 or Windows XP operating system and a properly installed infrared port. This IR port can either be integrated (such as found in notebook computers) or provided by an external Windows-supported IrDA adaptor (for example, the Actisys ACT-IR220L+).

The current Windows operating systems come with a built-in IrDA stack that implements various IrDA communication modes, such as the 9-wire IrCOMM mode. This mode can easily interface with external devices like PDAs, cell-phones, and the presented MSP430 IrDA stack. Microsoft decided to expose the IrDA stack through the Windows sockets library rather than by providing virtual COM ports. If virtual COM ports need to be used, then additional third-party driver software such as IrCOMM2k is required [9]. However, the more elegant approach is to perform IrDA communication by using the standard Windows built-in driver model as shown in this demonstration application.

The PC demonstration application provides feedback about every Windows API call it does. If one of the calls fail, the application terminates and displays the Windows error code as obtained by the Windows sockets function WSAGetLastError(). For detailed information about the error codes, see the Microsoft Windows Platform SDK documentation [8].

When starting the application, it tries to open the Winsock system library (DLL). At least version 2.2 is required for proper operation of the IrDA communication. The program exits with an error message if an incompatible version is located. After opening the Windows IrDA socket, the reception and transmit timeouts are configured to 3 seconds to prevent the software from indefinitely waiting for the end of the communication. The software then generates a list of IrDA devices which have been discovered already. For the sake of simplicity, the first device is taken from the list and assumed to be the IrDA peer the user wants to communicate with. At this point, the user could be provided with a list of the discovered devices. Next, the peer's IAS database is scanned to check whether or not it supports the 9-wire communication mode. If the 9-wire mode is supported, then it is activated. Otherwise, the application terminates with an error message.

From this point on, using the Windows IrDA stack does not differ from using any other Windows sockets such as TCP or UDP. The connection is opened by calling the connect() function. After that, a single t character is transmitted using send(). When the MSP430 IrDA stack receives this character, it initiates an A/D conversion of the ADC12 module internal temperature sensor and then sends back the current MCU temperature as an ASCII string. Finally, the data that was received and buffered by the Windows IrDA stack is read out using the sockets function recv() and displayed on the screen. The Windows socket and therefore the IrDA stack are now closed by calling closesocket(). It is important that the socket is closed every time it has been used, even if an error occurred. Otherwise, internal Windows IrDA stack resources could remain locked and the IrDA port can no longer be accessed until the next system start-up. Therefore, make sure not to interrupt the demo application by not pressing Ctrl+C. Detailed information about the built-in Windows IrDA functionality can be found in the Microsoft Windows Platform SDK.