Maxim Integrated MAX5171 14-bit Force/Sense DAC

Dependents:   MAX5171BOB_Tester MAX5171BOB_14bit_Remote_Sense_SPI_DAC MAX5171BOB_Serial_Tester

Committer:
whismanoid
Date:
Fri May 15 08:23:46 2020 +0000
Revision:
7:564b438a0448
Parent:
6:f661c4a61207
Support MAX5171BOB self test

Who changed what in which revision?

UserRevisionLine numberNew contents of line
whismanoid 1:e73245718b2a 1 // /*******************************************************************************
whismanoid 5:e8c0dfaeb53b 2 // * Copyright (C) 2020 Maxim Integrated Products, Inc., All Rights Reserved.
whismanoid 1:e73245718b2a 3 // *
whismanoid 1:e73245718b2a 4 // * Permission is hereby granted, free of charge, to any person obtaining a
whismanoid 1:e73245718b2a 5 // * copy of this software and associated documentation files (the "Software"),
whismanoid 1:e73245718b2a 6 // * to deal in the Software without restriction, including without limitation
whismanoid 1:e73245718b2a 7 // * the rights to use, copy, modify, merge, publish, distribute, sublicense,
whismanoid 1:e73245718b2a 8 // * and/or sell copies of the Software, and to permit persons to whom the
whismanoid 1:e73245718b2a 9 // * Software is furnished to do so, subject to the following conditions:
whismanoid 1:e73245718b2a 10 // *
whismanoid 1:e73245718b2a 11 // * The above copyright notice and this permission notice shall be included
whismanoid 1:e73245718b2a 12 // * in all copies or substantial portions of the Software.
whismanoid 1:e73245718b2a 13 // *
whismanoid 1:e73245718b2a 14 // * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
whismanoid 1:e73245718b2a 15 // * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
whismanoid 1:e73245718b2a 16 // * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
whismanoid 1:e73245718b2a 17 // * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
whismanoid 1:e73245718b2a 18 // * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
whismanoid 1:e73245718b2a 19 // * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
whismanoid 1:e73245718b2a 20 // * OTHER DEALINGS IN THE SOFTWARE.
whismanoid 1:e73245718b2a 21 // *
whismanoid 1:e73245718b2a 22 // * Except as contained in this notice, the name of Maxim Integrated
whismanoid 1:e73245718b2a 23 // * Products, Inc. shall not be used except as stated in the Maxim Integrated
whismanoid 1:e73245718b2a 24 // * Products, Inc. Branding Policy.
whismanoid 1:e73245718b2a 25 // *
whismanoid 1:e73245718b2a 26 // * The mere transfer of this software does not imply any licenses
whismanoid 1:e73245718b2a 27 // * of trade secrets, proprietary technology, copyrights, patents,
whismanoid 1:e73245718b2a 28 // * trademarks, maskwork rights, or any other form of intellectual
whismanoid 1:e73245718b2a 29 // * property whatsoever. Maxim Integrated Products, Inc. retains all
whismanoid 1:e73245718b2a 30 // * ownership rights.
whismanoid 1:e73245718b2a 31 // *******************************************************************************
whismanoid 1:e73245718b2a 32 // */
whismanoid 1:e73245718b2a 33 // *********************************************************************
whismanoid 1:e73245718b2a 34 // @file MAX5171.cpp
whismanoid 1:e73245718b2a 35 // *********************************************************************
whismanoid 1:e73245718b2a 36 // Device Driver file
whismanoid 1:e73245718b2a 37 // DO NOT EDIT; except areas designated "CUSTOMIZE". Automatically generated file.
whismanoid 1:e73245718b2a 38 // generated by XMLSystemOfDevicesToMBED.py
whismanoid 1:e73245718b2a 39 // System Name = ExampleSystem
whismanoid 1:e73245718b2a 40 // System Description = Device driver example
whismanoid 1:e73245718b2a 41
whismanoid 1:e73245718b2a 42 #include "MAX5171.h"
whismanoid 1:e73245718b2a 43
whismanoid 1:e73245718b2a 44 // Device Name = MAX5171
whismanoid 1:e73245718b2a 45 // Device Description = Low-Power, Serial, 14-Bit, 1-Channel DACs with Force/Sense Voltage Output and SPI Interface
whismanoid 5:e8c0dfaeb53b 46 // Device DeviceBriefDescription = 14-bit Force/Sense DAC
whismanoid 1:e73245718b2a 47 // Device Manufacturer = Maxim Integrated
whismanoid 1:e73245718b2a 48 // Device PartNumber = MAX5171AEEE+
whismanoid 1:e73245718b2a 49 // Device RegValue_Width = DataWidth16bit_HL
whismanoid 1:e73245718b2a 50 //
whismanoid 1:e73245718b2a 51 // DAC NumChannels = 1
whismanoid 1:e73245718b2a 52 // DAC ResolutionBits = 14
whismanoid 1:e73245718b2a 53 //
whismanoid 1:e73245718b2a 54 // SPI CS = ActiveLow
whismanoid 1:e73245718b2a 55 // SPI FrameStart = CS
whismanoid 1:e73245718b2a 56 // SPI CPOL = 0
whismanoid 1:e73245718b2a 57 // SPI CPHA = 0
whismanoid 1:e73245718b2a 58 // SPI MOSI and MISO Data are both stable on Rising edge of SCLK
whismanoid 1:e73245718b2a 59 // SPI SCLK Idle Low
whismanoid 1:e73245718b2a 60 // SPI SCLKMaxMHz = 10
whismanoid 1:e73245718b2a 61 // SPI SCLKMinMHz = 0
whismanoid 1:e73245718b2a 62 //
whismanoid 1:e73245718b2a 63 // InputPin Name = FB
whismanoid 1:e73245718b2a 64 // InputPin Description = Feedback Input
whismanoid 1:e73245718b2a 65 // InputPin Function = Analog
whismanoid 1:e73245718b2a 66 //
whismanoid 1:e73245718b2a 67 // InputPin Name = RS
whismanoid 1:e73245718b2a 68 // InputPin Description = Reset Mode Select (digital input). Connect to VDD to select midscale reset output value. Connect to DGND
whismanoid 1:e73245718b2a 69 // to select 0 reset output value.
whismanoid 1:e73245718b2a 70 // InputPin Function = Configuration
whismanoid 1:e73245718b2a 71 //
whismanoid 1:e73245718b2a 72 // InputPin Name = PDL#
whismanoid 1:e73245718b2a 73 // InputPin Description = Power-Down Lockout (digital input). Connect to VDD to allow shutdown. Connect to DGND to disable shutdown.
whismanoid 1:e73245718b2a 74 // InputPin Function = Configuration
whismanoid 1:e73245718b2a 75 //
whismanoid 1:e73245718b2a 76 // InputPin Name = CLR#
whismanoid 1:e73245718b2a 77 // InputPin Description = Clear DAC (digital input). Clears the DAC to its predetermined output state as set by RS.
whismanoid 1:e73245718b2a 78 // InputPin Function = Configuration
whismanoid 1:e73245718b2a 79 //
whismanoid 1:e73245718b2a 80 // InputPin Name = SHDN
whismanoid 1:e73245718b2a 81 // InputPin Description = Shutdown (digital input). Pulling SHDN high when PDL = VDD places the chip in shutdown mode with a
whismanoid 1:e73245718b2a 82 // maximum shutdown current 0f 10uA.
whismanoid 1:e73245718b2a 83 // InputPin Function = Configuration
whismanoid 1:e73245718b2a 84 //
whismanoid 1:e73245718b2a 85 // OutputPin Name = OUT
whismanoid 1:e73245718b2a 86 // OutputPin Description = Analog Voltage Output. High impedance in shutdown. Output voltage is limited to VDD.
whismanoid 1:e73245718b2a 87 // OutputPin Function = Analog
whismanoid 1:e73245718b2a 88 //
whismanoid 1:e73245718b2a 89 // OutputPin Name = UPO
whismanoid 1:e73245718b2a 90 // OutputPin Description = User-Programmable Output. State is set by serial input.
whismanoid 1:e73245718b2a 91 // OutputPin Function = General-Purpose
whismanoid 1:e73245718b2a 92 //
whismanoid 1:e73245718b2a 93 // SupplyPin Name = VDD
whismanoid 1:e73245718b2a 94 // SupplyPin Description = Positive Supply. Bypass to AGND with a 4.7uF capacitor in parallel with a 0.1uF capacitor.
whismanoid 1:e73245718b2a 95 // SupplyPin VinMax = 4.50
whismanoid 1:e73245718b2a 96 // SupplyPin VinMin = 5.50
whismanoid 1:e73245718b2a 97 // SupplyPin Function = Analog
whismanoid 1:e73245718b2a 98 //
whismanoid 1:e73245718b2a 99 // SupplyPin Name = REF
whismanoid 1:e73245718b2a 100 // SupplyPin Description = Reference Input. Maximum VREF is VDD - 1.4V. Connect an external +2.5V reference.
whismanoid 1:e73245718b2a 101 // SupplyPin VinMax = VDD-1.4
whismanoid 1:e73245718b2a 102 // SupplyPin VinMin = 0
whismanoid 1:e73245718b2a 103 // SupplyPin Function = Analog
whismanoid 1:e73245718b2a 104 //
whismanoid 1:e73245718b2a 105 // SupplyPin Name = DGND
whismanoid 1:e73245718b2a 106 // SupplyPin Description = Digital Ground.
whismanoid 1:e73245718b2a 107 // SupplyPin VinMax = 0
whismanoid 1:e73245718b2a 108 // SupplyPin VinMin = 0
whismanoid 1:e73245718b2a 109 // SupplyPin Function = Analog
whismanoid 1:e73245718b2a 110 //
whismanoid 1:e73245718b2a 111 // SupplyPin Name = AGND
whismanoid 1:e73245718b2a 112 // SupplyPin Description = Analog Ground.
whismanoid 1:e73245718b2a 113 // SupplyPin VinMax = 0
whismanoid 1:e73245718b2a 114 // SupplyPin VinMin = 0
whismanoid 1:e73245718b2a 115 // SupplyPin Function = Analog
whismanoid 1:e73245718b2a 116 //
whismanoid 1:e73245718b2a 117
whismanoid 1:e73245718b2a 118 MAX5171::MAX5171(SPI &spi, DigitalOut &cs_pin, // SPI interface
whismanoid 1:e73245718b2a 119 // AnalogOut &FB_pin, // Analog Input to MAX5171 device
whismanoid 1:e73245718b2a 120 DigitalOut &RS_pin, // Digital Configuration Input to MAX5171 device
whismanoid 1:e73245718b2a 121 DigitalOut &PDLb_pin, // Digital Configuration Input to MAX5171 device
whismanoid 1:e73245718b2a 122 DigitalOut &CLRb_pin, // Digital Configuration Input to MAX5171 device
whismanoid 1:e73245718b2a 123 DigitalOut &SHDN_pin, // Digital Configuration Input to MAX5171 device
whismanoid 1:e73245718b2a 124 // AnalogIn &OUT_pin, // Analog Output from MAX5171 device
whismanoid 1:e73245718b2a 125 DigitalIn &UPO_pin, // Digital General-Purpose Output from MAX5171 device
whismanoid 1:e73245718b2a 126 MAX5171_ic_t ic_variant)
whismanoid 1:e73245718b2a 127 : m_spi(spi), m_cs_pin(cs_pin), // SPI interface
whismanoid 3:79839617d532 128 // m_FB_pin(FB_pin), // Analog Input to MAX5171 device
whismanoid 3:79839617d532 129 m_RS_pin(RS_pin), // Digital Configuration Input to MAX5171 device
whismanoid 3:79839617d532 130 m_PDLb_pin(PDLb_pin), // Digital Configuration Input to MAX5171 device
whismanoid 3:79839617d532 131 m_CLRb_pin(CLRb_pin), // Digital Configuration Input to MAX5171 device
whismanoid 3:79839617d532 132 m_SHDN_pin(SHDN_pin), // Digital Configuration Input to MAX5171 device
whismanoid 3:79839617d532 133 // m_OUT_pin(OUT_pin), // Analog Output from MAX5171 device
whismanoid 3:79839617d532 134 m_UPO_pin(UPO_pin), // Digital General-Purpose Output from MAX5171 device
whismanoid 3:79839617d532 135 m_ic_variant(ic_variant)
whismanoid 1:e73245718b2a 136 {
whismanoid 1:e73245718b2a 137 // SPI CS = ActiveLow
whismanoid 1:e73245718b2a 138 // SPI FrameStart = CS
whismanoid 1:e73245718b2a 139 m_SPI_cs_state = 1;
whismanoid 5:e8c0dfaeb53b 140 if (m_cs_pin.is_connected()) { // avoid mbed runtime error if pin is NC not connected
whismanoid 5:e8c0dfaeb53b 141 m_cs_pin = m_SPI_cs_state;
whismanoid 5:e8c0dfaeb53b 142 }
whismanoid 1:e73245718b2a 143
whismanoid 1:e73245718b2a 144 // SPI CPOL = 0
whismanoid 1:e73245718b2a 145 // SPI CPHA = 0
whismanoid 1:e73245718b2a 146 // SPI MOSI and MISO Data are both stable on Rising edge of SCLK
whismanoid 1:e73245718b2a 147 // SPI SCLK Idle Low
whismanoid 5:e8c0dfaeb53b 148 m_SPI_dataMode = 0; //SPI_MODE0; // CPOL=0,CPHA=0: Rising Edge stable; SCLK idle Low
whismanoid 1:e73245718b2a 149 m_spi.format(8,m_SPI_dataMode); // int bits_must_be_8, int mode=0_3 CPOL=0,CPHA=0
whismanoid 1:e73245718b2a 150
whismanoid 1:e73245718b2a 151 // SPI SCLKMaxMHz = 10
whismanoid 1:e73245718b2a 152 // SPI SCLKMinMHz = 0
whismanoid 1:e73245718b2a 153 //#define SPI_SCLK_Hz 48000000 // 48MHz
whismanoid 1:e73245718b2a 154 //#define SPI_SCLK_Hz 24000000 // 24MHz
whismanoid 1:e73245718b2a 155 //#define SPI_SCLK_Hz 12000000 // 12MHz
whismanoid 5:e8c0dfaeb53b 156 //#define SPI_SCLK_Hz 6000000 // 6MHz
whismanoid 1:e73245718b2a 157 //#define SPI_SCLK_Hz 4000000 // 4MHz
whismanoid 1:e73245718b2a 158 //#define SPI_SCLK_Hz 2000000 // 2MHz
whismanoid 1:e73245718b2a 159 //#define SPI_SCLK_Hz 1000000 // 1MHz
whismanoid 1:e73245718b2a 160 m_SPI_SCLK_Hz = 10000000; // 10MHz; MAX5171 limit is 10MHz
whismanoid 1:e73245718b2a 161 m_spi.frequency(m_SPI_SCLK_Hz);
whismanoid 1:e73245718b2a 162
whismanoid 1:e73245718b2a 163 //
whismanoid 5:e8c0dfaeb53b 164 // FB Analog Input to MAX5171 device
whismanoid 5:e8c0dfaeb53b 165 //
whismanoid 5:e8c0dfaeb53b 166 // RS Configuration Input to MAX5171 device
whismanoid 1:e73245718b2a 167 m_RS_pin = 1; // output logic high -- initial value in constructor
whismanoid 5:e8c0dfaeb53b 168 //
whismanoid 5:e8c0dfaeb53b 169 // PDLb Configuration Input to MAX5171 device
whismanoid 1:e73245718b2a 170 m_PDLb_pin = 1; // output logic high -- initial value in constructor
whismanoid 5:e8c0dfaeb53b 171 //
whismanoid 5:e8c0dfaeb53b 172 // CLRb Configuration Input to MAX5171 device
whismanoid 1:e73245718b2a 173 m_CLRb_pin = 1; // output logic high -- initial value in constructor
whismanoid 5:e8c0dfaeb53b 174 //
whismanoid 5:e8c0dfaeb53b 175 // SHDN Configuration Input to MAX5171 device
whismanoid 1:e73245718b2a 176 m_SHDN_pin = 1; // output logic high -- initial value in constructor
whismanoid 5:e8c0dfaeb53b 177 //
whismanoid 5:e8c0dfaeb53b 178 // OUT Analog Output from device
whismanoid 5:e8c0dfaeb53b 179 //
whismanoid 5:e8c0dfaeb53b 180 // UPO General-Purpose Output from device
whismanoid 1:e73245718b2a 181 }
whismanoid 1:e73245718b2a 182
whismanoid 1:e73245718b2a 183 MAX5171::~MAX5171()
whismanoid 1:e73245718b2a 184 {
whismanoid 1:e73245718b2a 185 // do nothing
whismanoid 1:e73245718b2a 186 }
whismanoid 1:e73245718b2a 187
whismanoid 5:e8c0dfaeb53b 188 /// set SPI SCLK frequency
whismanoid 1:e73245718b2a 189 void MAX5171::spi_frequency(int spi_sclk_Hz)
whismanoid 1:e73245718b2a 190 {
whismanoid 1:e73245718b2a 191 m_SPI_SCLK_Hz = spi_sclk_Hz;
whismanoid 1:e73245718b2a 192 m_spi.frequency(m_SPI_SCLK_Hz);
whismanoid 1:e73245718b2a 193 }
whismanoid 1:e73245718b2a 194
whismanoid 1:e73245718b2a 195 // Assert SPI Chip Select
whismanoid 1:e73245718b2a 196 // SPI chip-select for MAX5171
whismanoid 1:e73245718b2a 197 //
whismanoid 5:e8c0dfaeb53b 198 inline void MAX5171::SPIoutputCS(int isLogicHigh)
whismanoid 1:e73245718b2a 199 {
whismanoid 1:e73245718b2a 200 m_SPI_cs_state = isLogicHigh;
whismanoid 5:e8c0dfaeb53b 201 if (m_cs_pin.is_connected()) { // avoid mbed runtime error if pin is NC not connected
whismanoid 5:e8c0dfaeb53b 202 m_cs_pin = m_SPI_cs_state;
whismanoid 5:e8c0dfaeb53b 203 }
whismanoid 1:e73245718b2a 204 }
whismanoid 1:e73245718b2a 205
whismanoid 1:e73245718b2a 206 // SPI write 16 bits
whismanoid 1:e73245718b2a 207 // SPI interface to MAX5171 shift 16 bits mosiData into MAX5171 DIN
whismanoid 1:e73245718b2a 208 //
whismanoid 1:e73245718b2a 209 void MAX5171::SPIwrite16bits(int16_t mosiData16)
whismanoid 1:e73245718b2a 210 {
whismanoid 1:e73245718b2a 211 size_t byteCount = 2;
whismanoid 1:e73245718b2a 212 static char mosiData[2];
whismanoid 1:e73245718b2a 213 static char misoData[2];
whismanoid 1:e73245718b2a 214 mosiData[0] = (char)((mosiData16 >> 8) & 0xFF); // MSByte
whismanoid 1:e73245718b2a 215 mosiData[1] = (char)((mosiData16 >> 0) & 0xFF); // LSByte
whismanoid 1:e73245718b2a 216 //
whismanoid 1:e73245718b2a 217 // Arduino: begin critical section: noInterrupts() masks all interrupt sources; end critical section with interrupts()
whismanoid 1:e73245718b2a 218 //~ noInterrupts();
whismanoid 1:e73245718b2a 219 //
whismanoid 1:e73245718b2a 220 //~ digitalWrite(Scope_Trigger_Pin, LOW); // diagnostic Scope_Trigger_Pin
whismanoid 1:e73245718b2a 221 //
whismanoid 1:e73245718b2a 222 unsigned int numBytesTransferred = m_spi.write(mosiData, byteCount, misoData, byteCount);
whismanoid 1:e73245718b2a 223 //~ m_spi.transfer(mosiData8_FF0000);
whismanoid 1:e73245718b2a 224 //~ m_spi.transfer(mosiData16_00FF00);
whismanoid 1:e73245718b2a 225 //~ m_spi.transfer(mosiData16_0000FF);
whismanoid 1:e73245718b2a 226 //
whismanoid 1:e73245718b2a 227 //~ digitalWrite(Scope_Trigger_Pin, HIGH); // diagnostic Scope_Trigger_Pin
whismanoid 1:e73245718b2a 228 //
whismanoid 1:e73245718b2a 229 // Arduino: begin critical section: noInterrupts() masks all interrupt sources; end critical section with interrupts()
whismanoid 1:e73245718b2a 230 //~ interrupts();
whismanoid 5:e8c0dfaeb53b 231 // Optional Diagnostic function to print SPI transactions
whismanoid 5:e8c0dfaeb53b 232 if (onSPIprint)
whismanoid 5:e8c0dfaeb53b 233 {
whismanoid 5:e8c0dfaeb53b 234 onSPIprint(byteCount, (uint8_t*)mosiData, (uint8_t*)misoData);
whismanoid 5:e8c0dfaeb53b 235 }
whismanoid 1:e73245718b2a 236 //
whismanoid 1:e73245718b2a 237 // VERIFY: SPIwrite24bits print diagnostic information
whismanoid 1:e73245718b2a 238 //cmdLine.serial().printf(" MOSI->"));
whismanoid 1:e73245718b2a 239 //cmdLine.serial().printf(" 0x"));
whismanoid 1:e73245718b2a 240 //Serial.print( (mosiData8_FF0000 & 0xFF), HEX);
whismanoid 1:e73245718b2a 241 //cmdLine.serial().printf(" 0x"));
whismanoid 1:e73245718b2a 242 //Serial.print( (mosiData16_00FF00 & 0xFF), HEX);
whismanoid 1:e73245718b2a 243 //cmdLine.serial().printf(" 0x"));
whismanoid 1:e73245718b2a 244 //Serial.print( (mosiData16_0000FF & 0xFF), HEX);
whismanoid 1:e73245718b2a 245 // hex dump mosiData[0..byteCount-1]
whismanoid 1:e73245718b2a 246 #if 0 // HAS_MICROUSBSERIAL
whismanoid 1:e73245718b2a 247 cmdLine_microUSBserial.serial().printf("\r\nSPI");
whismanoid 1:e73245718b2a 248 if (byteCount > 7) {
whismanoid 1:e73245718b2a 249 cmdLine_microUSBserial.serial().printf(" byteCount:%d", byteCount);
whismanoid 1:e73245718b2a 250 }
whismanoid 1:e73245718b2a 251 cmdLine_microUSBserial.serial().printf(" MOSI->");
whismanoid 3:79839617d532 252 for (unsigned int byteIndex = 0; byteIndex < byteCount; byteIndex++)
whismanoid 3:79839617d532 253 {
whismanoid 1:e73245718b2a 254 cmdLine_microUSBserial.serial().printf(" 0x%2.2X", mosiData[byteIndex]);
whismanoid 1:e73245718b2a 255 }
whismanoid 1:e73245718b2a 256 // hex dump misoData[0..byteCount-1]
whismanoid 7:564b438a0448 257 cmdLine_microUSBserial.serial().printf(" MISO<-");
whismanoid 3:79839617d532 258 for (unsigned int byteIndex = 0; byteIndex < numBytesTransferred; byteIndex++)
whismanoid 3:79839617d532 259 {
whismanoid 1:e73245718b2a 260 cmdLine_microUSBserial.serial().printf(" 0x%2.2X", misoData[byteIndex]);
whismanoid 1:e73245718b2a 261 }
whismanoid 1:e73245718b2a 262 cmdLine_microUSBserial.serial().printf(" ");
whismanoid 1:e73245718b2a 263 #endif
whismanoid 1:e73245718b2a 264 #if 0 // HAS_DAPLINK_SERIAL
whismanoid 1:e73245718b2a 265 cmdLine_DAPLINKserial.serial().printf("\r\nSPI");
whismanoid 1:e73245718b2a 266 if (byteCount > 7) {
whismanoid 1:e73245718b2a 267 cmdLine_DAPLINKserial.serial().printf(" byteCount:%d", byteCount);
whismanoid 1:e73245718b2a 268 }
whismanoid 1:e73245718b2a 269 cmdLine_DAPLINKserial.serial().printf(" MOSI->");
whismanoid 3:79839617d532 270 for (unsigned int byteIndex = 0; byteIndex < byteCount; byteIndex++)
whismanoid 3:79839617d532 271 {
whismanoid 1:e73245718b2a 272 cmdLine_DAPLINKserial.serial().printf(" 0x%2.2X", mosiData[byteIndex]);
whismanoid 1:e73245718b2a 273 }
whismanoid 1:e73245718b2a 274 // hex dump misoData[0..byteCount-1]
whismanoid 7:564b438a0448 275 cmdLine_DAPLINKserial.serial().printf(" MISO<-");
whismanoid 3:79839617d532 276 for (unsigned int byteIndex = 0; byteIndex < numBytesTransferred; byteIndex++)
whismanoid 3:79839617d532 277 {
whismanoid 1:e73245718b2a 278 cmdLine_DAPLINKserial.serial().printf(" 0x%2.2X", misoData[byteIndex]);
whismanoid 1:e73245718b2a 279 }
whismanoid 1:e73245718b2a 280 cmdLine_DAPLINKserial.serial().printf(" ");
whismanoid 1:e73245718b2a 281 #endif
whismanoid 1:e73245718b2a 282 // VERIFY: DIAGNOSTIC: print MAX5715 device register write
whismanoid 1:e73245718b2a 283 // TODO: MAX5715_print_register_verbose(mosiData8_FF0000, mosiData16_00FFFF);
whismanoid 1:e73245718b2a 284 // TODO: print_verbose_SPI_diagnostic(mosiData16_FF00, mosiData16_00FF, misoData16_FF00, misoData16_00FF);
whismanoid 1:e73245718b2a 285 //
whismanoid 1:e73245718b2a 286 // int misoData16 = (misoData16_FF00 << 8) | misoData16_00FF;
whismanoid 1:e73245718b2a 287 // return misoData16;
whismanoid 1:e73245718b2a 288 }
whismanoid 0:80a9add62408 289
whismanoid 1:e73245718b2a 290 //----------------------------------------
whismanoid 5:e8c0dfaeb53b 291 // Menu item '!'
whismanoid 1:e73245718b2a 292 // Initialize device
whismanoid 6:f661c4a61207 293 //
whismanoid 6:f661c4a61207 294 // TODO1: #170 MAX5171 Self Test for Test Fixture Firmware
whismanoid 6:f661c4a61207 295 // @future test group ____ // Verify function ____ (enabled by default)
whismanoid 6:f661c4a61207 296 // @future test
whismanoid 6:f661c4a61207 297 // tinyTester.settle_time_msec = 250;
whismanoid 6:f661c4a61207 298 //
whismanoid 6:f661c4a61207 299 // @test group DACCodeOfVoltage // Verify function DACCodeOfVoltage (enabled by default)
whismanoid 6:f661c4a61207 300 // @test group DACCodeOfVoltage tinyTester.blink_time_msec = 20 // quickly speed through the software verification
whismanoid 6:f661c4a61207 301 // @test group DACCodeOfVoltage tinyTester.print("VRef = 2.500 MAX5171 14-bit LSB = 0.00015V")
whismanoid 6:f661c4a61207 302 // @test group DACCodeOfVoltage VRef = 2.500
whismanoid 6:f661c4a61207 303 // @test group DACCodeOfVoltage tinyTester.err_threshold = 0.00015259720441921504 // 14-bit LSB (2.500/16383)
whismanoid 6:f661c4a61207 304 // //
whismanoid 6:f661c4a61207 305 // @test group DACCodeOfVoltage DACCodeOfVoltage(2.499847412109375) expect 0x3FFF
whismanoid 6:f661c4a61207 306 // @test group DACCodeOfVoltage DACCodeOfVoltage(2.49969482421875) expect 0x3FFE
whismanoid 6:f661c4a61207 307 // @test group DACCodeOfVoltage DACCodeOfVoltage(2.499542236328125) expect 0x3FFD
whismanoid 6:f661c4a61207 308 // @test group DACCodeOfVoltage DACCodeOfVoltage(2.4993896484375) expect 0x3FFC
whismanoid 6:f661c4a61207 309 // @test group DACCodeOfVoltage DACCodeOfVoltage(1.250152587890625) expect 0x2001
whismanoid 6:f661c4a61207 310 // @test group DACCodeOfVoltage DACCodeOfVoltage(1.25) expect 0x2000
whismanoid 6:f661c4a61207 311 // @test group DACCodeOfVoltage DACCodeOfVoltage(1.249847412109375) expect 0x1FFF
whismanoid 6:f661c4a61207 312 // @test group DACCodeOfVoltage DACCodeOfVoltage(1.24969482421875) expect 0x1FFE
whismanoid 6:f661c4a61207 313 // @test group DACCodeOfVoltage DACCodeOfVoltage(0.000457763671875) expect 0x0003
whismanoid 6:f661c4a61207 314 // @test group DACCodeOfVoltage DACCodeOfVoltage(0.00030517578125) expect 0x0002
whismanoid 6:f661c4a61207 315 // @test group DACCodeOfVoltage DACCodeOfVoltage(0.000152587890625) expect 0x0001
whismanoid 6:f661c4a61207 316 // @test group DACCodeOfVoltage DACCodeOfVoltage(0.00000) expect 0x0000
whismanoid 6:f661c4a61207 317 // @test group DACCodeOfVoltage tinyTester.blink_time_msec = 75 // default 75 resume hardware self test
whismanoid 6:f661c4a61207 318 // //
whismanoid 6:f661c4a61207 319 // @test group VoltageOfCode // Verify function VoltageOfCode (enabled by default)
whismanoid 6:f661c4a61207 320 // @test group VoltageOfCode tinyTester.blink_time_msec = 20 // quickly speed through the software verification
whismanoid 6:f661c4a61207 321 // @test group VoltageOfCode tinyTester.print("VRef = 2.500 MAX5171 14-bit LSB = 0.00015V")
whismanoid 6:f661c4a61207 322 // @test group VoltageOfCode VRef = 2.500
whismanoid 6:f661c4a61207 323 // @test group VoltageOfCode tinyTester.err_threshold = 0.00015259720441921504 // 14-bit LSB (2.500/16383)
whismanoid 6:f661c4a61207 324 // @test group VoltageOfCode VoltageOfCode(0x3FFF) expect 2.499847412109375
whismanoid 6:f661c4a61207 325 // @test group VoltageOfCode VoltageOfCode(0x3FFE) expect 2.49969482421875
whismanoid 6:f661c4a61207 326 // @test group VoltageOfCode VoltageOfCode(0x3FFD) expect 2.499542236328125
whismanoid 6:f661c4a61207 327 // @test group VoltageOfCode VoltageOfCode(0x3FFC) expect 2.4993896484375
whismanoid 6:f661c4a61207 328 // @test group VoltageOfCode VoltageOfCode(0x2001) expect 1.250152587890625
whismanoid 6:f661c4a61207 329 // @test group VoltageOfCode VoltageOfCode(0x2000) expect 1.25
whismanoid 6:f661c4a61207 330 // @test group VoltageOfCode VoltageOfCode(0x1FFF) expect 1.249847412109375
whismanoid 6:f661c4a61207 331 // @test group VoltageOfCode VoltageOfCode(0x1FFE) expect 1.24969482421875
whismanoid 6:f661c4a61207 332 // @test group VoltageOfCode VoltageOfCode(0x0003) expect 0.000457763671875
whismanoid 6:f661c4a61207 333 // @test group VoltageOfCode VoltageOfCode(0x0002) expect 0.00030517578125
whismanoid 6:f661c4a61207 334 // @test group VoltageOfCode VoltageOfCode(0x0001) expect 0.000152587890625
whismanoid 6:f661c4a61207 335 // @test group VoltageOfCode VoltageOfCode(0x0000) expect 0.00000
whismanoid 6:f661c4a61207 336 // @test group VoltageOfCode tinyTester.blink_time_msec = 75 // default 75 resume hardware self test
whismanoid 6:f661c4a61207 337 // //
whismanoid 6:f661c4a61207 338 // // Device Testing: DAC commands, verify using on-board ADC inputs
whismanoid 6:f661c4a61207 339 // //
whismanoid 6:f661c4a61207 340 // @test group CODE_LOAD // Verify function CODE_LOAD (enabled by default)
whismanoid 6:f661c4a61207 341 // @test group CODE_LOAD tinyTester.blink_time_msec = 75 // default 75 resume hardware self test
whismanoid 6:f661c4a61207 342 // @test group CODE_LOAD tinyTester.settle_time_msec = 500
whismanoid 6:f661c4a61207 343 // tinyTester.blink_time_msec = 75;
whismanoid 6:f661c4a61207 344 // cmdLine.serial().printf("
whismanoid 6:f661c4a61207 345 // MAX5171.Init()");
whismanoid 6:f661c4a61207 346 // Init();
whismanoid 6:f661c4a61207 347 // @test Init()
whismanoid 6:f661c4a61207 348 // @test VRef expect 2.500 // Nominal Full-Scale Voltage Reference
whismanoid 6:f661c4a61207 349 // //
whismanoid 6:f661c4a61207 350 // tinyTester.err_threshold = 0.030; // 30mV
whismanoid 6:f661c4a61207 351 // @test group CODE_LOAD tinyTester.err_threshold = 0.050
whismanoid 6:f661c4a61207 352 // uint16_t code = 0x3FFF;
whismanoid 6:f661c4a61207 353 // //~ double voltageV = 0.5;
whismanoid 6:f661c4a61207 354 // //
whismanoid 6:f661c4a61207 355 // cmdLine.serial().printf("
whismanoid 6:f661c4a61207 356 // MAX5171.CODE_LOAD code=%d", code);
whismanoid 6:f661c4a61207 357 // CODE_LOAD(code);
whismanoid 6:f661c4a61207 358 // @test group CODE_LOAD tinyTester.print("100.0% of full scale REF(2.50V) = 2.50V Jumper FB=1-2")
whismanoid 6:f661c4a61207 359 // @test group CODE_LOAD CODE_LOAD(0x3FFF) // 100.0% of full scale REF(2.50V) = 2.50V
whismanoid 6:f661c4a61207 360 // // tinyTester.Wait_Output_Settling replaces wait_ms
whismanoid 6:f661c4a61207 361 // tinyTester.Wait_Output_Settling();
whismanoid 6:f661c4a61207 362 // @test group CODE_LOAD tinyTester.Wait_Output_Settling()
whismanoid 6:f661c4a61207 363 // // tinyTester.AnalogIn0_Read_Expect_voltageV replaces SelfTest_AnalogInput_Expect_ch_V
whismanoid 6:f661c4a61207 364 // tinyTester.AnalogIn0_Read_Expect_voltageV(2.500);
whismanoid 6:f661c4a61207 365 // @test group CODE_LOAD tinyTester.AnalogIn0_Read_Expect_voltageV(2.500)
whismanoid 6:f661c4a61207 366 // //
whismanoid 6:f661c4a61207 367 // code = 0x0000;
whismanoid 6:f661c4a61207 368 // cmdLine.serial().printf("
whismanoid 6:f661c4a61207 369 // MAX5171.CODE_LOAD code=%d", code);
whismanoid 6:f661c4a61207 370 // CODE_LOAD(code);
whismanoid 6:f661c4a61207 371 // @test group CODE_LOAD tinyTester.print("0.0% of full scale REF(2.50V) = 0.000V")
whismanoid 6:f661c4a61207 372 // @test group CODE_LOAD CODE_LOAD(0x0000) // 0.0% of full scale REF(2.50V) = 0.000V
whismanoid 6:f661c4a61207 373 // // tinyTester.Wait_Output_Settling replaces wait_ms
whismanoid 6:f661c4a61207 374 // tinyTester.Wait_Output_Settling();
whismanoid 6:f661c4a61207 375 // @test group CODE_LOAD tinyTester.Wait_Output_Settling()
whismanoid 6:f661c4a61207 376 // // tinyTester.AnalogIn0_Read_Expect_voltageV replaces SelfTest_AnalogInput_Expect_ch_V
whismanoid 6:f661c4a61207 377 // tinyTester.AnalogIn0_Read_Expect_voltageV(0.0000);
whismanoid 6:f661c4a61207 378 // @test group CODE_LOAD tinyTester.AnalogIn0_Read_Expect_voltageV(0.0000)
whismanoid 6:f661c4a61207 379 // //
whismanoid 6:f661c4a61207 380 // code = 0x1FFF;
whismanoid 6:f661c4a61207 381 // cmdLine.serial().printf("
whismanoid 6:f661c4a61207 382 // MAX5171.CODE_LOAD code=%d", code);
whismanoid 6:f661c4a61207 383 // CODE_LOAD(code);
whismanoid 6:f661c4a61207 384 // @test group CODE_LOAD tinyTester.print("50.0% of full scale REF(2.50V) = 1.25V")
whismanoid 6:f661c4a61207 385 // @test group CODE_LOAD CODE_LOAD(0x1FFF) // 50.0% of full scale REF(2.50V) = 1.25V
whismanoid 6:f661c4a61207 386 // // tinyTester.Wait_Output_Settling replaces wait_ms
whismanoid 6:f661c4a61207 387 // tinyTester.Wait_Output_Settling();
whismanoid 6:f661c4a61207 388 // @test group CODE_LOAD tinyTester.Wait_Output_Settling()
whismanoid 6:f661c4a61207 389 // // tinyTester.AnalogIn0_Read_Expect_voltageV replaces SelfTest_AnalogInput_Expect_ch_V
whismanoid 6:f661c4a61207 390 // tinyTester.AnalogIn0_Read_Expect_voltageV(1.2500);
whismanoid 6:f661c4a61207 391 // @test group CODE_LOAD tinyTester.AnalogIn0_Read_Expect_voltageV(1.2500)
whismanoid 6:f661c4a61207 392 // //
whismanoid 6:f661c4a61207 393 // // test UPO User Programmable Output, verify using digital input D2
whismanoid 6:f661c4a61207 394 // //
whismanoid 6:f661c4a61207 395 // @test group UPO // Verify User Programmable Output functions UPO_HIGH and UPO_LOW (enabled by default)
whismanoid 6:f661c4a61207 396 // @test group UPO tinyTester.blink_time_msec = 75 // default 75 resume hardware self test
whismanoid 6:f661c4a61207 397 // @test group UPO tinyTester.settle_time_msec = 500 // default 250
whismanoid 6:f661c4a61207 398 // cmdLine.serial().printf("
whismanoid 6:f661c4a61207 399 // MAX5171.UPO_HIGH");
whismanoid 6:f661c4a61207 400 // UPO_HIGH();
whismanoid 6:f661c4a61207 401 // @test group UPO UPO_HIGH()
whismanoid 6:f661c4a61207 402 // tinyTester.Wait_Output_Settling();
whismanoid 6:f661c4a61207 403 // @test group UPO tinyTester.Wait_Output_Settling()
whismanoid 6:f661c4a61207 404 // // tinyTester.DigitalIn_Read_Expect_WarnOnly replaces SelfTest_Expect_Input_UPO_pin
whismanoid 6:f661c4a61207 405 // tinyTester.DigitalIn_Read_Expect_WarnOnly(UPO_pin, "UPO", 1, "UPO_pin is high after MAX5171 UPO_HIGH command");
whismanoid 6:f661c4a61207 406 // @test group CODE_LOAD tinyTester.DigitalIn_Read_Expect_WarnOnly(UPO_pin, "UPO", 1, "UPO_pin is high after MAX5171 UPO_HIGH command")
whismanoid 6:f661c4a61207 407 // //
whismanoid 6:f661c4a61207 408 // cmdLine.serial().printf("
whismanoid 6:f661c4a61207 409 // MAX5171.UPO_LOW");
whismanoid 6:f661c4a61207 410 // UPO_LOW();
whismanoid 6:f661c4a61207 411 // @test group UPO UPO_LOW()
whismanoid 6:f661c4a61207 412 // tinyTester.Wait_Output_Settling();
whismanoid 6:f661c4a61207 413 // @test group UPO tinyTester.Wait_Output_Settling()
whismanoid 6:f661c4a61207 414 // // tinyTester.DigitalIn_Read_Expect_WarnOnly replaces SelfTest_Expect_Input_UPO_pin
whismanoid 6:f661c4a61207 415 // tinyTester.DigitalIn_Read_Expect_WarnOnly(UPO_pin, "UPO", 0, "UPO_pin is low after MAX5171 UPO_LOW command");
whismanoid 6:f661c4a61207 416 // @test group CODE_LOAD tinyTester.DigitalIn_Read_Expect_WarnOnly(UPO_pin, "UPO", 0, "UPO_pin is low after MAX5171 UPO_LOW command")
whismanoid 6:f661c4a61207 417 // //
whismanoid 6:f661c4a61207 418 // cmdLine.serial().printf("
whismanoid 6:f661c4a61207 419 // MAX5171.UPO_HIGH");
whismanoid 6:f661c4a61207 420 // UPO_HIGH();
whismanoid 6:f661c4a61207 421 // @test group UPO UPO_HIGH()
whismanoid 6:f661c4a61207 422 // tinyTester.Wait_Output_Settling();
whismanoid 6:f661c4a61207 423 // @test group UPO tinyTester.Wait_Output_Settling()
whismanoid 6:f661c4a61207 424 // // tinyTester.DigitalIn_Read_Expect_WarnOnly replaces SelfTest_Expect_Input_UPO_pin
whismanoid 6:f661c4a61207 425 // tinyTester.DigitalIn_Read_Expect_WarnOnly(UPO_pin, "UPO", 1, "UPO_pin is high after MAX5171 UPO_HIGH command");
whismanoid 6:f661c4a61207 426 // @test group CODE_LOAD tinyTester.DigitalIn_Read_Expect_WarnOnly(UPO_pin, "UPO", 1, "UPO_pin is high after MAX5171 UPO_HIGH command")
whismanoid 6:f661c4a61207 427 // //
whismanoid 6:f661c4a61207 428 //
whismanoid 6:f661c4a61207 429 //
whismanoid 6:f661c4a61207 430 void MAX5171::Init(void)
whismanoid 1:e73245718b2a 431 {
whismanoid 3:79839617d532 432
whismanoid 3:79839617d532 433 //----------------------------------------
whismanoid 3:79839617d532 434 // Nominal Full-Scale Voltage Reference
whismanoid 3:79839617d532 435 VRef = 2.500;
whismanoid 1:e73245718b2a 436 }
whismanoid 1:e73245718b2a 437
whismanoid 1:e73245718b2a 438 //----------------------------------------
whismanoid 1:e73245718b2a 439 // Return the DAC register value corresponding to physical voltage.
whismanoid 1:e73245718b2a 440 // Does not perform any offset or gain correction.
whismanoid 1:e73245718b2a 441 //
whismanoid 1:e73245718b2a 442 // @pre VRef = Voltage of REF input, in Volts
whismanoid 1:e73245718b2a 443 // @param[in] voltage = physical voltage in Volts
whismanoid 1:e73245718b2a 444 // @return raw 14-bit MAX5171 code (right justified).
whismanoid 1:e73245718b2a 445 uint16_t MAX5171::DACCodeOfVoltage(double voltageV)
whismanoid 1:e73245718b2a 446 {
whismanoid 3:79839617d532 447
whismanoid 1:e73245718b2a 448 //----------------------------------------
whismanoid 1:e73245718b2a 449 // Linear map min and max endpoints
whismanoid 1:e73245718b2a 450 const double MaxScaleVoltage = VRef; // voltage of maximum code 0x3fff
whismanoid 1:e73245718b2a 451 const double MinScaleVoltage = 0.0; // voltage of minimum code 0x000
whismanoid 1:e73245718b2a 452 const uint16_t FULL_SCALE_CODE_14BIT = 0x3fff;
whismanoid 1:e73245718b2a 453 const uint16_t MaxCode = FULL_SCALE_CODE_14BIT;
whismanoid 1:e73245718b2a 454 const uint16_t MinCode = 0x000;
whismanoid 1:e73245718b2a 455 double codeFraction = (voltageV - MinScaleVoltage) / (MaxScaleVoltage - MinScaleVoltage);
whismanoid 1:e73245718b2a 456 double dacRegValueIdeal = ((codeFraction * (double)(MaxCode - MinCode + 1)) + MinCode + 0.5);
whismanoid 1:e73245718b2a 457 uint16_t dacRegValue = (uint16_t)dacRegValueIdeal;
whismanoid 3:79839617d532 458 if (dacRegValueIdeal > MaxCode)
whismanoid 3:79839617d532 459 {
whismanoid 1:e73245718b2a 460 dacRegValue = MaxCode;
whismanoid 3:79839617d532 461 } else if (dacRegValueIdeal < MinCode)
whismanoid 3:79839617d532 462 {
whismanoid 1:e73245718b2a 463 dacRegValue = MinCode;
whismanoid 1:e73245718b2a 464 }
whismanoid 1:e73245718b2a 465 return dacRegValue;
whismanoid 1:e73245718b2a 466 }
whismanoid 1:e73245718b2a 467
whismanoid 1:e73245718b2a 468 //----------------------------------------
whismanoid 1:e73245718b2a 469 // Return the physical voltage corresponding to DAC register.
whismanoid 1:e73245718b2a 470 // Does not perform any offset or gain correction.
whismanoid 1:e73245718b2a 471 //
whismanoid 1:e73245718b2a 472 // @pre VRef = Voltage of REF input, in Volts
whismanoid 1:e73245718b2a 473 // @param[in] value_u14: raw 14-bit MAX5171 code (right justified).
whismanoid 1:e73245718b2a 474 // @return physical voltage corresponding to MAX5171 code.
whismanoid 1:e73245718b2a 475 double MAX5171::VoltageOfCode(uint16_t value_u14)
whismanoid 1:e73245718b2a 476 {
whismanoid 3:79839617d532 477
whismanoid 1:e73245718b2a 478 //----------------------------------------
whismanoid 1:e73245718b2a 479 // Linear map min and max endpoints
whismanoid 1:e73245718b2a 480 double MaxScaleVoltage = VRef; // voltage of maximum code 0x3fff
whismanoid 1:e73245718b2a 481 double MinScaleVoltage = 0.0; // voltage of minimum code 0x000
whismanoid 1:e73245718b2a 482 const uint16_t FULL_SCALE_CODE_14BIT = 0x3fff;
whismanoid 1:e73245718b2a 483 const uint16_t MaxCode = FULL_SCALE_CODE_14BIT;
whismanoid 1:e73245718b2a 484 const uint16_t MinCode = 0x000;
whismanoid 1:e73245718b2a 485 double codeFraction = ((double)value_u14 - MinCode) / (MaxCode - MinCode + 1);
whismanoid 1:e73245718b2a 486 return MinScaleVoltage + ((MaxScaleVoltage - MinScaleVoltage) * codeFraction);
whismanoid 1:e73245718b2a 487 }
whismanoid 1:e73245718b2a 488
whismanoid 1:e73245718b2a 489 //----------------------------------------
whismanoid 1:e73245718b2a 490 // CMD_00dd_dddd_dddd_dddd_CODE
whismanoid 1:e73245718b2a 491 //
whismanoid 1:e73245718b2a 492 // Load input register; DAC registers are unchanged.
whismanoid 1:e73245718b2a 493 // @return 1 on success; 0 on failure
whismanoid 1:e73245718b2a 494 uint8_t MAX5171::CODE(uint16_t dacCodeLsbs)
whismanoid 1:e73245718b2a 495 {
whismanoid 3:79839617d532 496
whismanoid 1:e73245718b2a 497 //----------------------------------------
whismanoid 1:e73245718b2a 498 // Define command code
whismanoid 1:e73245718b2a 499 uint16_t mosiData16 = CMD_00dd_dddd_dddd_dddd_CODE
whismanoid 3:79839617d532 500 | ((0x3FFF & dacCodeLsbs) << 0); // left-align dddd_dddd_dddd
whismanoid 3:79839617d532 501
whismanoid 1:e73245718b2a 502 //----------------------------------------
whismanoid 1:e73245718b2a 503 // SPI write 16-bit mosiData16
whismanoid 1:e73245718b2a 504 SPIoutputCS(0);
whismanoid 1:e73245718b2a 505 SPIwrite16bits(mosiData16);
whismanoid 1:e73245718b2a 506 SPIoutputCS(1);
whismanoid 3:79839617d532 507
whismanoid 1:e73245718b2a 508 //----------------------------------------
whismanoid 1:e73245718b2a 509 // shadow of write-only register CMD_00dd_dddd_dddd_dddd_CODE
whismanoid 1:e73245718b2a 510 DACCode = dacCodeLsbs;
whismanoid 3:79839617d532 511
whismanoid 1:e73245718b2a 512 //----------------------------------------
whismanoid 1:e73245718b2a 513 // success
whismanoid 1:e73245718b2a 514 return 1;
whismanoid 1:e73245718b2a 515 }
whismanoid 1:e73245718b2a 516
whismanoid 1:e73245718b2a 517 //----------------------------------------
whismanoid 1:e73245718b2a 518 // CMD_01dd_dddd_dddd_dddd_CODE_LOAD
whismanoid 1:e73245718b2a 519 //
whismanoid 1:e73245718b2a 520 // Load input register; DAC registers are updated (start up DAC with new data).
whismanoid 1:e73245718b2a 521 // @return 1 on success; 0 on failure
whismanoid 1:e73245718b2a 522 uint8_t MAX5171::CODE_LOAD(uint16_t dacCodeLsbs)
whismanoid 1:e73245718b2a 523 {
whismanoid 3:79839617d532 524
whismanoid 1:e73245718b2a 525 //----------------------------------------
whismanoid 1:e73245718b2a 526 // Define command code
whismanoid 1:e73245718b2a 527 uint16_t mosiData16 = CMD_01dd_dddd_dddd_dddd_CODE_LOAD
whismanoid 3:79839617d532 528 | ((0x3FFF & dacCodeLsbs) << 0); // left-align dddd_dddd_dddd
whismanoid 3:79839617d532 529
whismanoid 1:e73245718b2a 530 //----------------------------------------
whismanoid 1:e73245718b2a 531 // SPI write 16-bit mosiData16
whismanoid 1:e73245718b2a 532 SPIoutputCS(0);
whismanoid 1:e73245718b2a 533 SPIwrite16bits(mosiData16);
whismanoid 1:e73245718b2a 534 SPIoutputCS(1);
whismanoid 3:79839617d532 535
whismanoid 1:e73245718b2a 536 //----------------------------------------
whismanoid 1:e73245718b2a 537 // shadow of write-only register CMD_00dd_dddd_dddd_dddd_CODE
whismanoid 1:e73245718b2a 538 DACCode = dacCodeLsbs;
whismanoid 3:79839617d532 539
whismanoid 1:e73245718b2a 540 //----------------------------------------
whismanoid 1:e73245718b2a 541 // success
whismanoid 1:e73245718b2a 542 return 1;
whismanoid 1:e73245718b2a 543 }
whismanoid 1:e73245718b2a 544
whismanoid 1:e73245718b2a 545 //----------------------------------------
whismanoid 1:e73245718b2a 546 // CMD_10xx_xxxx_xxxx_xxxx_LOAD
whismanoid 1:e73245718b2a 547 //
whismanoid 1:e73245718b2a 548 // Update DAC register from input register (start up DAC with data previously
whismanoid 1:e73245718b2a 549 // stored in the input registers).
whismanoid 1:e73245718b2a 550 // @return 1 on success; 0 on failure
whismanoid 1:e73245718b2a 551 uint8_t MAX5171::LOAD(void)
whismanoid 1:e73245718b2a 552 {
whismanoid 3:79839617d532 553
whismanoid 1:e73245718b2a 554 //----------------------------------------
whismanoid 1:e73245718b2a 555 // Define command code
whismanoid 1:e73245718b2a 556 uint16_t mosiData16 = CMD_10xx_xxxx_xxxx_xxxx_LOAD;
whismanoid 3:79839617d532 557
whismanoid 1:e73245718b2a 558 //----------------------------------------
whismanoid 1:e73245718b2a 559 // SPI write 16-bit mosiData16
whismanoid 1:e73245718b2a 560 SPIoutputCS(0);
whismanoid 1:e73245718b2a 561 SPIwrite16bits(mosiData16);
whismanoid 1:e73245718b2a 562 SPIoutputCS(1);
whismanoid 3:79839617d532 563
whismanoid 1:e73245718b2a 564 //----------------------------------------
whismanoid 1:e73245718b2a 565 // success
whismanoid 1:e73245718b2a 566 return 1;
whismanoid 1:e73245718b2a 567 }
whismanoid 1:e73245718b2a 568
whismanoid 1:e73245718b2a 569 //----------------------------------------
whismanoid 1:e73245718b2a 570 // CMD_1100_xxxx_xxxx_xxxx_NOP
whismanoid 1:e73245718b2a 571 //
whismanoid 1:e73245718b2a 572 // No operation (NOP).
whismanoid 1:e73245718b2a 573 // @return 1 on success; 0 on failure
whismanoid 1:e73245718b2a 574 uint8_t MAX5171::NOP(void)
whismanoid 1:e73245718b2a 575 {
whismanoid 3:79839617d532 576
whismanoid 1:e73245718b2a 577 //----------------------------------------
whismanoid 1:e73245718b2a 578 // Define command code
whismanoid 1:e73245718b2a 579 uint16_t mosiData16 = CMD_1100_xxxx_xxxx_xxxx_NOP;
whismanoid 3:79839617d532 580
whismanoid 1:e73245718b2a 581 //----------------------------------------
whismanoid 1:e73245718b2a 582 // SPI write 16-bit mosiData16
whismanoid 1:e73245718b2a 583 SPIoutputCS(0);
whismanoid 1:e73245718b2a 584 SPIwrite16bits(mosiData16);
whismanoid 1:e73245718b2a 585 SPIoutputCS(1);
whismanoid 3:79839617d532 586
whismanoid 1:e73245718b2a 587 //----------------------------------------
whismanoid 1:e73245718b2a 588 // success
whismanoid 1:e73245718b2a 589 return 1;
whismanoid 1:e73245718b2a 590 }
whismanoid 1:e73245718b2a 591
whismanoid 1:e73245718b2a 592 //----------------------------------------
whismanoid 1:e73245718b2a 593 // CMD_1101_xxxx_xxxx_xxxx_SHUTDOWN
whismanoid 1:e73245718b2a 594 //
whismanoid 1:e73245718b2a 595 // Shut down DAC (provided PDL# = 1).
whismanoid 1:e73245718b2a 596 // @return 1 on success; 0 on failure
whismanoid 1:e73245718b2a 597 uint8_t MAX5171::SHUTDOWN(void)
whismanoid 1:e73245718b2a 598 {
whismanoid 3:79839617d532 599
whismanoid 1:e73245718b2a 600 //----------------------------------------
whismanoid 1:e73245718b2a 601 // Define command code
whismanoid 1:e73245718b2a 602 uint16_t mosiData16 = CMD_1101_xxxx_xxxx_xxxx_SHUTDOWN;
whismanoid 3:79839617d532 603
whismanoid 1:e73245718b2a 604 //----------------------------------------
whismanoid 1:e73245718b2a 605 // SPI write 16-bit mosiData16
whismanoid 1:e73245718b2a 606 SPIoutputCS(0);
whismanoid 1:e73245718b2a 607 SPIwrite16bits(mosiData16);
whismanoid 1:e73245718b2a 608 SPIoutputCS(1);
whismanoid 3:79839617d532 609
whismanoid 1:e73245718b2a 610 //----------------------------------------
whismanoid 1:e73245718b2a 611 // success
whismanoid 1:e73245718b2a 612 return 1;
whismanoid 1:e73245718b2a 613 }
whismanoid 1:e73245718b2a 614
whismanoid 1:e73245718b2a 615 //----------------------------------------
whismanoid 1:e73245718b2a 616 // CMD_1110_0xxx_xxxx_xxxx_UPO_LOW
whismanoid 1:e73245718b2a 617 //
whismanoid 1:e73245718b2a 618 // UPO goes low (default).
whismanoid 1:e73245718b2a 619 // @return 1 on success; 0 on failure
whismanoid 1:e73245718b2a 620 uint8_t MAX5171::UPO_LOW(void)
whismanoid 1:e73245718b2a 621 {
whismanoid 3:79839617d532 622
whismanoid 1:e73245718b2a 623 //----------------------------------------
whismanoid 1:e73245718b2a 624 // Define command code
whismanoid 1:e73245718b2a 625 uint16_t mosiData16 = CMD_1110_0xxx_xxxx_xxxx_UPO_LOW;
whismanoid 3:79839617d532 626
whismanoid 1:e73245718b2a 627 //----------------------------------------
whismanoid 1:e73245718b2a 628 // SPI write 16-bit mosiData16
whismanoid 1:e73245718b2a 629 SPIoutputCS(0);
whismanoid 1:e73245718b2a 630 SPIwrite16bits(mosiData16);
whismanoid 1:e73245718b2a 631 SPIoutputCS(1);
whismanoid 3:79839617d532 632
whismanoid 1:e73245718b2a 633 //----------------------------------------
whismanoid 1:e73245718b2a 634 // success
whismanoid 1:e73245718b2a 635 return 1;
whismanoid 1:e73245718b2a 636 }
whismanoid 1:e73245718b2a 637
whismanoid 1:e73245718b2a 638 //----------------------------------------
whismanoid 1:e73245718b2a 639 // CMD_1110_1xxx_xxxx_xxxx_UPO_HIGH
whismanoid 1:e73245718b2a 640 //
whismanoid 1:e73245718b2a 641 // UPO goes high.
whismanoid 1:e73245718b2a 642 // @return 1 on success; 0 on failure
whismanoid 1:e73245718b2a 643 uint8_t MAX5171::UPO_HIGH(void)
whismanoid 1:e73245718b2a 644 {
whismanoid 3:79839617d532 645
whismanoid 1:e73245718b2a 646 //----------------------------------------
whismanoid 1:e73245718b2a 647 // Define command code
whismanoid 1:e73245718b2a 648 uint16_t mosiData16 = CMD_1110_1xxx_xxxx_xxxx_UPO_HIGH;
whismanoid 3:79839617d532 649
whismanoid 1:e73245718b2a 650 //----------------------------------------
whismanoid 1:e73245718b2a 651 // SPI write 16-bit mosiData16
whismanoid 1:e73245718b2a 652 SPIoutputCS(0);
whismanoid 1:e73245718b2a 653 SPIwrite16bits(mosiData16);
whismanoid 1:e73245718b2a 654 SPIoutputCS(1);
whismanoid 3:79839617d532 655
whismanoid 1:e73245718b2a 656 //----------------------------------------
whismanoid 1:e73245718b2a 657 // success
whismanoid 1:e73245718b2a 658 return 1;
whismanoid 1:e73245718b2a 659 }
whismanoid 1:e73245718b2a 660
whismanoid 1:e73245718b2a 661 //----------------------------------------
whismanoid 1:e73245718b2a 662 // CMD_1111_0xxx_xxxx_xxxx_MODE1_DOUT_SCLK_RISING_EDGE
whismanoid 1:e73245718b2a 663 //
whismanoid 5:e8c0dfaeb53b 664 // Mode 1, DOUT clocked out on SCLK's rising edge.
whismanoid 1:e73245718b2a 665 // @return 1 on success; 0 on failure
whismanoid 1:e73245718b2a 666 uint8_t MAX5171::MODE1_DOUT_SCLK_RISING_EDGE(void)
whismanoid 1:e73245718b2a 667 {
whismanoid 3:79839617d532 668
whismanoid 1:e73245718b2a 669 //----------------------------------------
whismanoid 1:e73245718b2a 670 // Define command code
whismanoid 1:e73245718b2a 671 uint16_t mosiData16 = CMD_1111_0xxx_xxxx_xxxx_MODE1_DOUT_SCLK_RISING_EDGE;
whismanoid 3:79839617d532 672
whismanoid 1:e73245718b2a 673 //----------------------------------------
whismanoid 1:e73245718b2a 674 // SPI write 16-bit mosiData16
whismanoid 1:e73245718b2a 675 SPIoutputCS(0);
whismanoid 1:e73245718b2a 676 SPIwrite16bits(mosiData16);
whismanoid 1:e73245718b2a 677 SPIoutputCS(1);
whismanoid 3:79839617d532 678
whismanoid 1:e73245718b2a 679 //----------------------------------------
whismanoid 1:e73245718b2a 680 // success
whismanoid 1:e73245718b2a 681 return 1;
whismanoid 1:e73245718b2a 682 }
whismanoid 1:e73245718b2a 683
whismanoid 1:e73245718b2a 684 //----------------------------------------
whismanoid 1:e73245718b2a 685 // CMD_1111_1xxx_xxxx_xxxx_MODE0_DOUT_SCLK_FALLING_EDGE
whismanoid 1:e73245718b2a 686 //
whismanoid 4:1984eef51fe3 687 // Mode 0, DOUT clocked out on SCLK's falling edge (default).
whismanoid 1:e73245718b2a 688 // @return 1 on success; 0 on failure
whismanoid 1:e73245718b2a 689 uint8_t MAX5171::MODE0_DOUT_SCLK_FALLING_EDGE(void)
whismanoid 1:e73245718b2a 690 {
whismanoid 3:79839617d532 691
whismanoid 1:e73245718b2a 692 //----------------------------------------
whismanoid 1:e73245718b2a 693 // Define command code
whismanoid 1:e73245718b2a 694 uint16_t mosiData16 = CMD_1111_1xxx_xxxx_xxxx_MODE0_DOUT_SCLK_FALLING_EDGE;
whismanoid 3:79839617d532 695
whismanoid 1:e73245718b2a 696 //----------------------------------------
whismanoid 1:e73245718b2a 697 // SPI write 16-bit mosiData16
whismanoid 1:e73245718b2a 698 SPIoutputCS(0);
whismanoid 1:e73245718b2a 699 SPIwrite16bits(mosiData16);
whismanoid 1:e73245718b2a 700 SPIoutputCS(1);
whismanoid 3:79839617d532 701
whismanoid 1:e73245718b2a 702 //----------------------------------------
whismanoid 1:e73245718b2a 703 // success
whismanoid 1:e73245718b2a 704 return 1;
whismanoid 1:e73245718b2a 705 }
whismanoid 1:e73245718b2a 706
whismanoid 1:e73245718b2a 707
whismanoid 1:e73245718b2a 708 // End of file