Go Down

Topic: USART Manchester Encoding and other USART features (Read 810 times) previous topic - next topic

thomas_nagels_bvba

Hi everyone,



Has anyone here managed to set the DUE USART ports to Manchester Encoding? If I understand this correctly, the MCU supports this natively which would make that the most elegant way to implement this.

Same question for other USART features as sending "Break" signals and so on. How do I access the USART registers to do this?


Kind regards,


Thomas

ard_newbie

#1
Jan 24, 2018, 12:27 pm Last Edit: Jan 24, 2018, 03:05 pm by ard_newbie
You will find most everything about Manchester Encoder explained in section 35 of Sam3x datasheet.

Before using e.g. USART2, you will have to Power ON USART2 with the PMC peripheral, and affect output pins to USART2.

Extracts from Sam3x datasheet:

page 782:
35.7.3.2 Manchester Encoder
When the Manchester encoder is in use, characters transmitted through the USART are encoded based on biphase Manchester II format. To enable this mode, set the MAN field in the US_MR register to 1. Depending on polarity configuration, a logic level (zero or one), is transmitted as a coded signal one-to-zero or zero-to-one. Thus, a transition always occurs at the midpoint of each bit time. It consumes more bandwidth than the original NRZ signal (2x) but the receiver has more error control since the expected input must show a change at the center of a bit cell. An example of Manchester encoded sequence is: the byte 0xB1 or 10110001 encodes to 10 01 10 10 0101 01 10, assuming the default polarity of the encoder. Figure 35-8 illustrates this coding scheme.

USART2->US_MR |= US_MR_MAN;

Then program US_MAN accordingly:
USART2->US_MAN = …..

page 793:
35.7.3.13 Transmit Break
……
A break is transmitted by writing the Control Register (US_CR) with the STTBRK bit to 1.

USART2->US_CR |= US_CR_STTBRK;

And idem for Manchester decoder.
Page 786:
35.7.3.4 Manchester Decoder
When the MAN field in US_MR register is set to 1, the Manchester decoder is enabled. The decoder performs both
preamble and start frame delimiter detection. One input line is dedicated to Manchester encoded input data.
....


You can test RS232 with Manchester encoder/decoder within a single DUE board by altering US_CR and US_MAN accordingly respectively in USART0 (Serial1) and USART1(Serial2) in this example sketch (hook a jumper wire between RX1 and TX2 and between TX1 and RX2) :
Code: [Select]

[char c = 0;
void setup() {
 
  Serial.begin(250000);
  Serial1.begin(1000000);
  Serial2.begin(1000000);

  Serial2.print("Hello");
}


void loop() {
  String s;
  s = "";

  while (Serial1.available() > 0) {
    c = Serial1.read();
    s += c;

  }
  if (s.length() > 0) {
    Serial.println(s);
    Serial2.print(s);
  }
  delay(1000);
}

code]




Go Up