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

Files at this revision

API Documentation at this revision

Comitter:
phonemacro
Date:
Mon Aug 13 04:18:09 2018 +0000
Parent:
4:280d1e05f2ca
Child:
6:cd8d96483262
Commit message:
v1.0000.1, Add Power Down command. Remove NOP command. Increase SPI bus baud rate to 24 MHz.

Changed in this revision

MAX5216.cpp Show annotated file Show diff for this revision Revisions of this file
MAX5216.h Show annotated file Show diff for this revision Revisions of this file
--- a/MAX5216.cpp	Sun Aug 12 10:04:09 2018 +0000
+++ b/MAX5216.cpp	Mon Aug 13 04:18:09 2018 +0000
@@ -37,50 +37,44 @@
     m_pin = 1;
 }
 
-void MAX5216::writeCommand(setting_t setting, uint32_t value)
+void MAX5216::writeCommand(setting_t setting, uint32_t value, pwrDwnMode_t mode)
 {
     
     char val[3] = {0, 0, 0};
     int i;
-    
-    if(value > MAX521X_IC_BIT_MASK[(uint8_t)(m_ic_variant)]) {
-        printf("value in writeCommand is too big: %X\r\n", value);
-        return;
-    }
     m_pin = 0;
-    if (m_ic_variant == MAX5214_IC) {  // MAX5214 is 14 bits
-        value &= MAX521X_IC_BIT_MASK[(uint8_t)(m_ic_variant)];
-    } else {                           // MAX5216 is 16 bits
-        value &= MAX521X_IC_BIT_MASK[(uint8_t)(m_ic_variant)];
-        value = value << 6;  // least significant 6 bits are not used
-        val[2] = value & 0xFF;
+    if (setting == PwrDwn_Reg) {
+        val[0] = char(value<<2);
+        val[0] |= char(setting);
+        for (i = 0; i < MAX521X_NUM_BYTES_SPI[(uint8_t)(m_ic_variant)]; i++) {
+            m_spi.write(val[i]);
+        }
+    } else if (setting == WrtThru_Reg){
+        
+        if(value > MAX521X_IC_BIT_MASK[(uint8_t)(m_ic_variant)]) {
+            printf("value in writeCommand is too big: %X\r\n", value);
+            return;
+        }
+        if (m_ic_variant == MAX5214_IC) {  // MAX5214 is 14 bits
+            value &= MAX521X_IC_BIT_MASK[(uint8_t)(m_ic_variant)];
+        } else {                           // MAX5216 is 16 bits
+            value &= MAX521X_IC_BIT_MASK[(uint8_t)(m_ic_variant)];
+            value = value << 6;  // least significant 6 bits are not used
+            val[2] = value & 0xFF;
+            value = value >> 8;
+        }
+        val[1] = value & 0xFF;
         value = value >> 8;
-    }
-    val[1] = value & 0xFF;
-    value = value >> 8;
-    val[0] = value;
-    val[0] |= setting;
-    //printf("mask %X, Value %X, val 0, 1, 2 %02X %02X %02X \r\n", MAX521X_IC_BIT_MASK[(uint8_t)(m_ic_variant)],value, val[0], val[1], val[2]);
-
-    for (i = 0; i < MAX521X_NUM_BYTES_SPI[(uint8_t)(m_ic_variant)]; i++) {
-        m_spi.write(val[i]);
+        val[0] = value;
+        val[0] |= setting;
+        //  printf("mask %X, Value %X, val 0, 1, 2 %02X %02X %02X \r\n", MAX521X_IC_BIT_MASK[(uint8_t)(m_ic_variant)],value, val[0], val[1], val[2]);
+        for (i = 0; i < MAX521X_NUM_BYTES_SPI[(uint8_t)(m_ic_variant)]; i++) {
+            m_spi.write(val[i]);
+        }
     }
     m_pin = 1;
 }
-#if 0 // tbd
-void MAX5216::writeCommand(setting_t setting, pwrDwnMode_t mode)
-{
-    char val[3] = {0, 0, 0};
-    int i;
-    m_pin = 0;
-    val[0] = setting | (char)(mode);
-    for (i = 0; i < MAX521X_NUM_BYTES_SPI[(uint8_t)(m_ic_variant)]; i++) {
-        m_spi.write(val[i]);
-    }
-    m_pin = 1;
-    
-}
-#endif
+
 MAX5216::~MAX5216(void) 
 {
   //empty block
--- a/MAX5216.h	Sun Aug 12 10:04:09 2018 +0000
+++ b/MAX5216.h	Mon Aug 13 04:18:09 2018 +0000
@@ -1,9 +1,37 @@
 /*******************************************************************************
+* Copyright (C) 2018 Maxim Integrated Products, Inc., All Rights Reserved.
+*
+* Permission is hereby granted, free of charge, to any person obtaining a
+* copy of this software and associated documentation files (the "Software"),
+* to deal in the Software without restriction, including without limitation
+* the rights to use, copy, modify, merge, publish, distribute, sublicense,
+* and/or sell copies of the Software, and to permit persons to whom the
+* Software is furnished to do so, subject to the following conditions:
+*
+* The above copyright notice and this permission notice shall be included
+* in all copies or substantial portions of the Software.
+*
+* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+* IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
+* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+* OTHER DEALINGS IN THE SOFTWARE.
+*
+* Except as contained in this notice, the name of Maxim Integrated
+* Products, Inc. shall not be used except as stated in the Maxim Integrated
+* Products, Inc. Branding Policy.
+*
+* The mere transfer of this software does not imply any licenses
+* of trade secrets, proprietary technology, copyrights, patents,
+* trademarks, maskwork rights, or any other form of intellectual
+* property whatsoever. Maxim Integrated Products, Inc. retains all
+* ownership rights.
+*******************************************************************************
 * @file MAX5216.h
-
 *******************************************************************************
 */
-
 #ifndef MAX5216_H
 #define MAX5216_H
 
@@ -22,7 +50,7 @@
 /**
 * @brief 16-bit, 14-bit digital-to-analog converters (DACs)
 *        for the MAX5216, MAX5214.
-* @version 1.0000.0
+* @version 1.0000.1
 *
 * @details The MAX5214/MAX5216 accept a wide 2.7V to 5.5V supply
 * voltage range. Power consumption is extremely low
@@ -54,7 +82,7 @@
 *     wait(1.0);
 *     dac.writeCommand(MAX5216::WrtThru_Reg, 0x7FFF);
 *     wait(1.0);
-*     dac.writeCommand(MAX5216::NoOp_Reg, 0xFFFF);
+*     dac.writeCommand(MAX5216::PwrDwn_Reg, MAX5216::PwrDwnHiZ);
 * }
 * @endcode
 */
@@ -73,12 +101,11 @@
 
     /**
     * @brief Commands supported by the DAC
-    * @details The upper 2 bits of the first byte define the commands
+    * @details The upper 2 bits define the commands
     */ 
     typedef enum {
-        NoOp_Reg =    (0x0<<6),                     // No Operation
-//tbd        PwrDwn_Reg =  (0x2<<6),                     // Power Down
-        WrtThru_Reg = (0x1<<6)                      // Write Through
+        PwrDwn_Reg =  (0x2<<6),                   // Power Down
+        WrtThru_Reg = (0x1<<6)                    // Write Through
     } setting_t;
     
     /**
@@ -86,12 +113,11 @@
     * @details 2 bits are used to define the power down modes
     */ 
     typedef enum {
-        PwrDwnNormalOp = 0x0<<2,                  // DAC powers up and returns to its previous code setting.
-        PwrDwnHiZ =      0x1<<2,                  // DAC powers down; OUT is high impedance.
-        PwrDwn100K =     0x2<<2,                  // DAC powers down; OUT connects to ground through an internal 100k resistor.
-        PwrDwn10K =      0x3<<2                   // DAC powers down; OUT connects to ground through an internal 1k resistor.
+        PwrDwnNormalOp = (0x00),                  // DAC powers up and returns to its previous code setting.
+        PwrDwnHiZ =      (0x01),                  // DAC powers down; OUT is high impedance.
+        PwrDwn100K =     (0x02),                  // DAC powers down; OUT connects to ground through an internal 100k resistor.
+        PwrDwn1K =       (0x03)                   // DAC powers down; OUT connects to ground through an internal 1k resistor.
     } pwrDwnMode_t; 
-    
     /**********************************************************//**
     * @brief Constructor for MAX5216 Class.  
     * 
@@ -111,13 +137,12 @@
     
     /** 
     * @brief Send write command
-    * @param setting - Command sent to MAX5216 register
-    * @param value - 14 or 16 bit Value to write
+    * @param setting - WrtThru_Reg or Power Down Mode command
+    * @param value - 14 or 16 bit Value to write if WrtThru_Reg commanded
+    *                Power Down Mode if PwrDwn_Reg commanded
     * @return void
     */
-    void writeCommand(MAX5216::setting_t setting, uint32_t value);
-    
-//    void writeCommand(setting_t setting, pwrDwnMode_t mode);
+    void writeCommand(MAX5216::setting_t setting, uint32_t value, pwrDwnMode_t mode = PwrDwnNormalOp);
 
     /************************************************************
     * @brief Default destructor for MAX5216 Class.