Manchester Code Library

The mikroC PRO for ARM provides a library for handling Manchester coded signals. The Manchester code is a code in which data and clock signals are combined to form a single self-synchronizing data stream; each encoded bit contains a transition at the midpoint of a bit period, the direction of transition determines whether the bit is 0 or 1; the second half is the true bit value and the first half is the complement of the true bit value (as shown in the figure below).

Manchester signal format

  Important :

External dependencies of Manchester Code Library

Stellaris

The following variables must be defined in all projects using Manchester Code Library: Description: Example:
extern sfr sbit MANRXPIN; Receive line. sbit MANRXPIN at GPIO_PORTE_DATA.B0;
extern sfr sbit MANTXPIN; Transmit line. sbit MANTXPIN at GPIO_PORTE_DATA.B1;
extern sfr sbit MANRXPIN_Direction; Direction of the Receive pin. sbit MANRXPIN_Direction at GPIO_PORTE_DIR.B0;
extern sfr sbit MANTXPIN_Direction; Direction of the Transmit pin. sbit MANTXPIN_Direction at GPIO_PORTE_DIR.B1;

MSP432

The following variables must be defined in all projects using Manchester Code Library: Description: Example:
extern sfr sbit MANRXPIN; Receive line. sbit MANRXPIN at DIO_P6IN.B0;
extern sfr sbit MANTXPIN; Transmit line. sbit MANTXPIN at DIO_P6OUT.B1;
extern sfr sbit MANRXPIN_Direction; Direction of the Receive pin. sbit MANRXPIN_Direction at DIO_P6DIR.B0;
extern sfr sbit MANTXPIN_Direction; Direction of the Transmit pin. sbit MANTXPIN_Direction at DIO_P6DIR.B1;

STM32

The following variables must be defined in all projects using Manchester Code Library: Description: Example:
extern sfr sbit MANRXPIN; Receive line. sbit MANRXPIN at GPIOE_IDR.B8;
extern sfr sbit MANTXPIN; Transmit line. sbit MANTXPIN at GPIOE_ODR.B9;

CEC1x02

The following variables must be defined in all projects using Manchester Code Library: Description: Example:
extern sfr sbit MANRXPIN; Receive line. sbit MANRXPIN at GPIO_INPUT_PIN_023_bit;
extern sfr sbit MANTXPIN; Transmit line. sbit MANTXPIN at GPIO_OUTPUT_PIN_023_bit;

Library Routines

The following routines are for the internal use by compiler only:

Man_Receive_Init

Prototype

unsigned int Man_Receive_Init();

Description

The function configures Receiver pin. After that, the function performs synchronization procedure in order to retrieve baud rate out of the incoming signal.

Parameters

None.

Returns

  • 0 - if initialization and synchronization were successful.
  • 1 - upon unsuccessful synchronization.
  • 255 - upon user abort.

Requires

External dependencies of the library from the top of the page must be defined before using this function.

Example

Stellaris

// Manchester module connections
sbit MANRXPIN at GPIO_PORTE_DATA.B0;
sbit MANRXPIN_Direction at GPIO_PORTE_DIR.B0;
sbit MANTXPIN at GPIO_PORTE_DATA.B1;
sbit MANTXPIN_Direction at GPIO_PORTE_DIR.B1;
...
if (Man_Receive_Init() == 0) {
...
}

Stellaris

// Manchester module connections
sbit MANRXPIN at DIO_P6IN.B0;
sbit MANRXPIN_Direction at DIO_P6DIR.B0;
sbit MANTXPIN at DIO_P6OUT.B1;
sbit MANTXPIN_Direction at DIO_P6DIR.B1;
...
if (Man_Receive_Init() == 0) {
...
}

STM32

// Manchester module connections
sbit MANRXPIN at GPIOE_IDR.B8;
sbit MANTXPIN at GPIOE_IDR.B9;
...
if (Man_Receive_Init() == 0) {
...
}

CEC1x02

// Manchester module connections
sbit MANRXPIN at GPIO_INPUT_PIN_023_bit;
sbit MANTXPIN at GPIO_OUTPUT_PIN_023_bit;
...
if (Man_Receive_Init() == 0) {
...
}
Notes

In case of multiple persistent errors on reception, the user should call this routine once again or Man_Synchro routine to enable synchronization.

Man_Receive

Prototype

unsigned char Man_Receive(unsigned int *error);

Description

The function extracts one byte from incoming signal.

Parameters
  • error: error flag. If signal format does not match the expected, the error flag will be set to non-zero.
Returns

A byte read from the incoming signal.

Requires

To use this function, the user must prepare the MCU for receiving. See Man_Receive_Init routines.

Example
unsigned int data = 0, error = 0;
...
data = Man_Receive(&error);
if (error)
  { /* error handling */ }
Notes

None.

Man_Send_Init

Prototype

void Man_Send_Init();

Description

The function configures Transmitter pin.

Parameters

None.

Returns

Nothing.

Requires

External dependencies of the library from the top of the page must be defined before using this function.

Example

Stellaris

// Manchester module connections
sbit MANRXPIN at GPIO_PORTE_DATA.B0;
sbit MANRXPIN_Direction at GPIO_PORTE_DIR.B0;
sbit MANTXPIN at GPIO_PORTE_DATA.B1;
sbit MANTXPIN_Direction at GPIO_PORTE_DIR.B1;
...
Man_Send_Init();

MSP432

// Manchester module connections
sbit MANRXPIN at DIO_P6IN.B0;
sbit MANRXPIN_Direction at DIO_P6DIR.B0;
sbit MANTXPIN at DIO_P6OUT.B1;
sbit MANTXPIN_Direction at DIO_P6DIR.B1;
...
Man_Send_Init();

STM32

// Manchester module connections
sbit MANRXPIN at GPIOE_IDR.B8;
sbit MANTXPIN at GPIOE_IDR.B9;
...
Man_Send_Init();

CEC1x02

// Manchester module connections
sbit MANRXPIN at GPIO_INPUT_PIN_023_bit;
sbit MANTXPIN at GPIO_OUTPUT_PIN_023_bit;
...
Man_Send_Init();
Notes

None.

Man_Send

Prototype

void Man_Send(unsigned char tr_data);

Description

Sends one byte.

Parameters
  • tr_data: data to be sent
Returns

Nothing.

Requires

To use this function, the user must prepare the MCU for sending. See Man_Send_Init routine.

Example
unsigned int msg;
...
Man_Send(msg);
Notes

Baud rate used is 500 bps.

Man_Synchro

Prototype

unsigned int Man_Synchro();

Description

Measures half of the manchester bit length with 10us resolution.

Parameters

None.

Returns
  • 0 - if synchronization was not successful.
  • Half of the manchester bit length, given in multiples of 10us - upon successful synchronization.
Requires

To use this function, you must first prepare the MCU for receiving. See Man_Receive_Init.

Example
unsigned int man__half_bit_len;
...
man__half_bit_len = Man_Synchro();
Notes

None.

Man_Break

Prototype

void Man_Break();

Description

Man_Receive is blocking routine and it can block the program flow. Call this routine from interrupt to unblock the program execution. This mechanism is similar to WDT.

Parameters

None.

Returns

Nothing.

Requires

Nothing.

Example

Notes

Interrupts should be disabled before using Manchester routines again (see note at the top of this page).

Copyright (c) 2002-2019 mikroElektronika. All rights reserved.
What do you think about this topic ? Send us feedback!
Want more examples and libraries? 
Find them on LibStock - A place for the code