日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程语言 > python >内容正文

python

如何用python的i2c教程_Micropython TPYBoard I2C的用法

發(fā)布時(shí)間:2025/3/12 python 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 如何用python的i2c教程_Micropython TPYBoard I2C的用法 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

先看看基本用法:

from pyb import I2C

i2c = I2C(1) ? ? ? ? ? ? ? ? ? ? ? ? # create on bus 1

i2c = I2C(1, I2C.MASTER) ? ? ? ? ? ? # create and init as a master

i2c.init(I2C.MASTER, baudrate=20000) # init as a master

i2c.init(I2C.SLAVE, addr=0x42) ? ? ? # init as a slave with given address

i2c.deinit() ? ? ? ? ? ? ? ? ? ? ? ? # turn off the peripheral

i2c.init(I2C.MASTER)

i2c.send(‘123‘, 0x42) ? ? ? ?# send 3 bytes to slave with address 0x42

i2c.send(b‘456‘, addr=0x42) ?# keyword for address

i2c.is_ready(0x42) ? ? ? ? ? # check if slave 0x42 is ready

i2c.scan() ? ? ? ? ? ? ? ? ? # scan for slaves on the bus, returning

# ? a list of valid addresses

i2c.mem_read(3, 0x42, 2) ? ? # read 3 bytes from memory of slave 0x42,

# ? starting at address 2 in the slave

i2c.mem_write(‘a(chǎn)bc‘, 0x42, 2, timeout=1000) # write ‘a(chǎn)bc‘ (3 bytes) to memory of slave 0x42

# starting at address 2 in the slave, timeout after 1 second

I2C的用法:

class pyb.I2C(bus, ...)

bus,I2C總線的序號(hào)

i2c.deinit(),解除I2C定義

i2c.init(mode, *, addr=0x12, baudrate=400000, gencall=False),初始化

mode,只能是 I2C.MASTER 或 I2C.SLAVE

addr,7位I2C地址

baudrate,時(shí)鐘頻率

gencall,通用調(diào)用模式

i2c.is_ready(addr),檢測(cè)I2C設(shè)備是否響應(yīng),只對(duì)主模式有效

i2c.mem_read(data, addr, memaddr, *, timeout=5000, addr_size=8),讀取數(shù)據(jù)

data,整數(shù)或者緩存

addr,設(shè)備地址

memaddr,內(nèi)存地址

timeout,讀取等待超時(shí)時(shí)間

addr_size,memaddr的大小。8位或16位

i2c.mem_write(data, addr, memaddr, *, timeout=5000, addr_size=8),寫(xiě)入數(shù)據(jù),參數(shù)含義同上

i2c.recv(recv, addr=0x00, *, timeout=5000),從總線讀取數(shù)據(jù)

recv,需要讀取數(shù)據(jù)數(shù)量,或者緩沖區(qū)

addr,I2C地址

timeout,超時(shí)時(shí)間

i2c.send(send, addr=0x00, *, timeout=5000)

send,整數(shù)或者緩沖區(qū)

addr,I2C地址

timeout,超時(shí)時(shí)間

i2c.scan(),搜索I2C總線上設(shè)備。

總結(jié)

以上是生活随笔為你收集整理的如何用python的i2c教程_Micropython TPYBoard I2C的用法的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。