Skip to content

Conversation

@sparques
Copy link
Contributor

I was hitting an issue with using an SSD1306 display and the tinygo.org/x/drivers/ssd1306 i2c driver. The display worked, but then after about ~20 minutes of running, I would get i2c write timeout errors, even though the screen was still updating. This was due to eventually needing GC to run and that made gosched() take long enough that we hit the i2c timeout.

I see this is actually fixed in the dev branch: gosched() time is compensated for. But I also see that the total, fixed timeout was lowered from 40ms to 4ms.

For the SSD1306 driver which sends the full frame buffer, about 1025 bytes, when it does an update, 4ms is not enough time.

I2C consumes 9 clock pulses per byte (8 bits + ACK). So the wire time for N bytes is: t≈9N/f.

Any single I2C write of ~180+ bytes @ 400kHz is guaranteed to exceed 4 ms wire time.

Any single write of ~45+ bytes @ 100kHz is guaranteed to exceed 4 ms.

My proposed fix is adding a 100us budget per byte to be transfered, with a cap of 500ms.

@sparques sparques marked this pull request as draft January 26, 2026 16:28
@sparques sparques marked this pull request as ready for review January 26, 2026 17:34
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

Successfully merging this pull request may close these issues.

1 participant