OneWireSlave::waitReset_() - Timing Dependency Error #3

Open
opened 5 years ago by IanF · 1 comments
IanF commented 5 years ago

This issue concerns an interrupt timing dependency in the OneWire Slave reset handling.

FUNCTION IMPACTED : void OneWireSlave::waitReset_() in OneWireSlave.cpp

The function is invoked as a result of a CHANGE interrupt on the onewire pin. This means the function is called when the master pulls the bus line low to initiate a reset and when the bus is released by the master to wait for the slave presence pulse.

In OneWireSlave::waitReset_() the variable "resetDuration" is first declared as a local variable

unsigned long resetDuration = now - resetStart_;

However when the function OneWireSlave::waitReset_() is invoked again by interrupt as a result of the master releasing the bus, the previous local value of "resetDuration" is not retained.

As a result, there is a timing dependency between when OneWireSlave::waitReset_() is called as the bus goes low and later when the bus is released. This causes erratic behavior with some valid onewire resets being seen as too long (and treated as errors) when this is not true.

The timing dependency does not appear to seriously impact the ATMEGA328 version of OneWireArduinoSlave. On the ATTINY85 platform, the timing dependency causes very erratic handling of master resets.

PROPOSED FIX

Declare "resetDuration" as a static variable in function void OneWireSlave::waitReset_()

static unsigned long resetDuration = now - resetStart_;

Also the variable "resetStart_" should be declared as "long" rather than "int"

resetStart_ = (unsigned long) - 1;

This fix has been tested and works reliably.

This issue concerns an interrupt timing dependency in the OneWire Slave reset handling. FUNCTION IMPACTED : void OneWireSlave::waitReset_() in OneWireSlave.cpp The function is invoked as a result of a CHANGE interrupt on the onewire pin. This means the function is called when the master pulls the bus line low to initiate a reset and when the bus is released by the master to wait for the slave presence pulse. In OneWireSlave::waitReset_() the variable "resetDuration" is first declared as a local variable unsigned long resetDuration = now - resetStart_; However when the function OneWireSlave::waitReset_() is invoked again by interrupt as a result of the master releasing the bus, the previous local value of "resetDuration" is not retained. As a result, there is a timing dependency between when OneWireSlave::waitReset_() is called as the bus goes low and later when the bus is released. This causes erratic behavior with some valid onewire resets being seen as too long (and treated as errors) when this is not true. The timing dependency does not appear to seriously impact the ATMEGA328 version of OneWireArduinoSlave. On the ATTINY85 platform, the timing dependency causes very erratic handling of master resets. PROPOSED FIX Declare "resetDuration" as a static variable in function void OneWireSlave::waitReset_() static unsigned long resetDuration = now - resetStart_; Also the variable "resetStart_" should be declared as "long" rather than "int" resetStart_ = (unsigned long) - 1; This fix has been tested and works reliably.
Poster

Hi Youen,

I'm no longer entirely sure this fix has completely solved the problem.

For example if I reflash the atttiny85 a few times the timing issue may or may not be evident. It is a weird problem.

Hi Youen, I'm no longer entirely sure this fix has completely solved the problem. For example if I reflash the atttiny85 a few times the timing issue may or may not be evident. It is a weird problem.
Sign in to join this conversation.
No Label
No Milestone
No Assignees
1 Participants
Notifications
Due Date

No due date set.

Dependencies

This issue currently doesn't have any dependencies.

Loading…
There is no content yet.