adafruit / adafruit/Adafruit_CircuitPython_MCP4728
reset method not working
- Dominant language
- Python
- Stars
- 6
- Forks
- 8
- PR merge metrics
- No merged PRs in 30d
Description
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:
```python
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:
```text
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)]
```
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by reading the reset() and _general_call implementations, then compare the bytes they send with the manual I2C write of b'\x06' shown in the report. Re-run the provided example and verify that reset restores all four DAC registers to their EEPROM-saved values rather than changing only channel A.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- embedded-iot
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 65/100