Biphase data encoding => rising/falling edge

Triv38:
Hi,
i'm sorry, i make a fault concerning the direction of time on oscilloscope on trace.
The time go from left to right and not the inverse.
So the first bit sent to output is the bit at the leftmost and the last is at the right. (see my graph trace2 in attached file).

I wish to have the behavior as the diagram in attached file "trace3".
I try to test your code of the function "send_biphase_msb_first" routine but the behavior is not as expected (see "trace4")
I have on output "0b1000 0000" instead of "0b0111 1111".

I continue to work to have the good behavior.

I found where there error was in that routine. just needed to move a line! :wink:

void send_biphase_msb_first(uint8_t frame, uint8_t bits) {

  uint16_t previous_state = 0x01 & (!digitalRead(TxRx_PIN));
  uint16_t MSB_mask = (1 << (bits - 1));
  uint8_t bit = (frame & MSB_mask > 0) ? 1 : 0;

  for (int i = 0; i < bits * 2; ++i) {

    digitalWrite(TxRx_PIN, (previous_state ^ ((i & 0x01)&bit)));
    if (i & 0x01) {
      frame <<= 1;
      bit = (frame & MSB_mask > 0) ? 1 : 0;
    }
    previous_state = 0x01 & (!digitalRead(TxRx_PIN)); //<--- line moved out of 'if' statement
    delayMicroseconds(T_HBBIT);
  }

}

hope that helps...