Skip to content

Commit 63a5df3

Browse files
committed
docs/library/machine.I2C: Refine definitions of I2C methods.
1 parent a3320e7 commit 63a5df3

1 file changed

Lines changed: 20 additions & 20 deletions

File tree

docs/library/machine.I2C.rst

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -102,29 +102,31 @@ control over the bus, otherwise the standard methods (see below) can be used.
102102

103103
.. method:: I2C.start()
104104

105-
Send a start bit on the bus (SDA transitions to low while SCL is high).
105+
Generate a START condition on the bus (SDA transitions to low while SCL is high).
106106

107107
Availability: ESP8266.
108108

109109
.. method:: I2C.stop()
110110

111-
Send a stop bit on the bus (SDA transitions to high while SCL is high).
111+
Generate a STOP condition on the bus (SDA transitions to high while SCL is high).
112112

113113
Availability: ESP8266.
114114

115-
.. method:: I2C.readinto(buf)
115+
.. method:: I2C.readinto(buf, nack=True)
116116

117117
Reads bytes from the bus and stores them into `buf`. The number of bytes
118118
read is the length of `buf`. An ACK will be sent on the bus after
119-
receiving all but the last byte, and a NACK will be sent following the last
120-
byte.
119+
receiving all but the last byte. After the last byte is received, if `nack`
120+
is true then a NACK will be sent, otherwise an ACK will be sent (and in this
121+
case the slave assumes more bytes are going to be read in a later call).
121122

122123
Availability: ESP8266.
123124

124125
.. method:: I2C.write(buf)
125126

126-
Write all the bytes from `buf` to the bus. Checks that an ACK is received
127-
after each byte and raises an OSError if not.
127+
Write the bytes from `buf` to the bus. Checks that an ACK is received
128+
after each byte and stops transmitting the remaining bytes if a NACK is
129+
received. The function returns the number of ACKs that were received.
128130

129131
Availability: ESP8266.
130132

@@ -134,29 +136,27 @@ Standard bus operations
134136
The following methods implement the standard I2C master read and write
135137
operations that target a given slave device.
136138

137-
.. method:: I2C.readfrom(addr, nbytes)
139+
.. method:: I2C.readfrom(addr, nbytes, stop=True)
138140

139141
Read `nbytes` from the slave specified by `addr`.
142+
If `stop` is true then a STOP condition is generated at the end of the transfer.
140143
Returns a `bytes` object with the data read.
141144

142-
.. method:: I2C.readfrom_into(addr, buf)
145+
.. method:: I2C.readfrom_into(addr, buf, stop=True)
143146

144147
Read into `buf` from the slave specified by `addr`.
145148
The number of bytes read will be the length of `buf`.
149+
If `stop` is true then a STOP condition is generated at the end of the transfer.
146150

147-
On WiPy the return value is the number of bytes read. Otherwise the
148-
return value is `None`.
149-
150-
.. method:: I2C.writeto(addr, buf, \*, stop=True)
151+
The method returns `None`.
151152

152-
Write the bytes from `buf` to the slave specified by `addr`.
153+
.. method:: I2C.writeto(addr, buf, stop=True)
153154

154-
The `stop` argument (only available on WiPy) tells if a stop bit should be
155-
sent at the end of the transfer. If `False` the transfer should be
156-
continued later on.
157-
158-
On WiPy the return value is the number of bytes written. Otherwise the
159-
return value is `None`.
155+
Write the bytes from `buf` to the slave specified by `addr`. If a
156+
NACK is received following the write of a byte from `buf` then the
157+
remaining bytes are not sent. If `stop` is true then a STOP condition is
158+
generated at the end of the transfer, even if a NACK is received.
159+
The function returns the number of ACKs that were received.
160160

161161
Memory operations
162162
-----------------

0 commit comments

Comments
 (0)