-
Notifications
You must be signed in to change notification settings - Fork 224
Description
First, thank you for the amazing tinygo work - am having much success on both Raspberry Pi Pico and Seeed Studio XIAO RP2040 boards.
The documented maximum write time in the datasheet is 10 milliseconds.
In file:
https://github.com/tinygo-org/drivers/blob/v0.32.0/at24cx/at24cx.go
The method "WriteByte" there is no write time delay so the engineer using this driver must know to include a write time delay when calling iteratively (as demonstrated by the at24cx example main.go file)
The method "writeAt" contains a write time delay but it is only 2 milliseconds - this obviously works for many/most at24cx chips but not all as i have one at24cx which must be on the slower-side to complete the write cycle.
In my local copy of the driver, i added the following to the two appropriate locations, in "WriteByte" before "return d.bus.Tx(d.Address, address, nil)" which results in the delay when iteratively called and is less disruptive to the code than trying to add afterward (though it would be better to delay afterward), and replacing the existing 2 millisecond write time delay in the "writeAt" method:
// The required time delay should be in the driver and preferably not the responsibility of the application
//time.Sleep(2 * time.Millisecond) // empirically NOT enough sleep time
//time.Sleep(3 * time.Millisecond) // empirically YES enough sleep time
//time.Sleep(10 * time.Millisecond) // DATASHEET-REQUIRED sleep time
time.Sleep(11 * time.Millisecond) // DATASHEET-REQUIRED-SAFETY-MARGIN sleep time
Again, thank you for all the great work on tinygo!
I hope this helps others in the future.