@@ -249,16 +249,15 @@ ESP32 specific ADC class method reference:
249
249
Software SPI bus
250
250
----------------
251
251
252
- There are two SPI drivers. One is implemented in software (bit-banging)
253
- and works on all pins, and is accessed via the :ref: `machine.SPI <machine.SPI >`
254
- class::
252
+ Software SPI (using bit-banging) works on all pins, and is accessed via the
253
+ :ref: `machine.SoftSPI <machine.SoftSPI >` class::
255
254
256
- from machine import Pin, SPI
255
+ from machine import Pin, SoftSPI
257
256
258
- # construct an SPI bus on the given pins
257
+ # construct a SoftSPI bus on the given pins
259
258
# polarity is the idle state of SCK
260
259
# phase=0 means sample on the first edge of SCK, phase=1 means the second
261
- spi = SPI (baudrate=100000, polarity=1, phase=0, sck=Pin(0), mosi=Pin(2), miso=Pin(4))
260
+ spi = SoftSPI (baudrate=100000, polarity=1, phase=0, sck=Pin(0), mosi=Pin(2), miso=Pin(4))
262
261
263
262
spi.init(baudrate=200000) # set the baudrate
264
263
@@ -298,39 +297,54 @@ mosi 13 23
298
297
miso 12 19
299
298
===== =========== ============
300
299
301
- Hardware SPI has the same methods as Software SPI above::
300
+ Hardware SPI is accessed via the :ref: `machine.SPI <machine.SPI >` class and
301
+ has the same methods as software SPI above::
302
302
303
303
from machine import Pin, SPI
304
304
305
305
hspi = SPI(1, 10000000, sck=Pin(14), mosi=Pin(13), miso=Pin(12))
306
306
vspi = SPI(2, baudrate=80000000, polarity=0, phase=0, bits=8, firstbit=0, sck=Pin(18), mosi=Pin(23), miso=Pin(19))
307
307
308
+ Software I2C bus
309
+ ----------------
308
310
309
- I2C bus
310
- -------
311
-
312
- The I2C driver has both software and hardware implementations, and the two
313
- hardware peripherals have identifiers 0 and 1. Any available output-capable
314
- pins can be used for SCL and SDA. The driver is accessed via the
315
- :ref: `machine.I2C <machine.I2C >` class::
316
-
317
- from machine import Pin, I2C
311
+ Software I2C (using bit-banging) works on all output-capable pins, and is
312
+ accessed via the :ref: `machine.SoftI2C <machine.SoftI2C >` class::
318
313
319
- # construct a software I2C bus
320
- i2c = I2C(scl=Pin(5), sda=Pin(4), freq=100000)
314
+ from machine import Pin, SoftI2C
321
315
322
- # construct a hardware I2C bus
323
- i2c = I2C(0)
324
- i2c = I2C(1, scl=Pin(5), sda=Pin(4), freq=400000)
316
+ i2c = SoftI2C(scl=Pin(5), sda=Pin(4), freq=100000)
325
317
326
- i2c.scan() # scan for slave devices
318
+ i2c.scan() # scan for devices
327
319
328
- i2c.readfrom(0x3a, 4) # read 4 bytes from slave device with address 0x3a
329
- i2c.writeto(0x3a, '12') # write '12' to slave device with address 0x3a
320
+ i2c.readfrom(0x3a, 4) # read 4 bytes from device with address 0x3a
321
+ i2c.writeto(0x3a, '12') # write '12' to device with address 0x3a
330
322
331
323
buf = bytearray(10) # create a buffer with 10 bytes
332
324
i2c.writeto(0x3a, buf) # write the given buffer to the slave
333
325
326
+ Hardware I2C bus
327
+ ----------------
328
+
329
+ There are two hardware I2C peripherals with identifiers 0 and 1. Any available
330
+ output-capable pins can be used for SCL and SDA but the defaults are given
331
+ below.
332
+
333
+ ===== =========== ============
334
+ \ I2C(0) I2C(1)
335
+ ===== =========== ============
336
+ scl 18 25
337
+ sda 19 26
338
+ ===== =========== ============
339
+
340
+ The driver is accessed via the :ref: `machine.I2C <machine.I2C >` class and
341
+ has the same methods as software I2C above::
342
+
343
+ from machine import Pin, I2C
344
+
345
+ i2c = I2C(0)
346
+ i2c = I2C(1, scl=Pin(5), sda=Pin(4), freq=400000)
347
+
334
348
Real time clock (RTC)
335
349
---------------------
336
350
0 commit comments