Skip to content

Commit 0e8af0b

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 0e8af0b

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

adafruit_mcp4728.py

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

3737
_MCP4728_CH_A_MULTI_EEPROM = 0x50
3838

39+
_MCP4728_GENERAL_CALL_ADDRESS = 0x00
40+
3941

4042
class CV:
4143
"""struct helper"""
@@ -227,6 +229,38 @@ def _chunk(big_list, chunk_size):
227229
for i in range(0, len(big_list), chunk_size):
228230
yield big_list[i : i + chunk_size]
229231

232+
def _general_call(self, 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+
def reset(self):
242+
"""Internal Reset similar to a Power-on Reset (POR).
243+
The contents of the EEPROM are loaded into each DAC input
244+
and output registers immediately"""
245+
246+
reset_command = [0x06]
247+
self._general_call(reset_command)
248+
249+
def wakeup(self):
250+
"""Reset the Power-Down bits (PD1, PD0 = 0,0) and
251+
Resumes Normal Operation mode"""
252+
253+
wakeup_command = [0x09]
254+
self._general_call(wakeup_command)
255+
256+
def soft_update(self):
257+
"""Updates all DAC analog outputs (VOUT) at the same time."""
258+
259+
soft_update_command = [0x08]
260+
self._general_call(soft_update_command)
261+
262+
# TODO : general_call read address
263+
230264

231265
class Channel:
232266
"""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)