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
Revision 4:280d1e05f2ca, committed 2018-08-12
- Comitter:
- phonemacro
- Date:
- Sun Aug 12 10:04:09 2018 +0000
- Parent:
- 3:4d4053c4c29e
- Child:
- 5:bd8dbd9be2ac
- Commit message:
- Initial commit for MAX5216, MAX5216 Driver C++ Source Code
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/MAX5216.cpp Sun Aug 12 10:04:09 2018 +0000
@@ -0,0 +1,88 @@
+/*******************************************************************************
+* 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.
+*******************************************************************************
+*/
+#include "MAX5216.h"
+
+MAX5216::MAX5216(SPI &spi, DigitalOut &pin, MAX521X_ic_t ic_variant) : m_spi(spi), m_pin(pin), m_ic_variant(ic_variant)
+{
+ m_pin = 1;
+}
+
+void MAX5216::writeCommand(setting_t setting, uint32_t value)
+{
+
+ 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;
+ 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]);
+ }
+ 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
+}
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/MAX5216.h Sun Aug 12 10:04:09 2018 +0000
@@ -0,0 +1,143 @@
+/*******************************************************************************
+* @file MAX5216.h
+
+*******************************************************************************
+*/
+
+#ifndef MAX5216_H
+#define MAX5216_H
+
+#include "mbed.h"
+
+const unsigned int MAX521X_IC_BIT_MASK[] = {
+ 0X00003FFF, // 14 Bits for MAX5214
+ 0X0000FFFF // 16 Bits for MAX5216
+ };
+
+const int MAX521X_NUM_BYTES_SPI[] = {
+ 2, // 2 bytes for MAX5214
+ 3 // 3 bytes for MAX5216
+ };
+
+/**
+* @brief 16-bit, 14-bit digital-to-analog converters (DACs)
+* for the MAX5216, MAX5214.
+* @version 1.0000.0
+*
+* @details The MAX5214/MAX5216 accept a wide 2.7V to 5.5V supply
+* voltage range. Power consumption is extremely low
+* to accommodate most low-power and low-voltage applications.
+* These devices feature a 3-wire SPI-/QSPI™-/
+* MICROWIRE-/DSP-compatible serial interface
+* This driver is compatible with the
+* MAX5216, MAX5214.
+*
+* @code
+* #include "mbed.h"
+* #include "max32630fthr.h"
+* #include "MAX5216.h"
+* #include "USBSerial.h"
+* MAX32630FTHR pegasus(MAX32630FTHR::VIO_3V3);
+* DigitalOut rLED(LED1);
+* DigitalOut gLED(LED2);
+* DigitalOut bLED(LED3);
+* DigitalOut selectPin(P3_0); // Pin 3_0 is used to drive chip enable low
+* SPI spi(P5_1, P5_2, P5_0); // mosi, miso, sclk
+*
+* int main()
+* {
+* selectPin = 0;
+* MAX5216 dac(spi, selectPin, MAX5216::MAX5216_IC);
+* spi.format(8,0);
+* spi.frequency(1000000);
+* dac.writeCommand(MAX5216::WrtThru_Reg, 0xFFFF);
+* wait(1.0);
+* dac.writeCommand(MAX5216::WrtThru_Reg, 0x7FFF);
+* wait(1.0);
+* dac.writeCommand(MAX5216::NoOp_Reg, 0xFFFF);
+* }
+* @endcode
+*/
+
+class MAX5216{
+ public:
+ /**
+ * @brief IC's supported with this driver
+ * @details MAX5214, MAX5216
+ */
+ typedef enum
+ {
+ MAX5214_IC = 0,
+ MAX5216_IC = 1
+ }MAX521X_ic_t;
+
+ /**
+ * @brief Commands supported by the DAC
+ * @details The upper 2 bits of the first byte define the commands
+ */
+ typedef enum {
+ NoOp_Reg = (0x0<<6), // No Operation
+//tbd PwrDwn_Reg = (0x2<<6), // Power Down
+ WrtThru_Reg = (0x1<<6) // Write Through
+ } setting_t;
+
+ /**
+ * @brief Power Down modes
+ * @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.
+ } pwrDwnMode_t;
+
+ /**********************************************************//**
+ * @brief Constructor for MAX5216 Class.
+ *
+ * @details Requires an existing SPI object as well as a DigitalOut object.
+ * The DigitalOut object is used for a chip enable signal
+ *
+ * On Entry:
+ * @param[in] spi - pointer to existing SPI object
+ * @param[in] pin - pointer to a DigitalOut pin object
+ * @param[in] ic_variant - which type of MAX521x is used
+ *
+ * On Exit:
+ *
+ * @return None
+ **************************************************************/
+ MAX5216(SPI &spi, DigitalOut &pin, MAX521X_ic_t ic_variant);
+
+ /**
+ * @brief Send write command
+ * @param setting - Command sent to MAX5216 register
+ * @param value - 14 or 16 bit Value to write
+ * @return void
+ */
+ void writeCommand(MAX5216::setting_t setting, uint32_t value);
+
+// void writeCommand(setting_t setting, pwrDwnMode_t mode);
+
+ /************************************************************
+ * @brief Default destructor for MAX5216 Class.
+ *
+ * @details Destroys SPI object if owner
+ *
+ * On Entry:
+ *
+ * On Exit:
+ *
+ * @return None
+ **************************************************************/
+ ~MAX5216();
+ private:
+ // SPI object
+ SPI &m_spi;
+ // Selector pin object
+ DigitalOut &m_pin;
+ // Identifies which IC variant is being used
+ MAX521X_ic_t m_ic_variant;
+};
+
+#endif
\ No newline at end of file
--- a/MAX5487.cpp Sun Jul 15 03:49:41 2018 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,28 +0,0 @@
-#include "MAX5487.h"
-
-MAX5487::MAX5487(SPI &spi, DigitalOut &pin) : m_spi(spi), m_pin(pin)
-{
- m_pin = 1;
-}
-
-
-void MAX5487::writeCommand(MAX5487::setting_t setting, int value)
-{
- if((value >> 8) > 0) {
- printf("value in writeCommand > 8 bits!\r\n");
- return;
- }
- m_pin = 0;
- m_spi.write(setting);
- m_spi.write(value);
- m_pin = 1;
-}
-
-
-void MAX5487::writeCommand(MAX5487::setting_t setting)
-{
- m_pin = 0;
- m_spi.write(setting);
- m_pin = 1;
-}
-
\ No newline at end of file
--- a/MAX5487.h Sun Jul 15 03:49:41 2018 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,120 +0,0 @@
-/*******************************************************************************
-* @file MAX5487.h
-
-*******************************************************************************
-*/
-
-#ifndef MAX5487_H
-#define MAX5487_H
-
-#include "mbed.h"
-
-
-/**
-* @brief Dual Channel SPI Digital Potentiometers with Non Volatile Memory
-* for the MAX5487, MAX5488, MAX5489.
-*
-* @details The MAX5487 contains two SPI programmable potentiometers.
-* This driver enables setting the potentiometer wiper values as well
-* as the nonvolatile memory. This driver is compatible with the
-* MAX5487, MAX5488, MAX5489.
-*
-* @code
-* #include "mbed.h"
-* #include "max32630fthr.h"
-* #include "USBSerial.h"
-* #include "MAX5487.h"
-* MAX32630FTHR pegasus(MAX32630FTHR::VIO_3V3);
-* Serial daplink(P2_1, P2_0);
-* USBSerial microUSB;
-* DigitalOut led1(LED1); // led to blink
-* DigitalOut selectPin(P3_0); // Pin 6_0 is used to drive chip enable low
-* SPI spi(P5_1, P5_2, P5_0); // mosi, miso, sclk
-
-* int main()
-* {
-* MAX5487 test(spi, selectPin);
-* spi.format(8,0);
-* spi.frequency(1000000);
-* test.writeCommand(MAX5487::Wiper_RegA, 0x55);
-*
-* //... rest of application
-* }
-* @endcode
-*/
-
-
-
-class MAX5487{
- public:
- /**
- * @brief Commands supported by the potentiometer
- * @details write commands that don't involve copying
- * require an 8 bit value specified. Copy commands don't
- * requre sending an 8 bit value.
- */
- typedef enum {
- Wiper_RegA = 0x01, //Position of Wiper A
- Wiper_RegB = 0x02, //Position of Wiper B
- NV_RegA = 0x11, //Non Volatile Register A
- NV_RegB = 0x12, //Non Volatile Register B
- Copy_Wiper_RegA_to_NV_RegA = 0x21, //Copy Wiper A position to Non Volatile Register A
- Copy_Wiper_RegB_to_NV_RegB = 0x22, //Copy Wiper B position to Non Volatile Register B
- Copy_Wiper_RegAB_to_NV_RegAB = 0x23, //Copy both Wiper A & B positions to respective Non Volatile Registers
- Copy_NV_RegA_to_Wiper_RegA = 0x31, //Copy Non Volatile Register A to Wiper Register A
- Copy_NV_RegB_to_Wiper_RegB = 0x32, //Copy Non Volatile Register B to Wiper Register B
- Copy_NV_RegAB_to_Wiper_RegAB = 0x33 //Copy Non Volatile Register A & B to Wiper Register A & B
- } setting_t;
-
- /**********************************************************//**
- * @brief Constructor for MAX5487 Class.
- *
- * @details Requires an existing SPI object as well as a DigitalOut object.
- * The DigitalOut object is used for a chip enable signal
- *
- * On Entry:
- * @param[in] spi - pointer to existing SPI object
- * @param[in] pin - pointer to a DigitalOut pin object
- *
- * On Exit:
- *
- * @return None
- **************************************************************/
- MAX5487(SPI &spi, DigitalOut &pin);
-
- /**
- * @brief Send write command
- * @param setting - Command sent to MAX5487 register
- * @param value - 8 bit Value to write
- * @return void, output is sent through serial port
- */
- void writeCommand(MAX5487::setting_t setting, int value);
-
- /**
- * @brief Send copy command
- * @param setting - Command sent to MAX5487 register
- * @return void
- */
- void writeCommand(MAX5487::setting_t setting);
-
-
- /************************************************************
- * @brief Default destructor for MAX5487 Class.
- *
- * @details Destroys SPI object if owner
- *
- * On Entry:
- *
- * On Exit:
- *
- * @return None
- **************************************************************/
- ~MAX5487();
- private:
- // SPI object
- SPI &m_spi;
- // Selector pin object
- DigitalOut &m_pin;
-};
-
-#endif
\ No newline at end of file
