2

I am trying to read data from the ADS7828 12-bit ADC through my Raspberry Pi's I2C port.

The datasheet for the ADC mentions (on page 12) that once I read address the ADC it will return the 12 bit split into two bytes.

I am having issue reading two bytes at a time from the ADC using the i2cget command (with the 'w' option) from i2ctools as well as the smbus.read_word_data() function in python. Both these commands/methods require a second argument which will also be written to the SDA line following the read address. However my ADC expects only the address and the R/W bit set appropriately.

If I read just one byte using i2cget or smbus.read_byte (both of which sends ONLY the device address, and requires no second argument) I get first 4 MSB of the converted voltage which seems to match my expectations.

But when I try to read a two bytes at a time I am forced to give some second argument which the device does not expect. I tried to set this second argument to 0xFF in the hopes that the "active 0" behavior of the I2C will work to my advantage, but no such luck; any second argument that I give causes the ADC to return some nonsensical value ( I tried 0x00 too).

How can I get RPi to read two bytes from my device, preferably with Python?

1 Answer 1

1

The simplest way I know of is to use my pigpio Python module.

I would use i2c_write_device to select the register to read and then i2c_read_device to read two bytes.

There are other ways from Python involving IOCTLs which will also work.

1
  • Thanks, i2c_read_device() was just what I was looking for.
    – Akhil Prem
    May 17, 2016 at 10:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.