|
10 | 10 |
|
11 | 11 | from machine import Pin, I2C |
12 | 12 |
|
13 | | -clk = Pin(("clk", 43), Pin.OUT_OD) # Select the 43 pin device as the clock |
14 | | -sda = Pin(("sda", 44), Pin.OUT_OD) # Select the 44 pin device as the data line |
15 | | -i2c = I2C(-1, clk, sda, freq=100000) # create I2C peripheral at frequency of 100kHz |
16 | | -i2c.scan() # scan for slaves, returning a list of 7-bit addresses |
17 | | -i2c.writeto(0x51, b'123') # write 3 bytes to slave with 7-bit address 42 |
18 | | -i2c.readfrom(0x51, 4) # read 4 bytes from slave with 7-bit address 42 |
19 | | -i2c.readfrom_mem(0x51, 0x02, 1) # read 1 bytes from memory of slave 0x51(7-bit) |
20 | | -i2c.writeto_mem(0x51, 2, b'\x10') # write 1 byte to memory of slave 42 |
| 13 | +PIN_CLK = 29 # PB13, get the pin number from get_pin_number.py |
| 14 | +PIN_SDA = 30 # PB14 |
| 15 | + |
| 16 | +clk = Pin(("clk", PIN_CLK), Pin.OUT_OD) # Select the PIN_CLK pin device as the clock |
| 17 | +sda = Pin(("sda", PIN_SDA), Pin.OUT_OD) # Select the PIN_SDA pin device as the data line |
| 18 | +i2c = I2C(-1, clk, sda, freq=100000) # create I2C peripheral at frequency of 100kHz |
| 19 | +i2c.scan() # scan for slaves, returning a list of 7-bit addresses |
| 20 | +i2c.writeto(0x51, b'123') # write 3 bytes to slave with 7-bit address 42 |
| 21 | +i2c.readfrom(0x51, 4) # read 4 bytes from slave with 7-bit address 42 |
| 22 | +i2c.readfrom_mem(0x51, 0x02, 1) # read 1 bytes from memory of slave 0x51(7-bit) |
| 23 | +i2c.writeto_mem(0x51, 2, b'\x10') # write 1 byte to memory of slave 42 |
21 | 24 |
|
0 commit comments