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:
Thu Sep 06 21:23:25 2018 +0000
Revision:
7:1132d5fab5c7
Parent:
5:bd8dbd9be2ac
Updated method names to comply with Mbed coding standard.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jungkeviny 1:bc368afe2ec8 1 /*******************************************************************************
phonemacro 5:bd8dbd9be2ac 2 * Copyright (C) 2018 Maxim Integrated Products, Inc., All Rights Reserved.
phonemacro 5:bd8dbd9be2ac 3 *
phonemacro 5:bd8dbd9be2ac 4 * Permission is hereby granted, free of charge, to any person obtaining a
phonemacro 5:bd8dbd9be2ac 5 * copy of this software and associated documentation files (the "Software"),
phonemacro 5:bd8dbd9be2ac 6 * to deal in the Software without restriction, including without limitation
phonemacro 5:bd8dbd9be2ac 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
phonemacro 5:bd8dbd9be2ac 8 * and/or sell copies of the Software, and to permit persons to whom the
phonemacro 5:bd8dbd9be2ac 9 * Software is furnished to do so, subject to the following conditions:
phonemacro 5:bd8dbd9be2ac 10 *
phonemacro 5:bd8dbd9be2ac 11 * The above copyright notice and this permission notice shall be included
phonemacro 5:bd8dbd9be2ac 12 * in all copies or substantial portions of the Software.
phonemacro 5:bd8dbd9be2ac 13 *
phonemacro 5:bd8dbd9be2ac 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
phonemacro 5:bd8dbd9be2ac 15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
phonemacro 5:bd8dbd9be2ac 16 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
phonemacro 5:bd8dbd9be2ac 17 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
phonemacro 5:bd8dbd9be2ac 18 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
phonemacro 5:bd8dbd9be2ac 19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
phonemacro 5:bd8dbd9be2ac 20 * OTHER DEALINGS IN THE SOFTWARE.
phonemacro 5:bd8dbd9be2ac 21 *
phonemacro 5:bd8dbd9be2ac 22 * Except as contained in this notice, the name of Maxim Integrated
phonemacro 5:bd8dbd9be2ac 23 * Products, Inc. shall not be used except as stated in the Maxim Integrated
phonemacro 5:bd8dbd9be2ac 24 * Products, Inc. Branding Policy.
phonemacro 5:bd8dbd9be2ac 25 *
phonemacro 5:bd8dbd9be2ac 26 * The mere transfer of this software does not imply any licenses
phonemacro 5:bd8dbd9be2ac 27 * of trade secrets, proprietary technology, copyrights, patents,
phonemacro 5:bd8dbd9be2ac 28 * trademarks, maskwork rights, or any other form of intellectual
phonemacro 5:bd8dbd9be2ac 29 * property whatsoever. Maxim Integrated Products, Inc. retains all
phonemacro 5:bd8dbd9be2ac 30 * ownership rights.
phonemacro 5:bd8dbd9be2ac 31 *******************************************************************************
phonemacro 4:280d1e05f2ca 32 * @file MAX5216.h
jungkeviny 1:bc368afe2ec8 33 *******************************************************************************
jungkeviny 1:bc368afe2ec8 34 */
phonemacro 4:280d1e05f2ca 35 #ifndef MAX5216_H
phonemacro 4:280d1e05f2ca 36 #define MAX5216_H
jungkeviny 2:80e026469122 37
jungkeviny 2:80e026469122 38 #include "mbed.h"
jungkeviny 1:bc368afe2ec8 39
phonemacro 4:280d1e05f2ca 40 const unsigned int MAX521X_IC_BIT_MASK[] = {
phonemacro 4:280d1e05f2ca 41 0X00003FFF, // 14 Bits for MAX5214
phonemacro 4:280d1e05f2ca 42 0X0000FFFF // 16 Bits for MAX5216
phonemacro 4:280d1e05f2ca 43 };
phonemacro 4:280d1e05f2ca 44
phonemacro 4:280d1e05f2ca 45 const int MAX521X_NUM_BYTES_SPI[] = {
phonemacro 4:280d1e05f2ca 46 2, // 2 bytes for MAX5214
phonemacro 4:280d1e05f2ca 47 3 // 3 bytes for MAX5216
phonemacro 4:280d1e05f2ca 48 };
jungkeviny 1:bc368afe2ec8 49
jungkeviny 1:bc368afe2ec8 50 /**
phonemacro 4:280d1e05f2ca 51 * @brief 16-bit, 14-bit digital-to-analog converters (DACs)
phonemacro 4:280d1e05f2ca 52 * for the MAX5216, MAX5214.
phonemacro 5:bd8dbd9be2ac 53 * @version 1.0000.1
jungkeviny 1:bc368afe2ec8 54 *
phonemacro 4:280d1e05f2ca 55 * @details The MAX5214/MAX5216 accept a wide 2.7V to 5.5V supply
phonemacro 4:280d1e05f2ca 56 * voltage range. Power consumption is extremely low
phonemacro 4:280d1e05f2ca 57 * to accommodate most low-power and low-voltage applications.
phonemacro 4:280d1e05f2ca 58 * These devices feature a 3-wire SPI-/QSPI™-/
phonemacro 4:280d1e05f2ca 59 * MICROWIRE-/DSP-compatible serial interface
phonemacro 4:280d1e05f2ca 60 * This driver is compatible with the
phonemacro 4:280d1e05f2ca 61 * MAX5216, MAX5214.
jungkeviny 1:bc368afe2ec8 62 *
jungkeviny 1:bc368afe2ec8 63 * @code
jungkeviny 1:bc368afe2ec8 64 * #include "mbed.h"
jungkeviny 1:bc368afe2ec8 65 * #include "max32630fthr.h"
phonemacro 4:280d1e05f2ca 66 * #include "MAX5216.h"
jungkeviny 1:bc368afe2ec8 67 * #include "USBSerial.h"
phonemacro 4:280d1e05f2ca 68 * MAX32630FTHR pegasus(MAX32630FTHR::VIO_3V3);
phonemacro 4:280d1e05f2ca 69 * DigitalOut rLED(LED1);
phonemacro 4:280d1e05f2ca 70 * DigitalOut gLED(LED2);
phonemacro 4:280d1e05f2ca 71 * DigitalOut bLED(LED3);
phonemacro 4:280d1e05f2ca 72 * DigitalOut selectPin(P3_0); // Pin 3_0 is used to drive chip enable low
jungkeviny 1:bc368afe2ec8 73 * SPI spi(P5_1, P5_2, P5_0); // mosi, miso, sclk
phonemacro 4:280d1e05f2ca 74 *
jungkeviny 1:bc368afe2ec8 75 * int main()
jungkeviny 1:bc368afe2ec8 76 * {
phonemacro 4:280d1e05f2ca 77 * selectPin = 0;
phonemacro 4:280d1e05f2ca 78 * MAX5216 dac(spi, selectPin, MAX5216::MAX5216_IC);
phonemacro 4:280d1e05f2ca 79 * spi.format(8,0);
phonemacro 4:280d1e05f2ca 80 * spi.frequency(1000000);
phonemacro 7:1132d5fab5c7 81 * dac.write_command(MAX5216::WrtThru_Reg, 0xFFFF);
phonemacro 4:280d1e05f2ca 82 * wait(1.0);
phonemacro 7:1132d5fab5c7 83 * dac.write_command(MAX5216::WrtThru_Reg, 0x7FFF);
phonemacro 4:280d1e05f2ca 84 * wait(1.0);
phonemacro 7:1132d5fab5c7 85 * dac.write_cmmand(MAX5216::PwrDwn_Reg, MAX5216::PwrDwnHiZ);
jungkeviny 1:bc368afe2ec8 86 * }
jungkeviny 1:bc368afe2ec8 87 * @endcode
jungkeviny 1:bc368afe2ec8 88 */
jungkeviny 1:bc368afe2ec8 89
phonemacro 4:280d1e05f2ca 90 class MAX5216{
jungkeviny 1:bc368afe2ec8 91 public:
jungkeviny 1:bc368afe2ec8 92 /**
phonemacro 4:280d1e05f2ca 93 * @brief IC's supported with this driver
phonemacro 4:280d1e05f2ca 94 * @details MAX5214, MAX5216
phonemacro 4:280d1e05f2ca 95 */
phonemacro 4:280d1e05f2ca 96 typedef enum
phonemacro 4:280d1e05f2ca 97 {
phonemacro 4:280d1e05f2ca 98 MAX5214_IC = 0,
phonemacro 4:280d1e05f2ca 99 MAX5216_IC = 1
phonemacro 4:280d1e05f2ca 100 }MAX521X_ic_t;
phonemacro 4:280d1e05f2ca 101
phonemacro 4:280d1e05f2ca 102 /**
phonemacro 4:280d1e05f2ca 103 * @brief Commands supported by the DAC
phonemacro 5:bd8dbd9be2ac 104 * @details The upper 2 bits define the commands
jungkeviny 1:bc368afe2ec8 105 */
jungkeviny 0:3d525ab09933 106 typedef enum {
phonemacro 5:bd8dbd9be2ac 107 PwrDwn_Reg = (0x2<<6), // Power Down
phonemacro 5:bd8dbd9be2ac 108 WrtThru_Reg = (0x1<<6) // Write Through
jungkeviny 0:3d525ab09933 109 } setting_t;
jungkeviny 1:bc368afe2ec8 110
phonemacro 4:280d1e05f2ca 111 /**
phonemacro 4:280d1e05f2ca 112 * @brief Power Down modes
phonemacro 4:280d1e05f2ca 113 * @details 2 bits are used to define the power down modes
phonemacro 4:280d1e05f2ca 114 */
phonemacro 4:280d1e05f2ca 115 typedef enum {
phonemacro 5:bd8dbd9be2ac 116 PwrDwnNormalOp = (0x00), // DAC powers up and returns to its previous code setting.
phonemacro 5:bd8dbd9be2ac 117 PwrDwnHiZ = (0x01), // DAC powers down; OUT is high impedance.
phonemacro 5:bd8dbd9be2ac 118 PwrDwn100K = (0x02), // DAC powers down; OUT connects to ground through an internal 100k resistor.
phonemacro 5:bd8dbd9be2ac 119 PwrDwn1K = (0x03) // DAC powers down; OUT connects to ground through an internal 1k resistor.
phonemacro 4:280d1e05f2ca 120 } pwrDwnMode_t;
jungkeviny 1:bc368afe2ec8 121 /**********************************************************//**
phonemacro 4:280d1e05f2ca 122 * @brief Constructor for MAX5216 Class.
jungkeviny 1:bc368afe2ec8 123 *
jungkeviny 1:bc368afe2ec8 124 * @details Requires an existing SPI object as well as a DigitalOut object.
jungkeviny 1:bc368afe2ec8 125 * The DigitalOut object is used for a chip enable signal
jungkeviny 1:bc368afe2ec8 126 *
jungkeviny 1:bc368afe2ec8 127 * On Entry:
jungkeviny 1:bc368afe2ec8 128 * @param[in] spi - pointer to existing SPI object
jungkeviny 1:bc368afe2ec8 129 * @param[in] pin - pointer to a DigitalOut pin object
phonemacro 4:280d1e05f2ca 130 * @param[in] ic_variant - which type of MAX521x is used
jungkeviny 1:bc368afe2ec8 131 *
jungkeviny 1:bc368afe2ec8 132 * On Exit:
jungkeviny 1:bc368afe2ec8 133 *
jungkeviny 1:bc368afe2ec8 134 * @return None
jungkeviny 1:bc368afe2ec8 135 **************************************************************/
phonemacro 4:280d1e05f2ca 136 MAX5216(SPI &spi, DigitalOut &pin, MAX521X_ic_t ic_variant);
jungkeviny 1:bc368afe2ec8 137
jungkeviny 1:bc368afe2ec8 138 /**
jungkeviny 1:bc368afe2ec8 139 * @brief Send write command
phonemacro 5:bd8dbd9be2ac 140 * @param setting - WrtThru_Reg or Power Down Mode command
phonemacro 5:bd8dbd9be2ac 141 * @param value - 14 or 16 bit Value to write if WrtThru_Reg commanded
phonemacro 5:bd8dbd9be2ac 142 * Power Down Mode if PwrDwn_Reg commanded
jungkeviny 1:bc368afe2ec8 143 * @return void
jungkeviny 1:bc368afe2ec8 144 */
phonemacro 7:1132d5fab5c7 145 void write_command(MAX5216::setting_t setting, uint32_t value, pwrDwnMode_t mode = PwrDwnNormalOp);
jungkeviny 0:3d525ab09933 146
jungkeviny 2:80e026469122 147 /************************************************************
phonemacro 4:280d1e05f2ca 148 * @brief Default destructor for MAX5216 Class.
jungkeviny 1:bc368afe2ec8 149 *
jungkeviny 1:bc368afe2ec8 150 * @details Destroys SPI object if owner
jungkeviny 1:bc368afe2ec8 151 *
jungkeviny 1:bc368afe2ec8 152 * On Entry:
jungkeviny 1:bc368afe2ec8 153 *
jungkeviny 1:bc368afe2ec8 154 * On Exit:
jungkeviny 1:bc368afe2ec8 155 *
jungkeviny 1:bc368afe2ec8 156 * @return None
jungkeviny 1:bc368afe2ec8 157 **************************************************************/
phonemacro 4:280d1e05f2ca 158 ~MAX5216();
jungkeviny 1:bc368afe2ec8 159 private:
jungkeviny 1:bc368afe2ec8 160 // SPI object
jungkeviny 1:bc368afe2ec8 161 SPI &m_spi;
jungkeviny 1:bc368afe2ec8 162 // Selector pin object
jungkeviny 1:bc368afe2ec8 163 DigitalOut &m_pin;
phonemacro 4:280d1e05f2ca 164 // Identifies which IC variant is being used
phonemacro 4:280d1e05f2ca 165 MAX521X_ic_t m_ic_variant;
jungkeviny 1:bc368afe2ec8 166 };
jungkeviny 1:bc368afe2ec8 167
jungkeviny 1:bc368afe2ec8 168 #endif