0

I am unable to read an ADC (LTC2453) over i2c using a Raspberry Pi and python. I believe the problem is a mismatch between what SMBus outputs and what the ADC expects.

In my python program (copied below) I call for an ADC read with the bus.read_block_data() command and get the following error message: OSError: [Errno 121] Remote I/O error. I recorded oscilloscope traces showing how the SCK and SDA lines behave when this happens (figure linked below). The scope traces show four bytes of data, which I have labeled "address byte", "register byte" and "two bytes of data". The address byte shows that the Raspberry Pi outputs the 7 bit address followed by a 0, and that the ADC does not acknowledge. I believe the NACK from the ADC is why I get the error message. Scope traces I note that when I look for devices on the Raspberry Pi using the i2cdetect -y 1 command, the ADC does not acknowledge. This is also a case where the Raspberry Pi sends the address followed by 0 and again it gets no acknowledge bit from the ADC and the pi does not report seeing the ADC. Thus, it appears that the ADC requires the 1 following the 7 bit address. The behavior expected by the ADC is described on page 10 of its datasheet.

As shown in the scope traces linked above, the ADC does acknowledge the register address, which is comprised of the 7 bit address followed by a '1'. Receiving the correct signal, the ADC then outputs the two bytes of data. I would be grateful if someone could tell me how to just send the address followed by the read bit (1) and then collect two bytes of data.

python sketch:

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’)
0andriy
  • 4,183
  • 1
  • 24
  • 37

1 Answers1

0

Problem solved but not using python. I wrote new code in Processing using available libraries. I could not get Processing to download onto my Pi Zero but was able to get it running on a Pi 4B. Once I had the program running, I moved the SD card from the 4B to the Zero where the program worked fine. I then exported an executable, which runs also fine on my PI Zero.

  • Please use the edit link on your question to add additional information. The Post Answer button should be used only for complete answers to the question. - [From Review](/review/late-answers/32774615) – ohe Sep 27 '22 at 12:42