Manuel Caballero / MCP4725
Committer:
mcm
Date:
Thu Sep 07 19:55:40 2017 +0000
Revision:
1:102f0b249960
Parent:
0:b03a293ceb8d
Child:
2:e09b7dd7c1dd
Header file is ready to be tested, the function file left to be completed.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mcm 1:102f0b249960 1 /**
mcm 1:102f0b249960 2 * @brief MCP4725.h
mcm 1:102f0b249960 3 * @details 12-Bit Digital-to-Analog Converter with EEPROM Memory.
mcm 1:102f0b249960 4 * Header file.
mcm 1:102f0b249960 5 *
mcm 1:102f0b249960 6 *
mcm 1:102f0b249960 7 * @return NA
mcm 1:102f0b249960 8 *
mcm 1:102f0b249960 9 * @author Manuel Caballero
mcm 1:102f0b249960 10 * @date 7/September/2017
mcm 1:102f0b249960 11 * @version 7/September/2017 The ORIGIN
mcm 1:102f0b249960 12 * @pre NaN.
mcm 1:102f0b249960 13 * @warning NaN
mcm 1:102f0b249960 14 * @pre This code belongs to AqueronteBlog ( http://unbarquero.blogspot.com ).
mcm 1:102f0b249960 15 */
mcm 1:102f0b249960 16 #ifndef MCP4725_H
mcm 1:102f0b249960 17 #define MCP4725_H
mcm 1:102f0b249960 18
mcm 1:102f0b249960 19 #include "mbed.h"
mcm 1:102f0b249960 20
mcm 1:102f0b249960 21
mcm 1:102f0b249960 22 /**
mcm 1:102f0b249960 23 Example:
mcm 1:102f0b249960 24
mcm 1:102f0b249960 25 [TODO]
mcm 1:102f0b249960 26 */
mcm 1:102f0b249960 27
mcm 1:102f0b249960 28
mcm 1:102f0b249960 29 /*!
mcm 1:102f0b249960 30 Library for the MCP4725 12-Bit Digital-to-Analog Converter with EEPROM Memory.
mcm 1:102f0b249960 31 */
mcm 1:102f0b249960 32 class MCP4725
mcm 1:102f0b249960 33 {
mcm 1:102f0b249960 34 public:
mcm 1:102f0b249960 35 /**
mcm 1:102f0b249960 36 * @brief DEFAULT ADDRESSES ( NOTE1: The A2 and A1 are programmed to '00' (default), if not requested by customer.
mcm 1:102f0b249960 37 * NOTE2: On my board, the A2 and A1 are programmed to '01'. )
mcm 1:102f0b249960 38 */
mcm 1:102f0b249960 39 typedef enum {
mcm 1:102f0b249960 40 MCP4725_ADDRESS_LOW = ( 0x62 << 1 ), /*!< A0 pin ties to GND */
mcm 1:102f0b249960 41 MCP4725_ADDRESS_HIGH = ( 0x63 << 1 ) /*!< A0 pin ties to VDD */
mcm 1:102f0b249960 42 } MCP4725_address_t;
mcm 1:102f0b249960 43
mcm 1:102f0b249960 44
mcm 1:102f0b249960 45 /**
mcm 1:102f0b249960 46 * @brief COMMANDS
mcm 1:102f0b249960 47 */
mcm 1:102f0b249960 48 #define MCP4725_GENERAL_CALL 0x00 /*!< The MCP4725 device acknowledges the general call address */
mcm 1:102f0b249960 49
mcm 1:102f0b249960 50 /* General Call Commands */
mcm 1:102f0b249960 51 /**
mcm 1:102f0b249960 52 * @brief GENERAL CALL COMMANDS
mcm 1:102f0b249960 53 */
mcm 1:102f0b249960 54 #define MCP4725_GENERAL_CALL_RESET 0x06 /*!< Perform an internal reset similar to a power-on-reset (POR). */
mcm 1:102f0b249960 55 #define MCP4725_GENERAL_CALL_WAKE_UP 0x09 /*!< The power-down bits of the DAC register are set to a normal operation. */
mcm 1:102f0b249960 56
mcm 1:102f0b249960 57
mcm 1:102f0b249960 58
mcm 1:102f0b249960 59 /* Commands Registers */
mcm 1:102f0b249960 60 /**
mcm 1:102f0b249960 61 * @brief WRITE COMMAND TYPE
mcm 1:102f0b249960 62 */
mcm 1:102f0b249960 63 typedef enum {
mcm 1:102f0b249960 64 FAST_MODE = 0, /*!< This command is used to change the DAC register. EEPROM is not affected. */
mcm 1:102f0b249960 65 WRITE_DAC_REGISTER_MODE = 1, /*!< Load configuration bits and data code to the DAC Register. */
mcm 1:102f0b249960 66 WRITE_DAC_AND_EEPROM_REGISTER_MODE = 2 /*!< Load configuration bits and data code to the DAC Register and also write the EEPROM. */
mcm 1:102f0b249960 67 } MCP4725_write_command_type_t;
mcm 1:102f0b249960 68
mcm 1:102f0b249960 69
mcm 1:102f0b249960 70
mcm 1:102f0b249960 71 /**
mcm 1:102f0b249960 72 * @brief POWER-DOWN MODE
mcm 1:102f0b249960 73 */
mcm 1:102f0b249960 74 typedef enum {
mcm 1:102f0b249960 75 NORMAL_MODE = 0, /*!< Normal Mode. */
mcm 1:102f0b249960 76 POWER_DOWN_1KOHM_RESISTIVE_LOAD_MODE = 1, /*!< Power-Down Mode. 1 k‎Ω resistor to ground. */
mcm 1:102f0b249960 77 POWER_DOWN_100KOHM_RESISTIVE_LOAD_MODE = 2, /*!< Power-Down Mode. 100 k‎Ω resistor to ground. */
mcm 1:102f0b249960 78 POWER_DOWN_500KOHM_RESISTIVE_LOAD_MODE = 3 /*!< Power-Down Mode. 500 k‎Ω resistor to ground. */
mcm 1:102f0b249960 79 } MCP4725_operation_mode_t;
mcm 1:102f0b249960 80
mcm 1:102f0b249960 81
mcm 1:102f0b249960 82
mcm 1:102f0b249960 83 /**
mcm 1:102f0b249960 84 * @brief READY/#BUSY BIT
mcm 1:102f0b249960 85 */
mcm 1:102f0b249960 86 typedef enum {
mcm 1:102f0b249960 87 EEPROM_BUSY = 0, /*!< EEPROM write is not completed. */
mcm 1:102f0b249960 88 EEPROM_READY = 1 /*!< EEPROM write is complete. */
mcm 1:102f0b249960 89 } MCP4725_eeprom_status_t;
mcm 1:102f0b249960 90
mcm 1:102f0b249960 91
mcm 1:102f0b249960 92
mcm 1:102f0b249960 93
mcm 1:102f0b249960 94
mcm 1:102f0b249960 95 /**
mcm 1:102f0b249960 96 * @brief INTERNAL CONSTANTS
mcm 1:102f0b249960 97 */
mcm 1:102f0b249960 98 typedef enum {
mcm 1:102f0b249960 99 MCP4725_SUCCESS = 0,
mcm 1:102f0b249960 100 MCP4725_FAILURE = 1,
mcm 1:102f0b249960 101 I2C_SUCCESS = 0 /*!< I2C communication was fine */
mcm 1:102f0b249960 102 } MCP4725_status_t;
mcm 1:102f0b249960 103
mcm 1:102f0b249960 104
mcm 1:102f0b249960 105
mcm 1:102f0b249960 106
mcm 1:102f0b249960 107 /** Create an MCP4725 object connected to the specified I2C pins.
mcm 1:102f0b249960 108 *
mcm 1:102f0b249960 109 * @param sda I2C data pin
mcm 1:102f0b249960 110 * @param scl I2C clock pin
mcm 1:102f0b249960 111 * @param addr I2C slave address
mcm 1:102f0b249960 112 * @param freq I2C frequency in Hz.
mcm 1:102f0b249960 113 */
mcm 1:102f0b249960 114 MCP4725 ( PinName sda, PinName scl, uint32_t addr, uint32_t freq );
mcm 1:102f0b249960 115
mcm 1:102f0b249960 116 /** Delete MCP4725 object.
mcm 1:102f0b249960 117 */
mcm 1:102f0b249960 118 ~MCP4725();
mcm 1:102f0b249960 119
mcm 1:102f0b249960 120 /** It performs an internal reset similar to a power-on-reset ( POR ).
mcm 1:102f0b249960 121 */
mcm 1:102f0b249960 122 MCP4725_status_t MCP4725_Reset ( void );
mcm 1:102f0b249960 123
mcm 1:102f0b249960 124 /** The power-down bits of the DAC register are set to a normal operation.
mcm 1:102f0b249960 125 */
mcm 1:102f0b249960 126 MCP4725_status_t MCP4725_WakeUp ( void );
mcm 1:102f0b249960 127
mcm 1:102f0b249960 128 /** It configures the power mode of the device.
mcm 1:102f0b249960 129 */
mcm 1:102f0b249960 130 MCP4725_status_t MCP4725_PowerMode ( MCP4725_write_command_type_t myWriteCMD, uint32_t myDACNewValue );
mcm 1:102f0b249960 131
mcm 1:102f0b249960 132 /** It sets a new output value.
mcm 1:102f0b249960 133 */
mcm 1:102f0b249960 134 MCP4725_status_t MCP4725_SetNewValue ( MCP4725_write_command_type_t myWriteCMD, uint32_t myDACNewValue );
mcm 1:102f0b249960 135
mcm 1:102f0b249960 136 /** It gets the eeprom status.
mcm 1:102f0b249960 137 */
mcm 1:102f0b249960 138 MCP4725_status_t MCP4725_EEPROM_Status ( MCP4725_eeprom_status_t* myEEPROM_Status );
mcm 1:102f0b249960 139
mcm 1:102f0b249960 140
mcm 1:102f0b249960 141 private:
mcm 1:102f0b249960 142 I2C i2c;
mcm 1:102f0b249960 143 uint32_t MCP4725_Addr;
mcm 1:102f0b249960 144 };
mcm 1:102f0b249960 145
mcm 1:102f0b249960 146 #endif