Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of MCP4725 by
MCP4725 Class Reference
#include <MCP4725.h>
Public Types | |
enum | Address { ADDRESS_0 = (0x60 << 1), ADDRESS_1 = (0x61 << 1), ADDRESS_2 = (0x62 << 1), ADDRESS_3 = (0x63 << 1), ADDRESS_4 = (0x64 << 1), ADDRESS_5 = (0x65 << 1), ADDRESS_6 = (0x67 << 1), ADDRESS_7 = (0x68 << 1) } |
Represents the different I2C address possibilities for the MCP4725. More... | |
enum | PowerMode { POWER_NORMAL, POWER_SHUTDOWN_1K, POWER_SHUTDOWN_100K, POWER_SHUTDOWN_500K } |
Represents the power mode of the MCP4725. More... | |
Public Member Functions | |
MCP4725 (PinName sda, PinName scl, Address addr=ADDRESS_0, int hz=400000) | |
Create an MCP4725 object connected to the specified I2C pins with the specified I2C slave address. | |
bool | open () |
Probe for the MCP4725 and indicate if it's present on the bus. | |
void | reset () |
Issue a General Call Reset command to reset all MCP4725 devices on the bus. | |
void | wakeup () |
Issue a General Call Wake-up command to power-up all MCP4725 devices on the bus. | |
MCP4725::PowerMode | powerMode () |
Get the current power mode of the MCP4725. | |
void | powerMode (PowerMode mode) |
Set the power mode of the MCP4725. | |
float | read () |
Get the current output voltage of the MCP4725 as a percentage. | |
void | write (float value) |
Set the output voltage of the MCP4725 from a percentage. | |
void | write_u12 (unsigned short value) |
Set the output voltage of the MCP4725 from a 16-bit range. | |
void | readEeprom (PowerMode *mode, unsigned short *value) |
Get the current DAC settings in EEPROM. | |
void | writeEeprom (PowerMode mode, unsigned short value) |
Set the DAC settings in EEPROM. | |
operator float () | |
A shorthand for read() | |
MCP4725 & | operator= (float value) |
A shorthand for write() |
Detailed Description
MCP4725 class.
Used for controlling an MCP4725 DAC connected via I2C.
Example:
#include "mbed.h" #include "MCP4725.h" //Create an MCP4725 object at the default address (ADDRESS_0) MCP4725 dac(p28, p27); int main() { //Try to open the MCP4725 if (dac.open()) { printf("Device detected!\n"); //Wake up the DAC //NOTE: This might wake up other I2C devices as well! dac.wakeup(); while (1) { //Generate a sine wave on the DAC for (float i = 0.0; i < 360.0; i += 0.1) dac = 0.5 * (sinf(i * 3.14159265 / 180.0) + 1); } } else { error("Device not detected!\n"); } }
Definition at line 54 of file MCP4725.h.
Member Enumeration Documentation
enum Address |
Represents the different I2C address possibilities for the MCP4725.
enum PowerMode |
Represents the power mode of the MCP4725.
- Enumerator:
Constructor & Destructor Documentation
Create an MCP4725 object connected to the specified I2C pins with the specified I2C slave address.
- Parameters:
-
sda The I2C data pin. scl The I2C clock pin. addr The I2C slave address (defaults to ADDRESS_0). hz The I2C bus frequency (defaults to 400kHz).
Definition at line 19 of file MCP4725.cpp.
Member Function Documentation
bool open | ( | ) |
Probe for the MCP4725 and indicate if it's present on the bus.
- Returns:
- 'true' if the device exists on the bus, 'false' if the device doesn't exist on the bus.
Definition at line 25 of file MCP4725.cpp.
operator float | ( | ) |
A shorthand for read()
- Returns:
- The current output voltage as a percentage (0.0 to 1.0 * VDD).
Definition at line 141 of file MCP4725.cpp.
MCP4725 & operator= | ( | float | value ) |
A shorthand for write()
- Parameters:
-
value The new output voltage as a percentage (0.0 to 1.0 * VDD).
Definition at line 147 of file MCP4725.cpp.
MCP4725::PowerMode powerMode | ( | ) |
Get the current power mode of the MCP4725.
- Returns:
- The current power mode as a PowerMode enum.
Definition at line 55 of file MCP4725.cpp.
void powerMode | ( | PowerMode | mode ) |
Set the power mode of the MCP4725.
- Parameters:
-
mode The new power mode as a PowerMode enum.
Definition at line 64 of file MCP4725.cpp.
float read | ( | ) |
Get the current output voltage of the MCP4725 as a percentage.
- Returns:
- The current output voltage as a percentage (0.0 to 1.0 * VDD).
Definition at line 73 of file MCP4725.cpp.
void readEeprom | ( | PowerMode * | mode, |
unsigned short * | value | ||
) |
Get the current DAC settings in EEPROM.
- Parameters:
-
mode Pointer to a PowerMode enum for the power mode in EEPROM. value Pointer to an unsigned short for the 12-bit DAC value in EEPROM (0x0000 to 0x0FFF).
Definition at line 106 of file MCP4725.cpp.
void reset | ( | ) |
Issue a General Call Reset command to reset all MCP4725 devices on the bus.
- Warning:
- This might reset other I2C devices as well
Definition at line 37 of file MCP4725.cpp.
void wakeup | ( | ) |
Issue a General Call Wake-up command to power-up all MCP4725 devices on the bus.
- Warning:
- This might wake up other I2C devices as well
Definition at line 46 of file MCP4725.cpp.
void write | ( | float | value ) |
Set the output voltage of the MCP4725 from a percentage.
- Parameters:
-
value The new output voltage as a percentage (0.0 to 1.0 * VDD).
Definition at line 82 of file MCP4725.cpp.
void write_u12 | ( | unsigned short | value ) |
Set the output voltage of the MCP4725 from a 16-bit range.
- Parameters:
-
value The new output voltage as a 16-bit unsigned short (0x0000 to 0xFFFF).
Definition at line 97 of file MCP4725.cpp.
void writeEeprom | ( | PowerMode | mode, |
unsigned short | value | ||
) |
Set the DAC settings in EEPROM.
- Parameters:
-
mode The new EEPROM power mode as a PowerMode enum. value The new EEPROM DAC value as a 12-bit unsigned short (0x0000 to 0x0FFF).
Definition at line 121 of file MCP4725.cpp.
Generated on Fri Jul 15 2022 16:53:58 by
