MCP ExplorerExplorer

Rp2040 Mcp4728 Lib

@rppicomidion 9 months ago
4 MIT
FreeCommunity
AI Systems
#digital-to-analog-converter#mcp4728#raspberry-pi-pico#rp2040#4-channel-dac#i2c-dac
RP2040 driver library for the MCP4728 4-channel I2C DAC with example code

Overview

What is Rp2040 Mcp4728 Lib

The rp2040-mcp4728-lib is a C++ library designed for the RP2040 microcontroller, providing a driver for the MCP4728 4-channel I2C Digital-to-Analog Converter (DAC). It includes example code to facilitate integration and usage.

Use cases

Use cases for the rp2040-mcp4728-lib include generating audio signals, controlling motors with analog signals, and interfacing with sensors that require analog output. It is suitable for projects involving the RP2040 and the MCP4728 DAC.

How to use

To use the rp2040-mcp4728-lib, include the library in your project and periodically call the task() method of the RP2040_MCP4728 class. This can be done in a super-loop or a separate thread. Example codes are available in the examples directory.

Key features

Key features of the rp2040-mcp4728-lib include support for all I2C functions of the MCP4728, non-blocking and interrupt-driven operations, multi-core safety, and optional LDAC pin toggling. It also supports sharing the I2C bus with other devices.

Where to use

The rp2040-mcp4728-lib can be used in applications requiring precise analog output, such as audio processing, sensor data representation, and control systems in embedded systems and robotics.

Content

rp2040-mcp4728-lib

C++ library for the RP2040 and the MCP4728 4-channel DAC + example code

The rp2040-mcp4728-lib implements all of the I2C functions the MCP4728 supports.
There is an API for toggling the LDAC pin if it is used, but none for
or polling the RDY/BSY\ pin.
Use of the LDAC\ pin is optional unless your software needs to
read the MCP4728 I2C address or reprogram the MCP4728 I2C address.
Those functions require timing the LDAC\ pin against the I2C clock. The
rppicomidi::RP2040_MCP4728::access_addr_bits() function supports these
two functions. So unless you are reading and writing the I2C address
bits on the MCP4728 chip, you can implement a complete system with
just the I2C SCL and SDA pins. See the MCP4728 data sheet for more
information.

All functions in this library except rppicomidi::RP2040_MCP4728::access_addr_bits()
are interrupt driven and non-blocking with callbacks when I2C accesses are complete.
The functions are multi-core safe and application callbacks are called in non-interrupt
context. The application must call the RP2040_MCP4728 class’s task() method
peridocially, either as part of a super-loop or in its own thread. The underlying
I2C library is probably useful for other devices, too. It supportes sharing the I2C bus
with other devices.

The rppicomidi::RP2040_MCP4728::access_addr_bits() is implemented using
software-controlled bit-banging. It does not use PIO resources because
that function is likely to be called only during board bringup on systems
that require an I2C address other than factory standard.

The rp2040-mcp4728-cli-lib implements a command line interface (CLI) for
testing all of the functions in the rp2040-mcp4728-lib. It uses the
wonderful embedded-cli library by Sviatoslav Kokurin (funbiscuit), which
must be initialized and included in the build of whatever project uses
it. If your project does not need a CLI, there is no need to use it.

Example code is found in the examples directory.
Each example’s code is described in the README.md file contained in each
example’s directory. At the time of this writing, there is only one
example: a CLI-driven program that exercises all of the features of both
rp2040-mcp4728-lib and rp2040-mcp4728-cli-lib.

Tools

No tools

Comments

Recommend MCP Servers

View All MCP Servers