Skip to content

write_bit bug #59

@fonsoreyes

Description

@fonsoreyes

write_bit has a bug. Actually it writes 5V in the bus when it must allow it float.

void OneWire::write_bit(uint8_t v)
{
IO_REG_TYPE mask IO_REG_MASK_ATTR = bitmask;
volatile IO_REG_TYPE *reg IO_REG_BASE_ATTR = baseReg;

if (v & 1) {
	noInterrupts();
	DIRECT_WRITE_LOW(reg, mask);
	DIRECT_MODE_OUTPUT(reg, mask);	// drive output low
	delayMicroseconds(10);
	DIRECT_WRITE_HIGH(reg, mask);	// --> must be DIRECT_MODE_INPUT to allow it to float
	interrupts();
	delayMicroseconds(55);
} else {
	noInterrupts();
	DIRECT_WRITE_LOW(reg, mask);
	DIRECT_MODE_OUTPUT(reg, mask);	// drive output low
	delayMicroseconds(65);
	DIRECT_WRITE_HIGH(reg, mask);	// --> must be DIRECT_MODE_INPUT to allow it to float
	interrupts();
	delayMicroseconds(5);
}

}

This way the bus can be 3,3V or 5V.

Best regards

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions