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.cpp@1:bc368afe2ec8
Child:
5:bd8dbd9be2ac
Initial commit for MAX5216, MAX5216 Driver C++ Source Code

Who changed what in which revision?

UserRevisionLine numberNew contents of line
phonemacro 4:280d1e05f2ca 1 /*******************************************************************************
phonemacro 4:280d1e05f2ca 2 * Copyright (C) 2018 Maxim Integrated Products, Inc., All Rights Reserved.
phonemacro 4:280d1e05f2ca 3 *
phonemacro 4:280d1e05f2ca 4 * Permission is hereby granted, free of charge, to any person obtaining a
phonemacro 4:280d1e05f2ca 5 * copy of this software and associated documentation files (the "Software"),
phonemacro 4:280d1e05f2ca 6 * to deal in the Software without restriction, including without limitation
phonemacro 4:280d1e05f2ca 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
phonemacro 4:280d1e05f2ca 8 * and/or sell copies of the Software, and to permit persons to whom the
phonemacro 4:280d1e05f2ca 9 * Software is furnished to do so, subject to the following conditions:
phonemacro 4:280d1e05f2ca 10 *
phonemacro 4:280d1e05f2ca 11 * The above copyright notice and this permission notice shall be included
phonemacro 4:280d1e05f2ca 12 * in all copies or substantial portions of the Software.
phonemacro 4:280d1e05f2ca 13 *
phonemacro 4:280d1e05f2ca 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
phonemacro 4:280d1e05f2ca 15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
phonemacro 4:280d1e05f2ca 16 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
phonemacro 4:280d1e05f2ca 17 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
phonemacro 4:280d1e05f2ca 18 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
phonemacro 4:280d1e05f2ca 19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
phonemacro 4:280d1e05f2ca 20 * OTHER DEALINGS IN THE SOFTWARE.
phonemacro 4:280d1e05f2ca 21 *
phonemacro 4:280d1e05f2ca 22 * Except as contained in this notice, the name of Maxim Integrated
phonemacro 4:280d1e05f2ca 23 * Products, Inc. shall not be used except as stated in the Maxim Integrated
phonemacro 4:280d1e05f2ca 24 * Products, Inc. Branding Policy.
phonemacro 4:280d1e05f2ca 25 *
phonemacro 4:280d1e05f2ca 26 * The mere transfer of this software does not imply any licenses
phonemacro 4:280d1e05f2ca 27 * of trade secrets, proprietary technology, copyrights, patents,
phonemacro 4:280d1e05f2ca 28 * trademarks, maskwork rights, or any other form of intellectual
phonemacro 4:280d1e05f2ca 29 * property whatsoever. Maxim Integrated Products, Inc. retains all
phonemacro 4:280d1e05f2ca 30 * ownership rights.
phonemacro 4:280d1e05f2ca 31 *******************************************************************************
phonemacro 4:280d1e05f2ca 32 */
phonemacro 4:280d1e05f2ca 33 #include "MAX5216.h"
jungkeviny 1:bc368afe2ec8 34
phonemacro 4:280d1e05f2ca 35 MAX5216::MAX5216(SPI &spi, DigitalOut &pin, MAX521X_ic_t ic_variant) : m_spi(spi), m_pin(pin), m_ic_variant(ic_variant)
jungkeviny 1:bc368afe2ec8 36 {
jungkeviny 1:bc368afe2ec8 37 m_pin = 1;
jungkeviny 1:bc368afe2ec8 38 }
jungkeviny 1:bc368afe2ec8 39
phonemacro 4:280d1e05f2ca 40 void MAX5216::writeCommand(setting_t setting, uint32_t value)
jungkeviny 1:bc368afe2ec8 41 {
phonemacro 4:280d1e05f2ca 42
phonemacro 4:280d1e05f2ca 43 char val[3] = {0, 0, 0};
phonemacro 4:280d1e05f2ca 44 int i;
phonemacro 4:280d1e05f2ca 45
phonemacro 4:280d1e05f2ca 46 if(value > MAX521X_IC_BIT_MASK[(uint8_t)(m_ic_variant)]) {
phonemacro 4:280d1e05f2ca 47 printf("value in writeCommand is too big: %X\r\n", value);
jungkeviny 1:bc368afe2ec8 48 return;
jungkeviny 1:bc368afe2ec8 49 }
jungkeviny 1:bc368afe2ec8 50 m_pin = 0;
phonemacro 4:280d1e05f2ca 51 if (m_ic_variant == MAX5214_IC) { // MAX5214 is 14 bits
phonemacro 4:280d1e05f2ca 52 value &= MAX521X_IC_BIT_MASK[(uint8_t)(m_ic_variant)];
phonemacro 4:280d1e05f2ca 53 } else { // MAX5216 is 16 bits
phonemacro 4:280d1e05f2ca 54 value &= MAX521X_IC_BIT_MASK[(uint8_t)(m_ic_variant)];
phonemacro 4:280d1e05f2ca 55 value = value << 6; // least significant 6 bits are not used
phonemacro 4:280d1e05f2ca 56 val[2] = value & 0xFF;
phonemacro 4:280d1e05f2ca 57 value = value >> 8;
phonemacro 4:280d1e05f2ca 58 }
phonemacro 4:280d1e05f2ca 59 val[1] = value & 0xFF;
phonemacro 4:280d1e05f2ca 60 value = value >> 8;
phonemacro 4:280d1e05f2ca 61 val[0] = value;
phonemacro 4:280d1e05f2ca 62 val[0] |= setting;
phonemacro 4:280d1e05f2ca 63 //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]);
phonemacro 4:280d1e05f2ca 64
phonemacro 4:280d1e05f2ca 65 for (i = 0; i < MAX521X_NUM_BYTES_SPI[(uint8_t)(m_ic_variant)]; i++) {
phonemacro 4:280d1e05f2ca 66 m_spi.write(val[i]);
phonemacro 4:280d1e05f2ca 67 }
jungkeviny 1:bc368afe2ec8 68 m_pin = 1;
jungkeviny 1:bc368afe2ec8 69 }
phonemacro 4:280d1e05f2ca 70 #if 0 // tbd
phonemacro 4:280d1e05f2ca 71 void MAX5216::writeCommand(setting_t setting, pwrDwnMode_t mode)
jungkeviny 1:bc368afe2ec8 72 {
phonemacro 4:280d1e05f2ca 73 char val[3] = {0, 0, 0};
phonemacro 4:280d1e05f2ca 74 int i;
jungkeviny 1:bc368afe2ec8 75 m_pin = 0;
phonemacro 4:280d1e05f2ca 76 val[0] = setting | (char)(mode);
phonemacro 4:280d1e05f2ca 77 for (i = 0; i < MAX521X_NUM_BYTES_SPI[(uint8_t)(m_ic_variant)]; i++) {
phonemacro 4:280d1e05f2ca 78 m_spi.write(val[i]);
phonemacro 4:280d1e05f2ca 79 }
jungkeviny 1:bc368afe2ec8 80 m_pin = 1;
phonemacro 4:280d1e05f2ca 81
jungkeviny 1:bc368afe2ec8 82 }
phonemacro 4:280d1e05f2ca 83 #endif
phonemacro 4:280d1e05f2ca 84 MAX5216::~MAX5216(void)
phonemacro 4:280d1e05f2ca 85 {
phonemacro 4:280d1e05f2ca 86 //empty block
phonemacro 4:280d1e05f2ca 87 }
phonemacro 4:280d1e05f2ca 88