RC5 transmitter and receiver of bytes and integers (2 bytes)
I had a lot of problems with sending/receiving data by means of RS232. I looked for alternatives and found the RC5 data transmission as a good alternative. See below for the advantages and disadvantages.
Additional the RC5 does send maximum 6 bits (Command) or 5 bits (Address). In this software I made it possible to transmit bytes (6 bits) and even integers (2 bytes).
TRANSMITTER
Advantages this RC5 transmitter
1) No critical timers used. No PWM used.
2) Period time can be set at any value (but standard 2x889 usec)
3) Each output pin can be used
4) Special: Sending Bytes and Integers are possible
Advantages RC5 compared to RS232
1) With RC5 synchronisation possible on each bit (RS232 only on the start bit)
2) Oscillator accuracy not critical
Disadvantages RC5 compared to RS232:
1) In prinicpal not developed for byte communication (but see solution in this program)
2) Relative slow (RC5: 25 msec which is equal to RS232 400 baud rate)
This program:
- RC5 protocol has been followed. ( Although sending 2 bytes would be easier with RC-6 protocol)
- Only the demodulated signal will be send (no 36 KHz bursts). If IR-transmitter is used, an oscillator should be on at level '1'
- Each bit takes about 1800 usec (no timer used). If wanted, this can be changed in the SendBit macro (4 times)
- In case of Integer, send first the High Byte with toggle=1 and next the Low Byte with toggle=0
- In case of Byte send with toggle=0
- Address and Command together are 11 bits. Only 8 bits are used. There are 3 bits left for additional actions.
- Output is on pin A0. For other output pins, change RC5_Tx (the default values at top and bottom) and SendBit(the '0' and '1' levels, 4 times) macros
- Time between two Bytes can be given in Send_RC5 macro (minimum bit period time, about 7 msec)
- Rx-Timeout (waiting for next data) is infinit.
RECEIVER
The alternative RC5 receiver uses port B0.
Principal:
1) Detect the period time for 1 bit (about 1900 usec)
2) Synchronise on the level change half way each bit
3) Read input status directly after this half-way pulse
4) Wait 3/4 of a period to start at 2)
5) Repeat for 12 bits with: Toggle (1 bit), Address (5 bits) and Command (6 bits)
Interrupts used:
1) Timer2 (76800 Hz / 13 usec), but any other timer fits which measure the 900 usec accurate enough
2) Interrupt On Change (IOC) on portB on any change (positive and negative). In this version port B0, but all other ports can be used (change the IOC interrupt and inputs of port B0)
Remark:
- Chip oscillator frequency is not critical
- If Toggle=0 the Address and Command will be combined into a (low) byte
- If Toggle=1 the Address and Command will be combined into a (high) byte
- Toggle=1 followed by toggle=0 will give and integer (2 bytes)
Version V1
December 2013,
Jan Lichtenbelt, NL
PS. See faster alternative (about 3400 baud rate in stead of 400) http://www.matrixmultimedia.com/mmforum ... 54&t=14121
RC5 transmission of bytes and integers
Moderator: Benj
- Jan Lichtenbelt
- Posts: 797
- Joined: Tue Feb 17, 2009 8:35 pm
- Location: Haren GN, the Netherlands
- Has thanked: 128 times
- Been thanked: 264 times
- Contact:
RC5 transmission of bytes and integers
- Attachments
-
- RC5_Tx_Software_V1.fcf
- (26.45 KiB) Downloaded 351 times
-
- RC5_Rx_Software_V1.fcf
- (41.33 KiB) Downloaded 325 times