Driver C++ source code for MAX5216/MAX5214 16-bit/14-bit DAC SPI (50MHz) bus ICs. Low power Digital-to_Analog Converter chips which accept supply voltages of 2.7V to 5.5V. Features Rail-to-Rail Buffered Output Operation and Safe Power-On Reset (POR) to Zero DAC Output.

Dependents:   MAX5216_16_Bit_DAC_Hello_Code

Fork of MAX5487_Digital_Pot_Potentiometer_Rheostat_Resistor_Wiper by Kevin Jung

Committer:
phonemacro
Date:
Sun Aug 12 10:04:09 2018 +0000
Revision:
4:280d1e05f2ca
Parent:
MAX5487.h@3:4d4053c4c29e
Child:
5:bd8dbd9be2ac
Initial commit for MAX5216, MAX5216 Driver C++ Source Code

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jungkeviny 1:bc368afe2ec8 1 /*******************************************************************************
phonemacro 4:280d1e05f2ca 2 * @file MAX5216.h
jungkeviny 1:bc368afe2ec8 3
jungkeviny 1:bc368afe2ec8 4 *******************************************************************************
jungkeviny 1:bc368afe2ec8 5 */
jungkeviny 1:bc368afe2ec8 6
phonemacro 4:280d1e05f2ca 7 #ifndef MAX5216_H
phonemacro 4:280d1e05f2ca 8 #define MAX5216_H
jungkeviny 2:80e026469122 9
jungkeviny 2:80e026469122 10 #include "mbed.h"
jungkeviny 1:bc368afe2ec8 11
phonemacro 4:280d1e05f2ca 12 const unsigned int MAX521X_IC_BIT_MASK[] = {
phonemacro 4:280d1e05f2ca 13 0X00003FFF, // 14 Bits for MAX5214
phonemacro 4:280d1e05f2ca 14 0X0000FFFF // 16 Bits for MAX5216
phonemacro 4:280d1e05f2ca 15 };
phonemacro 4:280d1e05f2ca 16
phonemacro 4:280d1e05f2ca 17 const int MAX521X_NUM_BYTES_SPI[] = {
phonemacro 4:280d1e05f2ca 18 2, // 2 bytes for MAX5214
phonemacro 4:280d1e05f2ca 19 3 // 3 bytes for MAX5216
phonemacro 4:280d1e05f2ca 20 };
jungkeviny 1:bc368afe2ec8 21
jungkeviny 1:bc368afe2ec8 22 /**
phonemacro 4:280d1e05f2ca 23 * @brief 16-bit, 14-bit digital-to-analog converters (DACs)
phonemacro 4:280d1e05f2ca 24 * for the MAX5216, MAX5214.
phonemacro 4:280d1e05f2ca 25 * @version 1.0000.0
jungkeviny 1:bc368afe2ec8 26 *
phonemacro 4:280d1e05f2ca 27 * @details The MAX5214/MAX5216 accept a wide 2.7V to 5.5V supply
phonemacro 4:280d1e05f2ca 28 * voltage range. Power consumption is extremely low
phonemacro 4:280d1e05f2ca 29 * to accommodate most low-power and low-voltage applications.
phonemacro 4:280d1e05f2ca 30 * These devices feature a 3-wire SPI-/QSPI™-/
phonemacro 4:280d1e05f2ca 31 * MICROWIRE-/DSP-compatible serial interface
phonemacro 4:280d1e05f2ca 32 * This driver is compatible with the
phonemacro 4:280d1e05f2ca 33 * MAX5216, MAX5214.
jungkeviny 1:bc368afe2ec8 34 *
jungkeviny 1:bc368afe2ec8 35 * @code
jungkeviny 1:bc368afe2ec8 36 * #include "mbed.h"
jungkeviny 1:bc368afe2ec8 37 * #include "max32630fthr.h"
phonemacro 4:280d1e05f2ca 38 * #include "MAX5216.h"
jungkeviny 1:bc368afe2ec8 39 * #include "USBSerial.h"
phonemacro 4:280d1e05f2ca 40 * MAX32630FTHR pegasus(MAX32630FTHR::VIO_3V3);
phonemacro 4:280d1e05f2ca 41 * DigitalOut rLED(LED1);
phonemacro 4:280d1e05f2ca 42 * DigitalOut gLED(LED2);
phonemacro 4:280d1e05f2ca 43 * DigitalOut bLED(LED3);
phonemacro 4:280d1e05f2ca 44 * DigitalOut selectPin(P3_0); // Pin 3_0 is used to drive chip enable low
jungkeviny 1:bc368afe2ec8 45 * SPI spi(P5_1, P5_2, P5_0); // mosi, miso, sclk
phonemacro 4:280d1e05f2ca 46 *
jungkeviny 1:bc368afe2ec8 47 * int main()
jungkeviny 1:bc368afe2ec8 48 * {
phonemacro 4:280d1e05f2ca 49 * selectPin = 0;
phonemacro 4:280d1e05f2ca 50 * MAX5216 dac(spi, selectPin, MAX5216::MAX5216_IC);
phonemacro 4:280d1e05f2ca 51 * spi.format(8,0);
phonemacro 4:280d1e05f2ca 52 * spi.frequency(1000000);
phonemacro 4:280d1e05f2ca 53 * dac.writeCommand(MAX5216::WrtThru_Reg, 0xFFFF);
phonemacro 4:280d1e05f2ca 54 * wait(1.0);
phonemacro 4:280d1e05f2ca 55 * dac.writeCommand(MAX5216::WrtThru_Reg, 0x7FFF);
phonemacro 4:280d1e05f2ca 56 * wait(1.0);
phonemacro 4:280d1e05f2ca 57 * dac.writeCommand(MAX5216::NoOp_Reg, 0xFFFF);
jungkeviny 1:bc368afe2ec8 58 * }
jungkeviny 1:bc368afe2ec8 59 * @endcode
jungkeviny 1:bc368afe2ec8 60 */
jungkeviny 1:bc368afe2ec8 61
phonemacro 4:280d1e05f2ca 62 class MAX5216{
jungkeviny 1:bc368afe2ec8 63 public:
jungkeviny 1:bc368afe2ec8 64 /**
phonemacro 4:280d1e05f2ca 65 * @brief IC's supported with this driver
phonemacro 4:280d1e05f2ca 66 * @details MAX5214, MAX5216
phonemacro 4:280d1e05f2ca 67 */
phonemacro 4:280d1e05f2ca 68 typedef enum
phonemacro 4:280d1e05f2ca 69 {
phonemacro 4:280d1e05f2ca 70 MAX5214_IC = 0,
phonemacro 4:280d1e05f2ca 71 MAX5216_IC = 1
phonemacro 4:280d1e05f2ca 72 }MAX521X_ic_t;
phonemacro 4:280d1e05f2ca 73
phonemacro 4:280d1e05f2ca 74 /**
phonemacro 4:280d1e05f2ca 75 * @brief Commands supported by the DAC
phonemacro 4:280d1e05f2ca 76 * @details The upper 2 bits of the first byte define the commands
jungkeviny 1:bc368afe2ec8 77 */
jungkeviny 0:3d525ab09933 78 typedef enum {
phonemacro 4:280d1e05f2ca 79 NoOp_Reg = (0x0<<6), // No Operation
phonemacro 4:280d1e05f2ca 80 //tbd PwrDwn_Reg = (0x2<<6), // Power Down
phonemacro 4:280d1e05f2ca 81 WrtThru_Reg = (0x1<<6) // Write Through
jungkeviny 0:3d525ab09933 82 } setting_t;
jungkeviny 1:bc368afe2ec8 83
phonemacro 4:280d1e05f2ca 84 /**
phonemacro 4:280d1e05f2ca 85 * @brief Power Down modes
phonemacro 4:280d1e05f2ca 86 * @details 2 bits are used to define the power down modes
phonemacro 4:280d1e05f2ca 87 */
phonemacro 4:280d1e05f2ca 88 typedef enum {
phonemacro 4:280d1e05f2ca 89 PwrDwnNormalOp = 0x0<<2, // DAC powers up and returns to its previous code setting.
phonemacro 4:280d1e05f2ca 90 PwrDwnHiZ = 0x1<<2, // DAC powers down; OUT is high impedance.
phonemacro 4:280d1e05f2ca 91 PwrDwn100K = 0x2<<2, // DAC powers down; OUT connects to ground through an internal 100k resistor.
phonemacro 4:280d1e05f2ca 92 PwrDwn10K = 0x3<<2 // DAC powers down; OUT connects to ground through an internal 1k resistor.
phonemacro 4:280d1e05f2ca 93 } pwrDwnMode_t;
phonemacro 4:280d1e05f2ca 94
jungkeviny 1:bc368afe2ec8 95 /**********************************************************//**
phonemacro 4:280d1e05f2ca 96 * @brief Constructor for MAX5216 Class.
jungkeviny 1:bc368afe2ec8 97 *
jungkeviny 1:bc368afe2ec8 98 * @details Requires an existing SPI object as well as a DigitalOut object.
jungkeviny 1:bc368afe2ec8 99 * The DigitalOut object is used for a chip enable signal
jungkeviny 1:bc368afe2ec8 100 *
jungkeviny 1:bc368afe2ec8 101 * On Entry:
jungkeviny 1:bc368afe2ec8 102 * @param[in] spi - pointer to existing SPI object
jungkeviny 1:bc368afe2ec8 103 * @param[in] pin - pointer to a DigitalOut pin object
phonemacro 4:280d1e05f2ca 104 * @param[in] ic_variant - which type of MAX521x is used
jungkeviny 1:bc368afe2ec8 105 *
jungkeviny 1:bc368afe2ec8 106 * On Exit:
jungkeviny 1:bc368afe2ec8 107 *
jungkeviny 1:bc368afe2ec8 108 * @return None
jungkeviny 1:bc368afe2ec8 109 **************************************************************/
phonemacro 4:280d1e05f2ca 110 MAX5216(SPI &spi, DigitalOut &pin, MAX521X_ic_t ic_variant);
jungkeviny 1:bc368afe2ec8 111
jungkeviny 1:bc368afe2ec8 112 /**
jungkeviny 1:bc368afe2ec8 113 * @brief Send write command
phonemacro 4:280d1e05f2ca 114 * @param setting - Command sent to MAX5216 register
phonemacro 4:280d1e05f2ca 115 * @param value - 14 or 16 bit Value to write
jungkeviny 1:bc368afe2ec8 116 * @return void
jungkeviny 1:bc368afe2ec8 117 */
phonemacro 4:280d1e05f2ca 118 void writeCommand(MAX5216::setting_t setting, uint32_t value);
phonemacro 4:280d1e05f2ca 119
phonemacro 4:280d1e05f2ca 120 // void writeCommand(setting_t setting, pwrDwnMode_t mode);
jungkeviny 0:3d525ab09933 121
jungkeviny 2:80e026469122 122 /************************************************************
phonemacro 4:280d1e05f2ca 123 * @brief Default destructor for MAX5216 Class.
jungkeviny 1:bc368afe2ec8 124 *
jungkeviny 1:bc368afe2ec8 125 * @details Destroys SPI object if owner
jungkeviny 1:bc368afe2ec8 126 *
jungkeviny 1:bc368afe2ec8 127 * On Entry:
jungkeviny 1:bc368afe2ec8 128 *
jungkeviny 1:bc368afe2ec8 129 * On Exit:
jungkeviny 1:bc368afe2ec8 130 *
jungkeviny 1:bc368afe2ec8 131 * @return None
jungkeviny 1:bc368afe2ec8 132 **************************************************************/
phonemacro 4:280d1e05f2ca 133 ~MAX5216();
jungkeviny 1:bc368afe2ec8 134 private:
jungkeviny 1:bc368afe2ec8 135 // SPI object
jungkeviny 1:bc368afe2ec8 136 SPI &m_spi;
jungkeviny 1:bc368afe2ec8 137 // Selector pin object
jungkeviny 1:bc368afe2ec8 138 DigitalOut &m_pin;
phonemacro 4:280d1e05f2ca 139 // Identifies which IC variant is being used
phonemacro 4:280d1e05f2ca 140 MAX521X_ic_t m_ic_variant;
jungkeviny 1:bc368afe2ec8 141 };
jungkeviny 1:bc368afe2ec8 142
jungkeviny 1:bc368afe2ec8 143 #endif