I have a DAC device with I2C address 0x48 and I want to read and write to register 0x20.
i2cget 1 0x48 0x20 returns:
Writing to this register in a python script works, and the DAC respond as expected.Reading from this register in a python script fails.
This is the script that fails:
Can someone explain this and suggest a working solution?
i2cget 1 0x48 0x20 returns:
I2cdump also works and displays the correct value.i2cget 1 0x48 0x20
WARNING! This program can confuse your I2C bus, cause data loss and worse!
I will read from device file /dev/i2c-1, chip address 0x48, data address
0x20, using read byte data.
Continue? [Y/n]
0x44
Writing to this register in a python script works, and the DAC respond as expected.
This is the script that works:Write success: Register 0x20 = 85
Code:
import sysimport smbusimport timechannel = 1address = 0x48bus = smbus.SMBus(channel)try: reg = 0x20 # replace with a writeably register from docs. val = 85 # replace with the desired value to write. bus.write_byte_data(address, reg, 100 - val) print(f"Write success: Register 0x{reg:02X} = {val}")except OSError as e: print(f"Write failed: {e}")It also makes the device address disappear from the i2c bus, needs a power restart to reappear.Read failed: [Errno 5] Input/output error
This is the script that fails:
Code:
import smbusimport timechannel = 1address = 0x48bus = smbus.SMBus(channel)try: reg = 0x20 # replace with a read-only register from docs val = bus.read_byte_data(address, reg) print(f"Read success: Register 0x{reg:02X} = {val}") except OSError as e: print(f"Read failed: {e}")Statistics: Posted by bnilsson — Thu May 15, 2025 9:45 am