Skip to content

Commit 7a41d0a

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 7a41d0a

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed

adafruit_mcp4728.py

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

3737
_MCP4728_CH_A_MULTI_EEPROM = 0x50
3838

39+
_MCP4728_GENERAL_CALL_ADDRESS = 0x00
40+
41+
_MCP4728_GENERAL_CALL_RESET_COMMAND = 0x06
42+
43+
_MCP4728_GENERAL_CALL_WAKEUP_COMMAND = 0x09
44+
45+
_MCP4728_GENERAL_CALL_SOFTWARE_UPDATE_COMMAND = 0x08
46+
3947

4048
class CV:
4149
"""struct helper"""
@@ -227,6 +235,35 @@ def _chunk(big_list, chunk_size):
227235
for i in range(0, len(big_list), chunk_size):
228236
yield big_list[i : i + chunk_size]
229237

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

231268
class Channel:
232269
"""An instance of a single channel for a multi-channel DAC.

examples/mcp4728_generalcalltest.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
2+
# SPDX-License-Identifier: MIT
3+
4+
import board
5+
import adafruit_mcp4728
6+
7+
i2c = board.I2C() # uses board.SCL and board.SDA
8+
mcp4728 = adafruit_mcp4728.MCP4728(i2c)
9+
10+
mcp4728.channel_a.value = 65535 # Voltage = VDD
11+
mcp4728.channel_b.value = int(65535 / 2) # VDD/2
12+
mcp4728.channel_c.value = int(65535 / 4) # VDD/4
13+
mcp4728.channel_d.value = 0 # 0V
14+
15+
mcp4728.save_settings() # save current voltages into EEPROM
16+
17+
mcp4728.channel_a.value = 0 # Modify output
18+
mcp4728.channel_b.value = 0 # Modify output
19+
mcp4728.channel_c.value = 0 # Modify output
20+
mcp4728.channel_d.value = 65535 # Modify output
21+
22+
mcp4728.reset() # reset MCP4728

0 commit comments

Comments
 (0)