MCP4725  1.0.0
MCP4725 library DAC for PICO rp2040
Public Member Functions | List of all members
MCP4725_PICO Class Reference

Class for MCP4725_PIC0 DAC. More...

#include <mcp4725.hpp>

Public Member Functions

 MCP4725_PICO (float refV=MCP4725_REFERENCE_VOLTAGE)
 Constructor for class MCP4725_PIC0. More...
 
bool begin (MCP4725_I2C_Addr_e addr, i2c_inst_t *type, uint16_t speed, uint8_t SDA, uint8_t SCLK)
 Init & config i2c. More...
 
bool isConnected ()
 Checks if DAC is connected. More...
 
bool GeneralCall (MCP4725_GeneralCallType_e)
 General Call, name from datasheet section 7.3. More...
 
void deinitI2C ()
 Switch off the I2C interface and return I2C GPIO to default state.
 
void setReferenceVoltage (float value)
 Sets the reference voltage. More...
 
float getReferenceVoltage (void)
 Gets the reference voltage. More...
 
bool setInputCode (uint16_t inputCode, MCP4725_CmdType_e=MCP4725_FastMode, MCP4725_PowerDownType_e=MCP4725_PowerDown_Off)
 Set voltage out based on DAC input code. More...
 
uint16_t getInputCode (void)
 get current DAC InputCode from DAC register More...
 
bool setVoltage (float voltage, MCP4725_CmdType_e=MCP4725_FastMode, MCP4725_PowerDownType_e=MCP4725_PowerDown_Off)
 Set voltage out based on voltage input in volts. More...
 
float getVoltage (void)
 get DAC inputCode from DAC register & convert to volts More...
 
uint16_t getStoredInputCode (void)
 Read DAC inputCode from EEPROM. More...
 
float getStoredVoltage (void)
 Read stored DAC InputCode from EEPROM & convert to voltage. More...
 
uint16_t getPowerType (void)
 Get current power type from DAC register. More...
 
uint16_t getStoredPowerType (void)
 Get stored power type from EEPROM. More...
 
void setSerialDebugFlag (bool onOff)
 Setter for serial debug flag. More...
 
bool getSerialDebugFlag (void)
 Gets the serial Debug flag value. More...
 
void setSafetyCheckFlag (bool onOff)
 Setter for safety Check flag. More...
 
bool getSafetyCheckFlag (void)
 Gets the safety Check flag value. More...
 

Detailed Description

Class for MCP4725_PIC0 DAC.

Constructor & Destructor Documentation

◆ MCP4725_PICO()

MCP4725_PICO::MCP4725_PICO ( float  refV = MCP4725_REFERENCE_VOLTAGE)

Constructor for class MCP4725_PIC0.

Parameters
refVThe the reference voltage to be set in Volts.

Member Function Documentation

◆ begin()

bool MCP4725_PICO::begin ( MCP4725_I2C_Addr_e  addr,
i2c_inst_t *  i2c_type,
uint16_t  CLKspeed,
uint8_t  SDApin,
uint8_t  SCLKpin 
)

Init & config i2c.

Parameters
addrI2C address 8 bit address 0x6?.
i2c_typeI2C instance of port, IC20 or I2C1.
CLKspeedI2C Bus Clock speed in Kbit/s. see 7.1 datasheet
SDApinI2C Data GPIO
SCLKpinI2C Clock GPIO
Returns
true if success , false for failure

◆ GeneralCall()

bool MCP4725_PICO::GeneralCall ( MCP4725_GeneralCallType_e  typeCall)

General Call, name from datasheet section 7.3.

Parameters
typeCallReset or wakeup see MCP4725_GeneralCallType_e.
Returns
True on success, false on I2c error OR wrong input(GeneralCallAddress)
Note

  1. Reset MCP4725 & upload data from EEPROM to DAC register. Immediately after reset event, uploads contents of EEPROM into the DAC reg.
  2. Wake up & upload value from DAC register, Current power-down bits are set to normal, EEPROM power-down bit are not affected

