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
Diff: MAX5216.h
- Revision:
- 4:280d1e05f2ca
- Parent:
- 3:4d4053c4c29e
- Child:
- 5:bd8dbd9be2ac
--- /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