Manuel Caballero / MCP4725
Embed: (wiki syntax)

« Back to documentation index

MCP4725 Class Reference

MCP4725 Class Reference

Example: More...

#include <MCP4725.h>

Public Types

enum  MCP4725_address_t { MCP4725_ADDRESS_LOW = ( 0x62 << 1 ), MCP4725_ADDRESS_HIGH = ( 0x63 << 1 ) }
 

DEFAULT ADDRESSES ( NOTE1: The A2 and A1 are programmed to '00' (default), if not requested by customer.

More...
enum  MCP4725_write_command_type_t { FAST_MODE = 0, WRITE_DAC_REGISTER_MODE = 1, WRITE_DAC_AND_EEPROM_REGISTER_MODE = 2 }
 

WRITE COMMAND TYPE.

More...
enum  MCP4725_operation_mode_t { NORMAL_MODE = 0, POWER_DOWN_1KOHM_RESISTIVE_LOAD_MODE = 1, POWER_DOWN_100KOHM_RESISTIVE_LOAD_MODE = 2, POWER_DOWN_500KOHM_RESISTIVE_LOAD_MODE = 3 }
 

POWER-DOWN MODE.

More...
enum  MCP4725_eeprom_status_t { EEPROM_BUSY = 0, EEPROM_READY = 1 }
 

READY/BUSY BIT.

More...
enum  MCP4725_status_t { , I2C_SUCCESS = 0 }
 

INTERNAL CONSTANTS.

More...

Public Member Functions

 MCP4725 (PinName sda, PinName scl, uint32_t addr, uint32_t freq)
 Create an MCP4725 object connected to the specified I2C pins.
 ~MCP4725 ()
 Delete MCP4725 object.
MCP4725_status_t MCP4725_Reset (void)
 It performs an internal reset similar to a power-on-reset ( POR ).
MCP4725_status_t MCP4725_WakeUp (void)
 The power-down bits of the DAC register are set to a normal operation.
MCP4725_status_t MCP4725_PowerMode (MCP4725_write_command_type_t myWriteCMD, MCP4725_operation_mode_t myPowerMode)
 It configures the power mode of the device.
MCP4725_status_t MCP4725_SetNewValue (MCP4725_write_command_type_t myWriteCMD, Vector_new_dac_value_t myDACNewValue)
 It sets a new output value.
MCP4725_status_t MCP4725_EEPROM_Status (MCP4725_eeprom_status_t *myEEPROM_Status)
 It gets the eeprom status.
MCP4725_status_t MCP4725_GetEEPROM_Data (Vector_data_t *myEEPROMData)
 It gets the last eeprom stored value.
MCP4725_status_t MCP4725_GetDAC_Data (Vector_data_t *myDACData)
 It gets the last dac stored value.

Detailed Description

Example:

include "mbed.h" include "MCP4725.h"

MCP4725 myDACSensor ( I2C_SDA, I2C_SCL, MCP4725::MCP4725_ADDRESS_LOW, 400000 );

Ticker newDACOutput; DigitalOut myled(LED1);

MCP4725::MCP4725_status_t aux; uint8_t myState = 0;

void changeDATA ( void ) { MCP4725::Vector_new_dac_value_t myNewDAC_Value;

myled = 1;

switch ( myState ) { default: case 0: Vout ~ 0V myNewDAC_Value.DAC_New_Value = 0; aux = myDACSensor.MCP4725_SetNewValue ( MCP4725::FAST_MODE, myNewDAC_Value );

myState = 1; break;

case 1: Vout = ~ ( Vref * 0.5 ) myNewDAC_Value.DAC_New_Value = 2048; aux = myDACSensor.MCP4725_SetNewValue ( MCP4725::WRITE_DAC_AND_EEPROM_REGISTER_MODE, myNewDAC_Value );

myState = 2; break;

case 2: Vout ~ Vref myNewDAC_Value.DAC_New_Value = 4095; aux = myDACSensor.MCP4725_SetNewValue ( MCP4725::WRITE_DAC_REGISTER_MODE, myNewDAC_Value );

myState = 0; break; }

myled = 0; }

int main() { MCP4725::Vector_data_t myDefaultData;

Reset and wake the device up aux = myDACSensor.MCP4725_Reset (); aux = myDACSensor.MCP4725_WakeUp ();

Read the default data in both EEPROM and DAC aux = myDACSensor.MCP4725_GetDAC_Data ( &myDefaultData ); aux = myDACSensor.MCP4725_GetEEPROM_Data ( &myDefaultData );

newDACOutput.attach( &changeDATA, 0.5 ); // the address of the function to be attached ( changeDATA ) and the interval ( 0.5s )

Let the callbacks take care of everything while(1) sleep(); }

Library for the MCP4725 12-Bit Digital-to-Analog Converter with EEPROM Memory.

Definition at line 100 of file MCP4725.h.


Member Enumeration Documentation

DEFAULT ADDRESSES ( NOTE1: The A2 and A1 are programmed to '00' (default), if not requested by customer.

NOTE2: On my board, the A2 and A1 are programmed to '01'. )

Enumerator:
MCP4725_ADDRESS_LOW 

A0 pin ties to GND

MCP4725_ADDRESS_HIGH 

A0 pin ties to VDD

Definition at line 107 of file MCP4725.h.

READY/BUSY BIT.

Enumerator:
EEPROM_BUSY 

EEPROM write is not completed.

EEPROM_READY 

EEPROM write is complete.

Definition at line 154 of file MCP4725.h.

POWER-DOWN MODE.

Enumerator:
NORMAL_MODE 

Normal Mode.

POWER_DOWN_1KOHM_RESISTIVE_LOAD_MODE 

Power-Down Mode. 1 k‎Ω resistor to ground.

POWER_DOWN_100KOHM_RESISTIVE_LOAD_MODE 

Power-Down Mode. 100 k‎Ω resistor to ground.

POWER_DOWN_500KOHM_RESISTIVE_LOAD_MODE 

Power-Down Mode. 500 k‎Ω resistor to ground.

Definition at line 142 of file MCP4725.h.

INTERNAL CONSTANTS.

Enumerator:
I2C_SUCCESS 

I2C communication was fine

Definition at line 181 of file MCP4725.h.

WRITE COMMAND TYPE.

Enumerator:
FAST_MODE 

This command is used to change the DAC register. EEPROM is not affected.

WRITE_DAC_REGISTER_MODE 

Load configuration bits and data code to the DAC Register.

WRITE_DAC_AND_EEPROM_REGISTER_MODE 

Load configuration bits and data code to the DAC Register and also write the EEPROM.

Definition at line 131 of file MCP4725.h.


Constructor & Destructor Documentation

MCP4725 ( PinName  sda,
PinName  scl,
uint32_t  addr,
uint32_t  freq 
)

Create an MCP4725 object connected to the specified I2C pins.

MCP4725.c.

Parameters:
sdaI2C data pin
sclI2C clock pin
addrI2C slave address
freqI2C frequency in Hz.

12-Bit Digital-to-Analog Converter with EEPROM Memory. Functions file.

Returns:
NA
Author:
Manuel Caballero
Date:
7/September/2017
Version:
7/September/2017 The ORIGIN
Precondition:
NaN.
Warning:
NaN
Precondition:
This code belongs to AqueronteBlog ( http://unbarquero.blogspot.com ).

Definition at line 20 of file MCP4725.cpp.

~MCP4725 (  )

Delete MCP4725 object.

Definition at line 28 of file MCP4725.cpp.


Member Function Documentation

MCP4725::MCP4725_status_t MCP4725_EEPROM_Status ( MCP4725_eeprom_status_t myEEPROM_Status )

It gets the eeprom status.

MCP4725_EEPROM_Status ( MCP4725_eeprom_status_t )

It gets the eeprom status.

Parameters:
[in]myEEPROM_Status,:EEPROM status.
[out]NaN.
Returns:
Status of MCP4725_EEPROM_Status.
Author:
Manuel Caballero
Date:
7/September/2017
Version:
7/September/2017 The ORIGIN
Precondition:
NaN
Warning:
NaN.

Definition at line 285 of file MCP4725.cpp.

MCP4725::MCP4725_status_t MCP4725_GetDAC_Data ( Vector_data_t *  myDACData )

It gets the last dac stored value.

MCP4725_GetDAC_Data ( Vector_data_t* )

It gets the DAC value.

Parameters:
[in]myDACData,:DAC value.
[out]NaN.
Returns:
Status of MCP4725_GetDAC_Data.
Author:
Manuel Caballero
Date:
8/September/2017
Version:
8/September/2017 The ORIGIN
Precondition:
NaN
Warning:
NaN.

Definition at line 365 of file MCP4725.cpp.

MCP4725::MCP4725_status_t MCP4725_GetEEPROM_Data ( Vector_data_t *  myEEPROMData )

It gets the last eeprom stored value.

MCP4725_GetEEPROM_Data ( Vector_data_t* )

It gets the eeprom value.

Parameters:
[in]myEEPROMData,:EEPROM value.
[out]NaN.
Returns:
Status of MCP4725_GetEEPROM_Data.
Author:
Manuel Caballero
Date:
8/September/2017
Version:
8/September/2017 The ORIGIN
Precondition:
NaN
Warning:
NaN.

Definition at line 325 of file MCP4725.cpp.

MCP4725::MCP4725_status_t MCP4725_PowerMode ( MCP4725_write_command_type_t  myWriteCMD,
MCP4725_operation_mode_t  myPowerMode 
)

It configures the power mode of the device.

MCP4725_PowerMode ( MCP4725_write_command_type_t , MCP4725_operation_mode_t )

It configures the power mode of the device.

Parameters:
[in]myWriteCMD,:It writes the command into the DAC or EEPROM/DAC.
[in]myPowerMode,:Normal Mode or one of the Power-Down available modes.
[out]NaN.
Returns:
Status of MCP4725_PowerMode.
Author:
Manuel Caballero
Date:
7/September/2017
Version:
7/September/2017 The ORIGIN
Precondition:
NaN
Warning:
NaN.

Definition at line 128 of file MCP4725.cpp.

MCP4725::MCP4725_status_t MCP4725_Reset ( void   )

It performs an internal reset similar to a power-on-reset ( POR ).

MCP4725_Reset ( void )

It performs an internal reset similar to a power-on-reset ( POR ).

Parameters:
[in]NaN.
[out]NaN.
Returns:
Status of MCP4725_Reset.
Author:
Manuel Caballero
Date:
7/September/2017
Version:
7/September/2017 The ORIGIN
Precondition:
NaN
Warning:
The user MUST respect the time it takes this instruction to be performed ( max. 50ms ).

Definition at line 54 of file MCP4725.cpp.

MCP4725::MCP4725_status_t MCP4725_SetNewValue ( MCP4725_write_command_type_t  myWriteCMD,
Vector_new_dac_value_t  myDACNewValue 
)

It sets a new output value.

MCP4725_SetNewValue ( MCP4725_write_command_type_t , uint32_t )

It sends a new output value.

Parameters:
[in]myWriteCMD,:It writes the command into the DAC or EEPROM/DAC.
[in]myDACNewValue,:New output value.
[out]NaN.
Returns:
Status of MCP4725_SetNewValue.
Author:
Manuel Caballero
Date:
7/September/2017
Version:
7/September/2017 The ORIGIN
Precondition:
NaN
Warning:
NaN.

Definition at line 218 of file MCP4725.cpp.

MCP4725::MCP4725_status_t MCP4725_WakeUp ( void   )

The power-down bits of the DAC register are set to a normal operation.

MCP4725_WakeUp ( void )

The power-down bits of the DAC register are set to a normal operation.

Parameters:
[in]NaN.
[out]NaN.
Returns:
Status of MCP4725_WakeUp.
Author:
Manuel Caballero
Date:
7/September/2017
Version:
7/September/2017 The ORIGIN
Precondition:
NaN
Warning:
NaN.

Definition at line 91 of file MCP4725.cpp.