Skip to content

Commit

Permalink
Add strong pull-up for parasitic power
Browse files Browse the repository at this point in the history
Not 100% sure this is exactly the right timing for these commands, but
it works.

Was unable to read more than 3 sensors unless doing it very slowly
before.
  • Loading branch information
cybergibbons committed Feb 24, 2014
1 parent 6c259e4 commit dd2c475
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
25 changes: 22 additions & 3 deletions OneWire.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,16 @@ uint8_t OneWire::readConfig()
return readByte();
}

void OneWire::setStrongPullup()
{
writeConfig(readConfig() | DS2482_CONFIG_SPU);
}

void OneWire::clearStrongPullup()
{
writeConfig(readConfig() & !DS2482_CONFIG_SPU);
}

// Churn until the busy bit in the status register is clear
uint8_t OneWire::waitOnBusy()
{
Expand Down Expand Up @@ -140,6 +150,11 @@ void OneWire::writeConfig(uint8_t config)
uint8_t OneWire::wireReset()
{
waitOnBusy();
// Datasheet warns that reset with SPU set can exceed max ratings
clearStrongPullup();

waitOnBusy();

begin();
writeByte(DS2482_COMMAND_RESETWIRE);
end();
Expand All @@ -155,9 +170,11 @@ uint8_t OneWire::wireReset()
}

// Writes a single data byte to the 1-Wire line.
void OneWire::wireWriteByte(uint8_t data)
void OneWire::wireWriteByte(uint8_t data, uint8_t power)
{
waitOnBusy();
if (power)
setStrongPullup();
begin();
writeByte(DS2482_COMMAND_WRITEBYTE);
writeByte(data);
Expand All @@ -179,9 +196,11 @@ uint8_t OneWire::wireReadByte()
// (see Table 2). A V value of 0b generates a write-zero time slot (Figure 5); a V value of 1b generates a
// write-one time slot, which also functions as a read-data time slot (Figure 6). In either case, the logic
// level at the 1-Wire line is tested at tMSR and SBR is updated.
void OneWire::wireWriteBit(uint8_t data)
void OneWire::wireWriteBit(uint8_t data, uint8_t power)
{
waitOnBusy();
if (power)
setStrongPullup();
begin();
writeByte(DS2482_COMMAND_SINGLEBIT);
writeByte(data ? 0x80 : 0x00);
Expand Down Expand Up @@ -389,7 +408,7 @@ void OneWire::skip(void)
// Ignore the power bit
void OneWire::write(uint8_t v, uint8_t power)
{
wireWriteByte(v);
wireWriteByte(v, power);
}

// Read a byte.
Expand Down
10 changes: 8 additions & 2 deletions OneWire.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
#define DS2482_STATUS_DIR (1<<7)
#define DS2482_POINTER_DATA 0xE1
#define DS2482_POINTER_CONFIG 0xC3
#define DS2482_CONFIG_APU (1<<0)
#define DS2482_CONFIG_SPU (1<<2)
#define DS2482_CONFIG_1WS (1<<3)


#define DS2482_COMMAND_WRITECONFIG 0xD2
#define DS2482_COMMAND_RESETWIRE 0xB4
Expand Down Expand Up @@ -54,10 +58,12 @@ class OneWire
uint8_t waitOnBusy();
uint8_t readConfig();
void writeConfig(uint8_t config);
void setStrongPullup();
void clearStrongPullup();
uint8_t wireReset();
void wireWriteByte(uint8_t data);
void wireWriteByte(uint8_t data, uint8_t power = 0);
uint8_t wireReadByte();
void wireWriteBit(uint8_t data);
void wireWriteBit(uint8_t data, uint8_t power = 0);
uint8_t wireReadBit();
void wireSkip();
void wireSelect(const uint8_t rom[8]);
Expand Down

0 comments on commit dd2c475

Please sign in to comment.