Skip to content

Commit 1b10160

Browse files
committed
Add I2C General Call Commands
This Commit, - Adds _general_call static methods for executing different general calls to MCP4728 - Adds reset, wakeup and soft_update general call static methods
1 parent c81f84f commit 1b10160

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

adafruit_mcp4728.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636

3737
_MCP4728_CH_A_MULTI_EEPROM = 0x50
3838

39+
_MCP4728_GENERAL_CALL_ADDRESS = 0x00
3940

4041
class CV:
4142
"""struct helper"""
@@ -227,6 +228,41 @@ def _chunk(big_list, chunk_size):
227228
for i in range(0, len(big_list), chunk_size):
228229
yield big_list[i : i + chunk_size]
229230

231+
@staticmethod
232+
def _general_call(byte_command):
233+
buffer_list = [_MCP4728_GENERAL_CALL_ADDRESS]
234+
buffer_list += byte_command
235+
236+
buf = bytearray(buffer_list)
237+
238+
with self.i2c_device as i2c:
239+
i2c.write(buf)
240+
241+
@staticmethod
242+
def reset():
243+
"""Internal Reset similar to a Power-on Reset (POR).
244+
The contents of the EEPROM are loaded into each DAC input
245+
and output registers immediately"""
246+
247+
reset_command = [0x06]
248+
self._general_call(reset_command)
249+
250+
@staticmethod
251+
def wakeup():
252+
"""Reset the Power-Down bits (PD1, PD0 = 0,0) and
253+
Resumes Normal Operation mode"""
254+
255+
wakeup_command = [0x09]
256+
self._general_call(wakeup_command)
257+
258+
@staticmethod
259+
def soft_update():
260+
"""Updates all DAC analog outputs (VOUT) at the same time."""
261+
262+
soft_update_command = [0x08]
263+
self._general_call(soft_update_command)
264+
265+
#TODO : general_call read address
230266

231267
class Channel:
232268
"""An instance of a single channel for a multi-channel DAC.

0 commit comments

Comments
 (0)