◆ getInputCode()

uint16_t MCP4725_PICO::getInputCode ( void  )

get current DAC InputCode from DAC register

Returns
DAC InputCode :or 0xFFFF if I2C error

◆ getPowerType()

uint16_t MCP4725_PICO::getPowerType ( void  )

Get current power type from DAC register.

Returns
power type or 0xFFFF if I2C error
Note
Power type corresponds to enum MCP4725_PowerDownType_e

◆ getReferenceVoltage()

float MCP4725_PICO::getReferenceVoltage ( void  )

Gets the reference voltage.

Returns
The reference voltage in volts.

◆ getSafetyCheckFlag()

bool MCP4725_PICO::getSafetyCheckFlag ( void  )

Gets the safety Check flag value.

Returns
The safety Check flag value

◆ getSerialDebugFlag()

bool MCP4725_PICO::getSerialDebugFlag ( void  )

Gets the serial Debug flag value.

Returns
The serial Debug flag value

◆ getStoredInputCode()

uint16_t MCP4725_PICO::getStoredInputCode ( void  )

Read DAC inputCode from EEPROM.

Returns
stored EEPROM inputcode value or 0xFFFF if I2C error

◆ getStoredPowerType()

uint16_t MCP4725_PICO::getStoredPowerType ( void  )

Get stored power type from EEPROM.

Returns
EEPROM power type or 0xFFFF if I2C error
Note
Power type corresponds to enum MCP4725_PowerDownType_e

◆ getStoredVoltage()

float MCP4725_PICO::getStoredVoltage ( void  )

Read stored DAC InputCode from EEPROM & convert to voltage.

Returns
stored EEPROM voltage or 0xFFFF if I2C error

◆ getVoltage()

float MCP4725_PICO::getVoltage ( void  )

get DAC inputCode from DAC register & convert to volts

Returns
DAC voltage or 0xFFFF if I2C error

◆ isConnected()

bool MCP4725_PICO::isConnected ( )

Checks if DAC is connected.

Returns
true if DAC is connected , false if not

◆ setInputCode()

bool MCP4725_PICO::setInputCode ( uint16_t  InputCode,
MCP4725_CmdType_e  mode = MCP4725_FastMode,
MCP4725_PowerDownType_e  powerType = MCP4725_PowerDown_Off 
)

Set voltage out based on DAC input code.

Parameters
InputCode0 to MCP4725_MAX_VALUE.
modeMCP4725DAC mode, see enum MCP4725_CmdType_e.
powerTypeMCP4725DAC power type, see enum MCP4725_PowerType_e
Returns
output of writeCommand method, true for success, false for failure.

◆ setReferenceVoltage()

void MCP4725_PICO::setReferenceVoltage ( float  voltage)

Sets the reference voltage.

Parameters
voltagethe reference voltage to be set, called from constructor.

◆ setSafetyCheckFlag()

void MCP4725_PICO::setSafetyCheckFlag ( bool  onOff)

Setter for safety Check flag.

Parameters
onOffTurns or or off the safety check flag

◆ setSerialDebugFlag()

void MCP4725_PICO::setSerialDebugFlag ( bool  onOff)

Setter for serial debug flag.

Parameters
onOffTurns or or off the serial debug flag

◆ setVoltage()

bool MCP4725_PICO::setVoltage ( float  voltage,
MCP4725_CmdType_e  mode = MCP4725_FastMode,
MCP4725_PowerDownType_e  powerType = MCP4725_PowerDown_Off 
)

Set voltage out based on voltage input in volts.

Parameters
voltage0 to_MCP4725_REFERENCE_VOLTAGE, voltage out
modeMCP4725DAC mode, see enum MCP4725_CmdType_e.
powerTypeMCP4725DAC power type, see enum MCP4725_PowerType_e
Returns
output of writeCommand method, true for success, false for failure.

The documentation for this class was generated from the following files: