Manchester protocol + Saleae Logic trouble

I am trying to implement simple Manchester debug output to monitor via Saleae Logic but I am probably missing something. I am using "normal Manchester" with negative edge meaning one, 8 bits per transfer, LSB first. Values from 1 to 254 decode correctly (at least I did not notice a problem) but Saleae does not decode 255 and 0. Do you know how to fix it?

This decodes correctly:

This is ambiguous - I am probably missing some part of the protocol that prevents such byte:

And this is unambiguous but Saleae still does not decode it:

Do you think it might help if you posted your code ?

Do YOU think?

#define PINManchester PINB
#define PORTManchester PORTB
#define ManchesterPinPosition 1

byte byteToSend;

#define ManchesterPin (1<<ManchesterPinPosition)

//10CK per bit -> bits/s=f_CPU/10
static void ManchesterSend(register byte data) {
  byte PORTValue=PORTManchester;
  byte counter=8;
  asm volatile (
  "1:"
  "bst %0, 0 \n\t"      // bst(data,0);
  "bld %2, %3  \n\t"    // bld(PORTValue,ManchesterPinPosition);
  "out %4, %2  \n\t"    // PORTManchester=PORTValue;
  "asr %0 \n\t"         // asr(data);
  "dec %1 \n\t"         // dec(counter);
  "rjmp .+0 \n\t"            // nopnop();
  "sbi %5,%3 \n\t"      // sbi(PINManchester,ManchesterPinPosition);
  "brne 1b"             // brne(1b);
  :
  "+r" (data),  //0
  "+r" (counter), //1
  "+r" (PORTValue) //2
  :
  "I" (ManchesterPinPosition),  //3
  "I" ASMRegisterAddress(PORTManchester), //4
  "I" ASMRegisterAddress(PINManchester) //5
  );
}

int main (void) {
  DDRB=ManchesterPin;
  while (1) {
    ManchesterSend(++byteToSend);
    for (byte i = 255; i--;) {
      nop();
    }
    wdr();
  }
}

EDIT: I think the byte "correctly" but without 0-1 (or 1-0) transition Saleae is unable to decode the byte and on some circumstances it is even ambiguous (as shown in OP). But when looking into the protocol description I did not find any countermeasures.

EDIT 2:
There is a workaround sending one preamble bit of opposite polarity. It works but I still wonder how the "true" Manchester deals with the ambiguity presented in the OP. Updated code:

static void ManchesterSendByte (byte data) {
  byte PORTValue=PORTManchester;
  byte counter=9;
  asm volatile (
  "set \n\t"          //setT();
  "sbrc %0, 0 \n\t"   //sbs(data,0);
  "clt \n\t"          //clearT();
  "1:"
  "bld %2, %3  \n\t"    // bld(PORTValue,ManchesterPinPosition);
  "bst %0, 0 \n\t"      // bst(data,0);
  "out %4, %2  \n\t"    // PORTManchester=PORTValue;
  "asr %0 \n\t"         // asr(data);
  "dec %1 \n\t"         // dec(counter);
  "rjmp .+0 \n\t"            // nopnop();
  "sbi %5,%3 \n\t"      // sbi(PINManchester,ManchesterPinPosition);
  "brne 1b \n\t"             // brne(1b);
  :
  "+r" (data),  //0
  "+r" (counter), //1
  "+r" (PORTValue) //2
  :
  "I" (ManchesterPinPosition),  //3
  "I" ASMRegisterAddress(PORTManchester), //4
  "I" ASMRegisterAddress(PINManchester) //5
  );
}

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.