Manchester code (phase encoding) library.
Dependents: Manchester_Transmitter Manchester_Receiver
Manchester code (phase encoding) library
It implements Manchester code according to both IEEE 802.3 and G.E. Thomas' conventions.
- A '0' is expressed by a high-to-low transition, a '1' by low-to-high transition in the IEEE 802.3 convention. The reverse is true in the G.E. Thomas' convention.
- The transitions which signify '0' or '1' occur at the midpoint of a period.
- Transitions at the start of a period are overhead and don't signify data.
- Least significant bit is sent first
- There are synchronization pulses (the number can be set) at the begin of transmission
Select a convention to be used by commenting or uncommenting the line below in theManchester.h
header file.
Manchester.h
#define G_E_THOMAS 1
The IEEE 802.3 convention is used by default.
A Manchester encoded message (using G.E. Thomas' convention), with one sync pulse in the preamble, carrying four bytes:
ACKNOWLEDGEMENT: The code in this library was based on this article published by Robert Guastella.
Import programManchester_Transmitter
Manchester transmitter demo.
Import programManchester_Receiver
Manchester receiver demo.
NOTE: To perform a simple test (without radio modules) connect the txPin on transmitter board to the rxPin on the receiver board and make sure that grounds are also connected one another.
Diff: Manchester.h
- Revision:
- 1:11292d238e50
- Parent:
- 0:d5c75b0e5708
- Child:
- 2:de778df5892c
diff -r d5c75b0e5708 -r 11292d238e50 Manchester.h --- a/Manchester.h Wed May 17 07:52:15 2017 +0000 +++ b/Manchester.h Wed May 17 08:17:13 2017 +0000 @@ -4,7 +4,7 @@ * @author Zoltan Hudak * @version * @date 16-May-2017 - * @brief Manchester code for ARMmbed + * @brief Manchester code for mbed ****************************************************************************** * @attention * @@ -51,10 +51,10 @@ public: Manchester ( - PinName txPin, /* transmitter pin name */ - PinName rxPin, /* receiver pin name */ - uint32_t speed = 1500 /* speed in bits per second */, - uint8_t tol = 20 /* pulse width tolerance (+/-) in % */ + PinName txPin, /* transmitter pin name */ + PinName rxPin, /* receiver pin name */ + uint32_t speed = 1200 /* speed in bits per second */, + uint8_t tol = 20 /* pulse width tolerance (+/-) in % */ ); ~Manchester(void) { }; void transmit(ManchesterMsg& msg); @@ -66,8 +66,8 @@ Ticker _txTicker; // transmitter ticker Timeout _rxTimeout; // receiver timeout uint32_t _midBitTime; // mid-bit time [us] - uint32_t _minPulseWidth; // minimum pulse width - uint32_t _maxPulseWidth; // maximum pulse width + uint32_t _minPulseWidth; // minimum pulse width [us] + uint32_t _maxPulseWidth; // maximum pulse width [us] State _state; // state char* _data; // data array uint8_t _len; // data length in bytes