Skip to content

Commit 74ec360

Browse files
committed
V3: add I2C. Add I/O note to porting guide.
1 parent 0ae62dd commit 74ec360

File tree

4 files changed

+20
-17
lines changed

4 files changed

+20
-17
lines changed

v3/as_drivers/i2c/asi2c.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ async def _run(self):
160160
# On Pyboard blocks for 380μs to 1.2ms for small amounts of data
161161
def _handler(self, _, sn=bytearray(2), txnull=bytearray(2)):
162162
addr = Responder.addr
163-
self.rem.irq(handler=None, trigger=machine.Pin.IRQ_RISING)
163+
self.rem.irq(handler=None)
164164
utime.sleep_us(_DELAY) # Ensure Initiator has set up to write.
165165
self.i2c.readfrom_into(addr, sn)
166166
self.own(1)

v3/as_drivers/i2c/asi2c_i.py

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,7 @@ async def _run(self):
8686
tstart = utime.ticks_us()
8787
self._sendrx()
8888
t = utime.ticks_diff(utime.ticks_us(), tstart)
89-
except OSError as e:
90-
# print('OSError:', e) # TEST
89+
except OSError: # Reboot remote.
9190
break
9291
await asyncio.sleep_ms(Initiator.t_poll)
9392
self.block_max = max(self.block_max, t) # self measurement
@@ -99,27 +98,26 @@ async def _run(self):
9998
if self.reset is None: # No means of recovery
10099
raise OSError('Responder fail.')
101100

102-
# Send payload length (may be 0) then payload (if any)
103-
def _sendrx(self, sn=bytearray(2), txnull=bytearray(2)):
104-
siz = self.txsiz if self.cantx else txnull
105-
if self.rxbyt:
106-
siz[1] |= 0x80 # Hold off further received data
107-
else:
108-
siz[1] &= 0x7f
101+
def _send(self, d):
109102
# CRITICAL TIMING. Trigger interrupt on responder immediately before
110103
# send. Send must start before RX begins. Fast responders may need to
111104
# do a short blocking wait to guarantee this.
112105
self.own(1) # Trigger interrupt.
113-
self.i2c.send(siz) # Blocks until RX complete.
106+
self.i2c.send(d) # Blocks until RX complete.
114107
self.waitfor(1)
115108
self.own(0)
116109
self.waitfor(0)
110+
111+
# Send payload length (may be 0) then payload (if any)
112+
def _sendrx(self, sn=bytearray(2), txnull=bytearray(2)):
113+
siz = self.txsiz if self.cantx else txnull
114+
if self.rxbyt:
115+
siz[1] |= 0x80 # Hold off further received data
116+
else:
117+
siz[1] &= 0x7f
118+
self._send(siz)
117119
if self.txbyt and self.cantx:
118-
self.own(1)
119-
self.i2c.send(self.txbyt)
120-
self.waitfor(1)
121-
self.own(0)
122-
self.waitfor(0)
120+
self._send(self.txbyt)
123121
self._txdone() # Invalidate source
124122
# Send complete
125123
self.waitfor(1) # Wait for responder to request send
@@ -133,7 +131,6 @@ def _sendrx(self, sn=bytearray(2), txnull=bytearray(2)):
133131
self.cantx = not bool(sn[1] & 0x80)
134132
if n:
135133
self.waitfor(1) # Wait for responder to request send
136-
# print('setting up receive', n,' bytes')
137134
self.own(1) # Acknowledge
138135
mv = self.rx_mv[0: n] # mv is a memoryview instance
139136
self.i2c.recv(mv)

v3/as_drivers/i2c/i2c_esp.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ async def sender():
5151
swriter = asyncio.StreamWriter(chan, {})
5252
txdata = [0, 0]
5353
while True:
54+
txdata[0] = gc.mem_free()
5455
await swriter.awrite(''.join((ujson.dumps(txdata), '\n')))
5556
txdata[1] += 1
5657
await asyncio.sleep_ms(1500)

v3/docs/I2C.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,11 @@ chan = Initiator(i2c, syn, ack, rst, verbose, self._go, (), self._fail)
376376

377377
# 5. Limitations
378378

379+
Currently, on the ESP8266, the code is affected by
380+
[iss 5714](https://github.com/micropython/micropython/issues/5714). Unless the
381+
board is repeatedly pinged, the ESP8266 fails periodically and is rebooted by
382+
the Pyboard.
383+
379384
## 5.1 Blocking
380385

381386
Exchanges of data occur via `Initiator._sendrx()`, a synchronous method. This

0 commit comments

Comments
 (0)