Hi,
We need to control an MCP4725 DAC from an nRF52832 SoC, and for one reason or the other, no example we've found works.
This next was the last attempt, based on the examples from "\nordic\v2.3.0\zephyr\samples\drivers\dac". I created the board files in a folder, separated from the project, and added that folder to BOARD_ROOT
.
1) Added the i2c node in the dts
as:
&i2c0 {
compatible = "nordic,nrf-twi";
status = "okay";
pinctrl-0 = <&i2c0_default>;
pinctrl-1 = <&i2c0_sleep>;
pinctrl-names = "default", "sleep";
dac0: mcp4725@60 {
compatible = "microchip,mcp4725";
reg = <0x60>;
#io-channel-cells = <1>;
};
};
2) In defined the pins in the dtsi
:
&pinctrl {
i2c0_default: i2c0_default {
group1 {
psels = <NRF_PSEL(TWIM_SDA, 0, 7)>,
<NRF_PSEL(TWIM_SCL, 0, 6)>;
bias-pull-up;
};
};
i2c0_sleep: i2c0_sleep {
group1 {
psels = <NRF_PSEL(TWIM_SDA, 0, 7)>,
<NRF_PSEL(TWIM_SCL, 0, 6)>;
low-power-enable;
};
};
};
3) Added this to the overlay file:
/ {
zephyr,user {
dac = <&dac0>;
dac-channel-id = <0>;
dac-resolution = <12>;
};
};
4) Enabled required modules in prj.conf:
CONFIG_GPIO=y
CONFIG_NFCT_PINS_AS_GPIOS=y
CONFIG_I2C=y
CONFIG_PINCTRL=y
CONFIG_DAC=y
CONFIG_DAC_MCP4725=y
5) And used following code, extracted from the dac example:
#if (DT_NODE_HAS_PROP(ZEPHYR_USER_NODE, dac) && \
DT_NODE_HAS_PROP(ZEPHYR_USER_NODE, dac_channel_id) && \
DT_NODE_HAS_PROP(ZEPHYR_USER_NODE, dac_resolution))
#define DAC_NODE DT_PHANDLE(ZEPHYR_USER_NODE, dac)
#define DAC_CHANNEL_ID DT_PROP(ZEPHYR_USER_NODE, dac_channel_id)
#define DAC_RESOLUTION DT_PROP(ZEPHYR_USER_NODE, dac_resolution)
#else
#error "Unsupported board: see README and check /zephyr,user node"
#define DAC_NODE DT_INVALID_NODE
#define DAC_CHANNEL_ID 0
#define DAC_RESOLUTION 0
#endif
static const struct device *const dac_dev = DEVICE_DT_GET(DAC_NODE);
static const struct dac_channel_cfg dac_ch_cfg = {
.channel_id = DAC_CHANNEL_ID,
.resolution = DAC_RESOLUTION
};
static bool init_dac()
{
if (!device_is_ready(dac_dev)) {
printk("DAC device %s is not ready\n", dac_dev->name);
return false;
}
int ret = dac_channel_setup(dac_dev, &dac_ch_cfg);
if (ret != 0) {
printk("Setting up of DAC channel failed with code %d\n", ret);
return false;
}
---- etc -----
The result is device_is_ready(...)
always returns false.
Where can I find a working example of controlling an MCP4725 DAC from a nRF52832?
BR