Tap in on 39kbps bus, can I?


I have a serial communication using Differential Manchester Code running at 39kbps that I would like to tap into, using my Arduino Mega ADK.

As the bus speed is 39kbps, it means the clock frequency is 78khz.

I made a short piece of code to test speed, using the elapsedMillis library and the elapsedMicros type.

elapsedMicros DTime = 0; 
int pos=0;
int pos1=0;

void loop() {
  Serial.print(pos); Serial.print(" "); 
  Serial.print(pos1); Serial.print(" "); 
  Serial.println(" Here we go!");


And the output is

8 12 Here we go!
8 12 Here we go!
4 12 Here we go!
12 20 Here we go!
8 12 Here we go!
4 8 Here we go!
4 8 Here we go!
8 12 Here we go!
8 12 Here we go!
4 12 Here we go!

So just going from one DTiming clearing/storing to the next, often takes 8-12 us.

Just the times between the edge-transitions on the 38/79kHz bus is 12 us. I need to catch those transitions and do some evaluation within that time.

Looks like there is no way I can make this happen.


Any input is welcome.


I would try to use the hardware Serial to capture the data

Serial.begin(39000); // or 78000

drawback you can't print to serial to check your decoded data...

my 2 cents

That is actually similar to an idea I just came up with meanwhile.

To use one of the USART's, set the baudrate to 76,8 kbaud (kHz) which is a standard USART board rate if I get the data sheet right. 78 kHz is just 1,2 kHz of = 1,5%. If I understand the data sheet right again, that is within the limit of what the USART should be able to handle.

But the question is the about data format, start and stop bits and things like that.

Could it work at all?

I could read a data packet. Decode it. Re-set the Serial bus and then print the serial data. So that way I could easily check to decoded data to see it is ok. In the end I won't need to send it somewhere. I'll decode it and present data on an LCD-screen.

But the question is the about data format, start and stop bits and things like that.

Could it work at all?

Nobody can know whether it might work, unless you answer above questions yourself.

If you are sure about Manchester code, the signal deserves some conditioning before it can be fed into a UART. Or you write your own Manchester decoder, then try to figure out more about the transmission protocol.

The Mega has multiple Serial devices, so that you can receive data and send to the Serial Monitor at the same time.

No point in writing my own Manchester decoder when the Ardiuno isn't fast enough execute it. Otherwise I'd already be done :wink: Writing a decoder isn't the hard bit.

From what it looks No, the USART can't be used, as it requires start and stop bits for each byte.
At least what I found so far those can't be disabled. I could probably have used the inital sync bits as startbit, but then I get a number of bytes of data without any start or stops bits.

If you are continuously sending data over Serial, this transmission will block the sketch. What's the Serial baudrate?

It should run faster if you only transmit the difference between two loop() iterations, without further text. Even faster if you transmit the time spent for e.g. 100 iterations.

There is already a commonly used Manchester library used for IR protocols.
Maybe you could adapt this as a starting point?

You mean the mchr3k library? Will that be so much faster?