aboutsummaryrefslogtreecommitdiff
path: root/docs/library
diff options
context:
space:
mode:
authorDavid (Pololu) <dev-david@pololu.com>2023-04-12 18:58:44 -0700
committerDamien George <damien@micropython.org>2023-04-21 18:03:33 +1000
commitbf3eb9dc3911b8e4e7da3054ffece61ae5e2ef64 (patch)
tree43c4274630971559e8e6d0cd9f0c3b3d69a89164 /docs/library
parentb525f1c9ec8ffa9009754578932f3fad5f63026b (diff)
rp2/machine_i2c: Add timeout parameter for machine.I2C().
This commit adds support for the `timeout` keyword argument to machine.I2C on the rp2 port, following how it's done on other ports. The main motivation here is avoid the interpreter crashing due to infinite loops when SDA is stuck low, which is quite common if the board gets reset while reading from an I2C device. A default timeout of 50ms is chosen because it's consistent with: - Commit a707fe50b085ec83722106609f6fd219faf9f030 which used a timeout of 50,000us for zero-length writes on the rp2 port. - The machine.SoftI2C class which uses 50,000us as the default timeout. - The stm32 port's hardware I2C, which uses 50,000us for I2C_POLL_DEFAULT_TIMEOUT_US. This commit also fixes the default timeout on the esp32 port to be consistent with the above, and updates the documentation for machine.I2C to document this keyword argument.
Diffstat (limited to 'docs/library')
-rw-r--r--docs/library/machine.I2C.rst4
1 files changed, 3 insertions, 1 deletions
diff --git a/docs/library/machine.I2C.rst b/docs/library/machine.I2C.rst
index 0eb1b67f5..bfc9f7ebc 100644
--- a/docs/library/machine.I2C.rst
+++ b/docs/library/machine.I2C.rst
@@ -52,7 +52,7 @@ Example usage::
Constructors
------------
-.. class:: I2C(id, *, scl, sda, freq=400000)
+.. class:: I2C(id, *, scl, sda, freq=400000, timeout=50000)
Construct and return a new I2C object using the following parameters:
@@ -62,6 +62,8 @@ Constructors
- *sda* should be a pin object specifying the pin to use for SDA.
- *freq* should be an integer which sets the maximum frequency
for SCL.
+ - *timeout* is the maximum time in microseconds to allow for I2C
+ transactions. This parameter is not allowed on some ports.
Note that some ports/boards will have default values of *scl* and *sda*
that can be changed in this constructor. Others will have fixed values