You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The mainline OneWire library by Paul Stoffregen (v2.3.8, current Library Manager release) is silently non-functional on all tinyAVR 0/1/2-series chips with megaTinyCore. ow.reset() never returns true, reads always return 0xFF. There is no compile-time warning.
This was identified and a fix submitted as PR PaulStoffregen/OneWire#94 by @SpenceKonde in August 2020. That PR has not been merged as of May 2026 (5+ years).
Impact
Any megaTinyCore user who installs OneWire from the Arduino Library Manager and attempts to use it for DS18B20 temperature sensors, DS1990 iButtons, or any other 1-Wire device will get silent failures. The library compiles cleanly, reset() appears to execute, but no bus signals are produced on the correct pin.
Technical Details
OneWire_direct_gpio.h has a special case for __AVR_ATmega4809__ with correct PORT register offsets (−8 for DIR, −4 for OUT from the IN register). All other __AVR__ targets use classic ATmega offsets (+1, +2) which assume the PINx/DDRx/PORTx register layout.
The tinyAVR series shares the same modern PORT/VPORT peripheral as the ATmega4809 but is not matched by __AVR_ATmega4809__. The portInputRegister() on megaTinyCore returns a VPORT address where the layout is DIR(+0) / OUT(+1) / IN(+2). The classic +1/+2 offsets from IN land on INTFLAGS and the next VPORT's DIR — completely wrong registers.
Diagnostic Evidence
Tested on ATtiny3224, megaTinyCore 2.6.11, PA4 with DS1990A:
OneWire library (ow.reset()): 30 seconds of failures, 0/5 resets
Direct VPORTA bit-bang (same pin): Instant detection, ROM: 01:4E:BB:2A:04:00:00:91, CRC PASS
A diagnostic also revealed the pin numbering:
PIN_PA4 = 0 (not 4)
PIN_PA5 = 1
PIN_PA3 = 10
The non-obvious pin mapping is correct (megaTinyCore's own digitalPinToBitMask() resolves correctly) — the issue is solely in the OneWire library's register offset arithmetic.
Suggested Actions
Documentation: Add a note to LibraryCompatibility.md that OneWire (PaulStoffregen) is broken on tinyAVR 0/1/2-series and list the workaround (use OneWireNg, or a direct VPORT implementation).
Alternatively: If megaTinyCore's portInputRegister() could be made to return an address that is compatible with the ATmega4809 offsets (−8, −4), the existing ATmega4809 branch would work for tinyAVR too. However, this might break other assumptions.
Summary
The mainline OneWire library by Paul Stoffregen (v2.3.8, current Library Manager release) is silently non-functional on all tinyAVR 0/1/2-series chips with megaTinyCore.
ow.reset()never returns true, reads always return 0xFF. There is no compile-time warning.This was identified and a fix submitted as PR PaulStoffregen/OneWire#94 by @SpenceKonde in August 2020. That PR has not been merged as of May 2026 (5+ years).
Impact
Any megaTinyCore user who installs OneWire from the Arduino Library Manager and attempts to use it for DS18B20 temperature sensors, DS1990 iButtons, or any other 1-Wire device will get silent failures. The library compiles cleanly,
reset()appears to execute, but no bus signals are produced on the correct pin.Technical Details
OneWire_direct_gpio.hhas a special case for__AVR_ATmega4809__with correct PORT register offsets (−8 for DIR, −4 for OUT from the IN register). All other__AVR__targets use classic ATmega offsets (+1, +2) which assume thePINx/DDRx/PORTxregister layout.The tinyAVR series shares the same modern PORT/VPORT peripheral as the ATmega4809 but is not matched by
__AVR_ATmega4809__. TheportInputRegister()on megaTinyCore returns a VPORT address where the layout isDIR(+0) / OUT(+1) / IN(+2). The classic +1/+2 offsets from IN land onINTFLAGSand the next VPORT's DIR — completely wrong registers.Diagnostic Evidence
Tested on ATtiny3224, megaTinyCore 2.6.11, PA4 with DS1990A:
A diagnostic also revealed the pin numbering:
The non-obvious pin mapping is correct (megaTinyCore's own
digitalPinToBitMask()resolves correctly) — the issue is solely in the OneWire library's register offset arithmetic.Suggested Actions
Documentation: Add a note to
LibraryCompatibility.mdthat OneWire (PaulStoffregen) is broken on tinyAVR 0/1/2-series and list the workaround (use OneWireNg, or a direct VPORT implementation).PR Peripheral pin swapping not implemented #94 follow-up: Consider whether megaTinyCore should ship a bundled/patched OneWire library (as it does for Wire, SPI, etc.) since upstream appears unresponsive to PR Peripheral pin swapping not implemented #94.
Alternatively: If megaTinyCore's
portInputRegister()could be made to return an address that is compatible with the ATmega4809 offsets (−8, −4), the existing ATmega4809 branch would work for tinyAVR too. However, this might break other assumptions.Environment
Related