OneWire in Due

I've been working with OneWire today. I included the #defines for Due.

It seems to work on a couple sensors, but most of my 10 test sensors them do not work. They all respond with a presence pulse, but then return 0xFF for every byte including the checksum.

So I started troubleshooting. I believe I've tracked the problem to a possible bug in delayMicroseconds(). I'm using Arduino IDE 1.5.1.

Here is a very simple test program, which does a reset and then sends a single byte (skip is 0xCC).

#include <OneWire.h>

OneWire ds(10); // on pin 10

void setup() {
}

void loop() {
ds.reset();
ds.skip();
delay(10);
}

Here is the actual waveform:

On the top trace you can see the entire sequence. On the bottom is a zoomed in view of the first 4 bits after the reset. The time scale is 30 us/div. OneWire sends LSB first, so this is two 0s followed by two 1s.

The first 0 bit is incorrect. OneWire called delayMicroseconds(65), but as you can see on the trace, the time was only 30 us. The next zero bit is generated by the exact same code, where the delay actually is 65 us. Well, it's actually closer to 67 us, but a 2 us error is ok. But the first pulse being less than 60 us is not ok. The datasheet says the chip will sample the voltage between 15 to 60 us after the falling edge, so a 30 us pulse works with some chips, but not others (most my 10 test samples apparently sample after 30 us).

Here is the same code, with the same sensor and same oscilloscope setup, running on a Teensy 3.0 board.

Both of the zero bits have a 65 us wide low pulse.