HCSII IR Gateway Controller Copyright 1992 Circuit Cellar INK Firmware Furnace #26 Ed Nisley What you get The BBS files include two different HEX EPROM images: IRLINKB.HEX RS-485 network node IRGATE.HEX single RS-232 connection This documentation file describes the full IRLINK command set; ignore the network functions if you are using IRGATE.HEX. See the articles in Circuit Cellar INK for details on the hardware required to run the programs, as well as full schematics for all the circuitry. This documentation assumes you are using the IR-Link circuit board described in INK Issue 26. See the READ.ME file for details on recompiling the source code. The C source code accompanying this file produces IRGATE.HEX, which does not include the network functions. The complete IRLINK source code is available by licence from Micromint, Inc. RTC-31 connections P1.7 LED heartbeat at 0.5 Hz, IR rec/trans blip P1.6 Output bit A P1.5 Output bit B P1.4 Output bit C P1.3 INPUT - high bit of network address, gnd=1 P1.2 INPUT - middle bit, ditto P1.1 INPUT - low bit of network address P1.0 INPUT - gnd at reset -> RS-232 interactive mode P3.3 INT1 high to turn IR transmit LED ON P3.2 INT0 INPUT from Sharp IS1U60 IR detector P3.5 T1 transmitter oscillator input P3.4 T0 controls RS-485 driver (LED ON = disabled) Sharp IR Module connections Hold the module with leads down and IR window facing you. Lead 1 is on the left. 1 Output signal, ground for IR present 2 Ground 3 +5V To Get Started Communications is 9600 b/s 8N1. Remove 75176 transceiver chip, install MAX-232. Connect PC to RS-232 header as usual. Verify commands to satisfy yourself that it works... Prefix all commands with "! IRx " (note spaces!) x must match the net address set on P1.1-P1.3 There is no command echo in this mode If you have trouble, ground P1.0 and reset the CPU to enter "interactive" mode: Descriptive banner appears and prefix is not used For Network Use Install 75176 tranceiver, remove MAX-232. Ground P1.1-3 to set network address (ground = "1" bit) Connect PC through RS-485 converter. Your software must enable/disable RTS correctly! Make sure P1.0 is not grounded when you turn power ON. Checksums If you must be absolutely certain that there are no errors in either the commands or responses, you can add a checksum to each command. The firmware will respond only to commands with valid checksums, so your controller code must resend the command if it does not produce the expected response within a specified timeout. The command format is: #xx addr command where: # identifies a command with a checksum xx checksum byte in hex, described below blank a blank (ASCII 32, 20 hex) is required addr target node's network address blank a blank (ASCII 32, 20 hex) is required command command text carriage return (ASCII 13, 0D hex) The node's response will look like this: $xx addr command where: $ identifies node response (same as ! response) xx checksum byte in hex, described below blank a blank (ASCII 32, 20 hex) addr target node's network address blank a blank (ASCII 32, 20 hex) response the response to the command carriage return (ASCII 13, 0D hex) Note that ordinary and checksummed responses both start with a "$" character. You can distinguish between the two by examining the second character: if it's a blank, there is no checksum. Compute a checksum using this algorithm: - assemble the line with ASCII zeros in the checksum hexits #00 X10 QN01 - add up all the character values, including the zeros # 23 (all values in hex here) 0 30 0 30 blank 20 X 58 1 31 0 30 blank 20 Q 51 N 4E 0 30 1 31 total 7C (only the low byte is used) - find the 2's complement of the checksum byte -(7C) = 84 - convert the byte to ASCII hexits and replace the zeros #84 X10 QN01 To verify the checksum for an incoming line, - assemble the entire line $E7 X10 N01=XX - discard the trailing (and if present) $E7 X10 N01=XX - convert the checksum chars to a single binary byte $E7 X10 N01=XX (checksum is E7 hex) - replace the checksum chars with two ASCII zeros (30 hex) $00 X10 N01=XX (ASCII 48 chars, not binary zeros!) - add up all the character values, including the zeros $ 24 (all values in hex here) 0 30 0 30 blank 20 X 58 1 31 0 30 blank 20 N 4E 0 30 1 31 = 3D X 58 X 58 total 19 (only the low byte is used) - add the checksum byte 19 + E7 = 00 If the result is zero, the line is (quite likely) valid. After you think about it for a while you'll write a single subroutine to calculate or verify the checksum. If you hand the routine a line with a 00 checksum, it'll replace the zeros with the new checksum so you can send the line. If you hand it a (presumably) valid received line it will do the same, but also return the calculated checksum to the caller as an integer. Got it? Controller commands All time intervals are in units of 5.16 ms A=str Set network address 16 char max, forced uppercase, blanks discarded B Set badge response delay (default 40 ticks) CRn Calibrate remote MC145030 bit clock (12.4 kHz, 1290 us) n=0-3 sets report detail CT Calibrate transmitter oscillator connect 38 kHz output to T1 input D Dump program status (debugging use) E Show and clear error flags (debugging use) In Set badge polling interval (default 190 ticks) Ln Set logging mode (bit mapped) L report current mode L0 disable (default) L1 show received IR messages L2 show transmitted IR messages L4 show generated polls Nn Set network/interactive mode N report current mode N0 set interactive mode N1 network mode (no error messages) (default) N2 network mode with command echo and err msgs N3 same as N1 with command acknowledgement Ox=n Set output bit x to state n (OA=1, OB=0) Bits are normally high after reset Pn Set number of badges to poll (default 0, no polling) Q Query and reset received IDs Q dump all 512 IDs in hex bytes (about 132 chars) ID 0 is bit 0 of first byte Qn report ID n status in format 003=1 Qn-m report IDs n through m in hex bytes ID n is bit 0 of first byte RESET perform power-on reset must be completely spelled out! Sn Send IR ID n (decimal, 0-511) Notes IR-Link sends and receives the IR codes defined by the MC145030 Remote Control Encoder/Decoder. The nominal bit frame is 1.29 ms, corresponding to a 12.4 kHz clock. IR-Link can receive signals from encoders with clock frequency offsets of a few percent, but it will always transmit at the nominal frequency. The MC145030 transmits two copies of the ID (its "address" input pins), but requires only one correct ID for reception. IR-Link requires both a correct bit format and matching copies of the ID before it will record the signal. Signals from other remote control units with different modulation schemes will generally be ignored, but it is possible that portions of the signals will "match" a correct ID. IR-Link discards invalid signals and begins waiting for a new signal as soon as it detects an error; there is no fixed delay. The A command sets the network address. This command is most useful for battery-backed RAM; if the stored address is not valid on power-up, the firmware will use the default address of IRx (x matching the input on P1.1-P1.3). The last character of the address string will be replaced by the P1 bit settings. The Ox=n command controls output bits P1.4-6. The bits are normally high after a hardware or software reset. Issuing OA=0 (that's "Oscar Able equals Zero") sets P1.6 LOW, OA=1 sets it HIGH. Because 8031 CPU bits have very weak pullups, you should probably use drivers with active low inputs. Calibration You should use the calibration routines in interactive mode (ground P1.0 and reset the CPU) because they disable all interrupts. Use any serial communications program on your PC to send commands and observe the results. The heartbeat LED (P1.7) will blink rapidly while the firmware is in the calibration routines. Transmitter Install the jumper that connects the 38 kHz oscillator output to the T1 CPU input, then enter the CT command. The firmware will measure the frequency once per second and display the numeric value and a flying-dot tuning graph: 35990 Hz [<<< under 36000] 36249 Hz [ * | ] 36466 Hz [ * | ] 37309 Hz [ * | ] 37865 Hz [ *| ] 37999 Hz [ * ] Adjust the trimpot for 38 kHz, then press any key to get out of the calibration routine. Remove the jumper. Remote unit MC145030 oscillator Enter the CR command and send an IR signal from the remote unit. The firmware will measure the Manchester bit frame times, which are set by the remote unit's oscillator. Tune the remote for a frame time of 1290 us, which implies a 12400 Hz oscillator frequency (16/period). The display will resemble this: Bit frame time is 1310 us Bit frame time is 1301 us Bit frame time is 1290 us Bit frame time is 1268 us Bit frame time is 1291 us Press any key to get out of the calibration routine. You can display more details about the incoming signals by entering CR 1, CR 2, or CR 3. Badge Polling IR-Link can serve as the basis for a simple "people tracking" system based on either active or passive badges. In this context, active badges send their ID periodically without prompting and passive badges respond to a poll from the tracking system. Active badges require no special setup, as IR-Link will record all IDs seen by its sensor. Each ID is cleared as it is reported, so each Query command returns new IDs since the last Query. Passive badges must receive their ID to trigger the transmission of that ID. IR-Link can send IDs at regular intervals and will record the response; there is no difference between a polled ID and any other ID. IR-Link does not record its own transmissions, so there is no conflict between the outgoing and incoming IDs. IR-Link has three badge polling controls. The default values should handle most situations, but each can be changed as needed. The P command sets the number of badges to poll; the default is P0 to poll zero badges, which disables polling. Badge polling starts with ID 0 and continues to n-1, where n is the number of badges. The I command sets the interval between successive polls. The default is about two seconds. Because all badges must be active to analyze each poll and each matching poll triggers an IR message, polling too frequently will reduce the lifetime of the badge batteries (or, conversely, require bigger batteries for a given life). The B command sets the delay between the end of IR-Link's polling transmission and the start of the next transmission. This ensures that IR-Link does not transmit a poll and a S command so close together that the badge response gets clobbered. The default is about 200 ms, which should be adequate. Revision History Rev 1.0b Recompile with Micro-C 3.0 Expand serial input buffer to 250 bytes Rev 1.0a Add net mode 3 with command acknowledgement Force RESET to wait for serial output completion Rev 0.6a Collect common code, add checksums Rev 0.5e Relocate RAM to A000 Rev 0.5d Workaround for in-line assembler "semicolon" glitch Recompile to get all code in step Rev 0.5c IR transmitter output polarity is now + for IR signal. Rev 0.5b Set network address string in battery-backed RAM Add output bits