You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

树莓派I2C读取LTC2453 ADC失败:SMBus格式不匹配问题求助

树莓派Python通过I2C读取LTC2453 ADC的SMBus格式匹配问题

在树莓派上使用Python通过I2C读取LTC2453 ADC时遇到问题,推测是SMBus输出格式与ADC预期不匹配导致的。

在Python程序中调用bus.read_i2c_block_data()命令读取ADC时,出现错误:OSError: [Errno 121] Remote I/O error。通过示波器捕获SCK和SDA线的信号后发现,通信过程发送了四个字节:地址字节、寄存器字节和两个数据字节。其中地址字节是树莓派发送的7位地址后跟随0,但ADC未给出应答(ACK),这应该就是报错的原因。

使用i2cdetect -y 1命令扫描设备时,ADC同样未应答——此时树莓派也是发送地址后跟随0,未收到ADC的应答位,因此无法检测到该设备。

查阅LTC2453数据手册第10页可知,ADC要求7位地址后跟随1才会应答;示波器波形也显示,当寄存器地址为7位地址后跟随1时,ADC会应答并输出两个数据字节。

现需了解如何仅发送地址+读位(1),然后采集两个字节的数据。

Python代码

from smbus import SMBus
import re
import time

adcAddress = 0x14
adcRegister = 0x29
adcReading = bytearray()
adcReading.append(0x00)
adcReading.append(0x00)
adcReading.append(0x00)
adcReading.append(0x00)

bus = SMBus(1)
time.sleep(1)

def getReading(address, register):
    adcReading = bus.read_i2c_block_data(address, register, 2)
    h = adcReading[0]
    m = adcReading[1]
    t = ((h & 0b01111111) << 8) | m
    return t

while True:
    v = getReading(adcAddress, adcRegister)
    print(v)
    print('\n')

内容的提问来源于stack exchange,提问作者user3026317

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.26 00:18:21