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

write_bit bug #59

Closed
fonsoreyes opened this issue May 2, 2018 · 1 comment
Closed

write_bit bug #59

fonsoreyes opened this issue May 2, 2018 · 1 comment

Comments

@fonsoreyes
Copy link

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

@PaulStoffregen
Copy link
Owner

closing this as a duplicate of #60

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants