Pocket PC IrDA Interface


In this article we will explore interfacing the PocketPC platform to the ProtoIrDA module using RawIr.

The following paragraphs will guide you through creating this link by providing PIC source code, a PocketPC RawIr Terminal & hopefully a good explanation of the process.

We will start by creating the circuit, followed by writing the PIC source, and end by testing the communication with the Terminal.

If you want to follow along, download the ProtoIrDATest microcode, and the RawIrTerminal software. You will also need the free BoostC compiler in order to build the project.

Step 1 - Wiring the Circuit
The only parts required to complete this circuit are a PIC16F628A or comparable microcontroller, and a ProtoIrDA module. Obtain these components, and connect them as shown in the schematic shown below.

Step 2 - Writing the PIC code
The code is simple, the only difference between using the ProtoIrDA and using a standard serial interface is the need for a 16X clock. The 16X clock oscillates at 16 times the current baudrate and provides the ProtoIrDA module the timing needed to create true IrDA compliant signals. This is easily accomplished by using the PWM output we have available. In our case, our baudrate is 9600bps so we need to set the PWM output to 50% duty cycle and 153600hz (9600 X 16). The following code snippet show how to set this up. Note that these values are calculated from a 4Mhz internal clock. For more information on getting the pr2 value, check the comments in the source file ProtoIrDATest.c.

trisb.3 = 0; //ccp1=output
pr2 = 0x05; //calculated above.
t2con = 0x04; //timer2 on, 1:1 prescaler
ccpr1l = 0x03; //50% duty cycle

ccp1con = 0x0C; //PWM Mode

Thats it for the 16X clock. Just set it, and forget it.. From here its just the same as any other serial setup, for 9600bps out we use the this:

txsta.BRGH = 1; //high speed
txsta.TXEN = 1; //enable transmit
txsta.SYNC = 0; //asynchronous
rcsta.SPEN = 1; //enable usart
rcsta.CREN = 1; //enable receive
spbrg = 25; //for 9600bps @ 0.16% error

After this initial setup of the PWM and USART, you can transmit and receive by writing to the TXREG register and reading the RCREG register.

Step 3 - Testing with the RawIr Terminal
Since the current PIC code simply outputs a single character every 2 seconds, this part will not be overly exciting. And currently, I have no way of testing the Terminal software on a PocketPC besides the HP hx4700 so I can give no guarantees that it will work on your PocketPC. I plan to post the source code to the terminal in the near future. If you have any questions regarding the source, please email me at ryan@prototronix.com.

The RawIrTerm executable will need to be transferred to your device, typically through ActiveSync. When loaded to your PocketPC, execute it and you will see an empty text area and a button to clear the text area. This works as any terminal program, entering keystrokes will send the corresponding character to the IrDA port. When a character is received through the IrDA port, it will be shown in the text area.

Using MPLab, download the Hex image created from the PIC source code to your 16F628A device. Apply power to your circuit, and then align the infrared ports of the ProtoIrDA and your PocketPC. If everything is working correctly you will see the letter 'U' written to the screen every 2 seconds.

Thats it! If you have any problems, don't hesitate to send an email to me at ryan@prototronix.com.

Tutorial Downloads:
RawIrTerm (59Kb)
- Raw IrDA Terminal For PocketPC (Only tested on hx4700 & hx4705)
RawIrTerm Source (172Kb)
- Source For Raw IrDA Terminal
ProtoIrDATest (13Kb)
- PIC Test Code Written In The Freely Available BoostC Compiler

AttachmentSize
IrTerminal.zip58.21 KB
IrTerminalSrc.zip171.57 KB
ProtoIrDATest.zip12.46 KB