Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add inter-bit delay #107

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions OneWire.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ void OneWire::write_bit(uint8_t v)
interrupts();
delayMicroseconds(5);
}
delayMicroseconds(bit_delay);
}

//
Expand All @@ -238,6 +239,7 @@ uint8_t OneWire::read_bit(void)
r = DIRECT_READ(reg, mask);
interrupts();
delayMicroseconds(53);
delayMicroseconds(bit_delay);
return r;
}

Expand Down Expand Up @@ -318,6 +320,10 @@ void OneWire::depower()
interrupts();
}

void OneWire::set_bit_delay(unsigned int d) {
bit_delay = d;
}

#if ONEWIRE_SEARCH

//
Expand Down
3 changes: 3 additions & 0 deletions OneWire.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ class OneWire
IO_REG_TYPE bitmask;
volatile IO_REG_TYPE *baseReg;

unsigned int bit_delay = 0;

#if ONEWIRE_SEARCH
// global search state
unsigned char ROM_NO[8];
Expand Down Expand Up @@ -111,6 +113,7 @@ class OneWire
// someone shorts your bus.
void depower(void);

void set_bit_delay(unsigned int d);
#if ONEWIRE_SEARCH
// Clear the search state so that if will start from the beginning again.
void reset_search();
Expand Down