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:
jungkeviny
Date:
Sat Jul 14 04:25:25 2018 +0000
Revision:
1:bc368afe2ec8
Parent:
0:3d525ab09933
Child:
2:80e026469122
header file now has 2 method declarations to writeCommands

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jungkeviny 1:bc368afe2ec8 1 /*******************************************************************************
jungkeviny 1:bc368afe2ec8 2 * @file MAX5487.h
jungkeviny 1:bc368afe2ec8 3
jungkeviny 1:bc368afe2ec8 4 *******************************************************************************
jungkeviny 1:bc368afe2ec8 5 */
jungkeviny 1:bc368afe2ec8 6
jungkeviny 1:bc368afe2ec8 7
jungkeviny 1:bc368afe2ec8 8
jungkeviny 1:bc368afe2ec8 9 /**
jungkeviny 1:bc368afe2ec8 10 * @brief Dual Channel SPI Digital Potentiometers with Non Volatile Memory
jungkeviny 1:bc368afe2ec8 11 *
jungkeviny 1:bc368afe2ec8 12 * @details The MAX5487 contains two SPI porgrammable potentiometers.
jungkeviny 1:bc368afe2ec8 13 * This driver enables setting the potentiometer wiper values as well
jungkeviny 1:bc368afe2ec8 14 * as the nonvolatile memory.
jungkeviny 1:bc368afe2ec8 15 *
jungkeviny 1:bc368afe2ec8 16 * @code
jungkeviny 1:bc368afe2ec8 17 * #include "mbed.h"
jungkeviny 1:bc368afe2ec8 18 * #include "max32630fthr.h"
jungkeviny 1:bc368afe2ec8 19 * #include "USBSerial.h"
jungkeviny 1:bc368afe2ec8 20 * #include "MAX5487.h"
jungkeviny 1:bc368afe2ec8 21 * MAX32630FTHR pegasus(MAX32630FTHR::VIO_3V3);
jungkeviny 1:bc368afe2ec8 22 * Serial daplink(P2_1, P2_0);
jungkeviny 1:bc368afe2ec8 23 * USBSerial microUSB;
jungkeviny 1:bc368afe2ec8 24 * DigitalOut led1(LED1); // led to blink
jungkeviny 1:bc368afe2ec8 25 * DigitalOut selectPin(P3_0); // Pin 6_0 is used to drive chip enable low
jungkeviny 1:bc368afe2ec8 26 * SPI spi(P5_1, P5_2, P5_0); // mosi, miso, sclk
jungkeviny 1:bc368afe2ec8 27
jungkeviny 1:bc368afe2ec8 28 * int main()
jungkeviny 1:bc368afe2ec8 29 * {
jungkeviny 1:bc368afe2ec8 30 * MAX5487 test(spi, selectPin);
jungkeviny 1:bc368afe2ec8 31 * spi.format(8,0);
jungkeviny 1:bc368afe2ec8 32 * spi.frequency(1000000);
jungkeviny 1:bc368afe2ec8 33 * test.writeCommand(MAX5487::Wiper_RegA, 0x55);
jungkeviny 1:bc368afe2ec8 34 *
jungkeviny 1:bc368afe2ec8 35 * //... rest of application
jungkeviny 1:bc368afe2ec8 36 * }
jungkeviny 1:bc368afe2ec8 37 * @endcode
jungkeviny 1:bc368afe2ec8 38 */
jungkeviny 1:bc368afe2ec8 39
jungkeviny 0:3d525ab09933 40 #ifndef MAX5487_H
jungkeviny 0:3d525ab09933 41 #define MAX5487_H
jungkeviny 0:3d525ab09933 42
jungkeviny 0:3d525ab09933 43 #include "mbed.h"
jungkeviny 0:3d525ab09933 44
jungkeviny 0:3d525ab09933 45
jungkeviny 0:3d525ab09933 46 class MAX5487{
jungkeviny 1:bc368afe2ec8 47 public:
jungkeviny 1:bc368afe2ec8 48 /**
jungkeviny 1:bc368afe2ec8 49 * @brief Commands supported by the potentiometer
jungkeviny 1:bc368afe2ec8 50 * @details write commands that don't involve copying
jungkeviny 1:bc368afe2ec8 51 * require a 8 bit value specified. Copy commands don't
jungkeviny 1:bc368afe2ec8 52 */
jungkeviny 0:3d525ab09933 53 typedef enum {
jungkeviny 1:bc368afe2ec8 54 Wiper_RegA = 0x01, //Position of Wiper A
jungkeviny 1:bc368afe2ec8 55 Wiper_RegB = 0x02, //Position of Wiper B
jungkeviny 1:bc368afe2ec8 56 NV_RegA = 0x11, //Non Volatile Register A
jungkeviny 1:bc368afe2ec8 57 NV_RegB = 0x12, //Non Volatile Register B
jungkeviny 1:bc368afe2ec8 58 Copy_Wiper_RegA_to_NV_RegA = 0x21, //Copy Wiper A position to Non Volatile Register A
jungkeviny 1:bc368afe2ec8 59 Copy_Wiper_RegB_to_NV_RegB = 0x22, //Copy Wiper B position to Non Volatile Register B
jungkeviny 1:bc368afe2ec8 60 Copy_Wiper_RegAB_to_NV_RegAB = 0x23, //Copy both Wiper A & B positions to respective Non Volatile Registers
jungkeviny 1:bc368afe2ec8 61 Copy_NV_RegA_to_Wiper_RegA = 0x31, //Copy Non Volatile Register A to Wiper Register A
jungkeviny 1:bc368afe2ec8 62 Copy_NV_RegB_to_Wiper_RegB = 0x32, //Copy Non Volatile Register B to Wiper Register B
jungkeviny 1:bc368afe2ec8 63 Copy_NV_RegAB_to_Wiper_RegAB = 0x33 //Copy Non Volatile Register A & B to Wiper Register A & B
jungkeviny 0:3d525ab09933 64 } setting_t;
jungkeviny 1:bc368afe2ec8 65
jungkeviny 1:bc368afe2ec8 66 /**********************************************************//**
jungkeviny 1:bc368afe2ec8 67 * @brief Constructor for MAX5487 Class.
jungkeviny 1:bc368afe2ec8 68 *
jungkeviny 1:bc368afe2ec8 69 * @details Requires an existing SPI object as well as a DigitalOut object.
jungkeviny 1:bc368afe2ec8 70 * The DigitalOut object is used for a chip enable signal
jungkeviny 1:bc368afe2ec8 71 *
jungkeviny 1:bc368afe2ec8 72 * On Entry:
jungkeviny 1:bc368afe2ec8 73 * @param[in] spi - pointer to existing SPI object
jungkeviny 1:bc368afe2ec8 74 * @param[in] pin - pointer to a DigitalOut pin object
jungkeviny 1:bc368afe2ec8 75 *
jungkeviny 1:bc368afe2ec8 76 * On Exit:
jungkeviny 1:bc368afe2ec8 77 *
jungkeviny 1:bc368afe2ec8 78 * @return None
jungkeviny 1:bc368afe2ec8 79 **************************************************************/
jungkeviny 1:bc368afe2ec8 80 MAX5487(SPI &spi, DigitalOut &pin);
jungkeviny 1:bc368afe2ec8 81
jungkeviny 1:bc368afe2ec8 82 /**
jungkeviny 1:bc368afe2ec8 83 * @brief Send write command
jungkeviny 1:bc368afe2ec8 84 * @param setting - Command sent to MAX5487 register
jungkeviny 1:bc368afe2ec8 85 * @param value - 8 bit Value to write
jungkeviny 1:bc368afe2ec8 86 * @return void, output is sent through serial port
jungkeviny 1:bc368afe2ec8 87 */
jungkeviny 1:bc368afe2ec8 88 void writeCommand(MAX5487::setting_t setting, int value);
jungkeviny 1:bc368afe2ec8 89
jungkeviny 1:bc368afe2ec8 90 /**
jungkeviny 1:bc368afe2ec8 91 * @brief Send copy command
jungkeviny 1:bc368afe2ec8 92 * @param setting - Command sent to MAX5487 register
jungkeviny 1:bc368afe2ec8 93 * @return void
jungkeviny 1:bc368afe2ec8 94 */
jungkeviny 1:bc368afe2ec8 95 void writeCommand(MAX5487::setting_t setting);
jungkeviny 0:3d525ab09933 96
jungkeviny 0:3d525ab09933 97
jungkeviny 1:bc368afe2ec8 98 /**********************************************************//**
jungkeviny 1:bc368afe2ec8 99 * @brief Default destructor for MAX5487 Class.
jungkeviny 1:bc368afe2ec8 100 *
jungkeviny 1:bc368afe2ec8 101 * @details Destroys SPI object if owner
jungkeviny 1:bc368afe2ec8 102 *
jungkeviny 1:bc368afe2ec8 103 * On Entry:
jungkeviny 1:bc368afe2ec8 104 *
jungkeviny 1:bc368afe2ec8 105 * On Exit:
jungkeviny 1:bc368afe2ec8 106 *
jungkeviny 1:bc368afe2ec8 107 * @return None
jungkeviny 1:bc368afe2ec8 108 **************************************************************/
jungkeviny 0:3d525ab09933 109 ~MAX5487();
jungkeviny 1:bc368afe2ec8 110 private:
jungkeviny 1:bc368afe2ec8 111 // SPI object
jungkeviny 1:bc368afe2ec8 112 SPI &m_spi;
jungkeviny 1:bc368afe2ec8 113 // Selector pin object
jungkeviny 1:bc368afe2ec8 114 DigitalOut &m_pin;
jungkeviny 1:bc368afe2ec8 115 };
jungkeviny 1:bc368afe2ec8 116
jungkeviny 1:bc368afe2ec8 117 #endif