Skip to content

reset method not working #18

@fabh2o

Description

@fabh2o

The .reset() method is not working properly: it fails to restore the DAC registers to the EEPROM-saved values. Sending the bytes directly on the I2C bus works.
Code example demonstrating this behaviour:

import adafruit_mcp4728
import board
import time

i2c = board.I2C()
mcp4728 =  adafruit_mcp4728.MCP4728(i2c)

print('DAC: Initialize to 0V')
for channel in [
                mcp4728.channel_a,
                mcp4728.channel_b,
                mcp4728.channel_c,
                mcp4728.channel_d
                ]:
    channel.raw_value = 0
    channel.vref = adafruit_mcp4728.Vref.INTERNAL
    channel.gain = 1
time.sleep(1)
print(f'DAC: _read_registers() \n\t{mcp4728._read_registers()}')
mcp4728.save_settings()
time.sleep(1)

def load_values():
    print('DAC: loading values')
    mcp4728.channel_a.raw_value = int(2048)
    mcp4728.channel_b.raw_value = int(1024)
    mcp4728.channel_c.raw_value = int(512)
    mcp4728.channel_d.raw_value = int(256)
    print(f'DAC: _read_registers() \n\t{mcp4728._read_registers()}')
    print()
    time.sleep(1)

load_values()
print('DAC: mcp4728.reset()')
mcp4728.reset()
print(f'DAC: _read_registers() \n\t{mcp4728._read_registers()}')


load_values()
print('HACK: manual GC reset')
if i2c.try_lock():
    i2c.writeto(0x00, b'\x06')
    i2c.unlock()
else:
    print('**ERROR** could not claim I2C bus')
print(f'DAC: _read_registers() \n\t{mcp4728._read_registers()}')
time.sleep(1e3)

Relative output (modified lib to print the buf variable when _general_call is called:

DAC: Initialize to 0V
DAC: _read_registers()
        [(0, True, False, 0), (0, True, False, 0), (0, True, False, 0), (0, True, False, 0)]
DAC: loading values
DAC: _read_registers()
        [(2048, True, False, 0), (1024, True, False, 0), (512, True, False, 0), (256, True, False, 0)]

DAC: mcp4728.reset()
LIB: reset() method called
LIB: _general_call buf: bytearray(b'\x00\x06')
DAC: _read_registers()
        [(6, True, False, 0), (1024, True, False, 0), (512, True, False, 0), (256, True, False, 0)]
DAC: loading values
DAC: _read_registers()
        [(2048, True, False, 0), (1024, True, False, 0), (512, True, False, 0), (256, True, False, 0)]

HACK: manual GC reset
DAC: _read_registers()
        [(0, True, False, 0), (0, True, False, 0), (0, True, False, 0), (0, True, False, 0)]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions