Example host software code for the Maxim Integrated MAX5216/MAX5214 16-bit/14-bit SPI bus DAC. Hosted on the MAX32630FTHR FeatherWing micro-controller board.

Dependencies:   MAX5216_16_Bit_DAC_SPI_Bus_Driver USBDevice max32630fthr

Committer:
phonemacro
Date:
Thu Sep 06 21:24:17 2018 +0000
Revision:
3:601454551d3a
Parent:
2:5f8cd1facd15
Updated method names to comply with Mbed coding standard

Who changed what in which revision?

UserRevisionLine numberNew contents of line
phonemacro 0:64aee6498091 1 /*******************************************************************************
phonemacro 0:64aee6498091 2 * Copyright (C) 2018 Maxim Integrated Products, Inc., All Rights Reserved.
phonemacro 0:64aee6498091 3 *
phonemacro 0:64aee6498091 4 * Permission is hereby granted, free of charge, to any person obtaining a
phonemacro 0:64aee6498091 5 * copy of this software and associated documentation files (the "Software"),
phonemacro 0:64aee6498091 6 * to deal in the Software without restriction, including without limitation
phonemacro 0:64aee6498091 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
phonemacro 0:64aee6498091 8 * and/or sell copies of the Software, and to permit persons to whom the
phonemacro 0:64aee6498091 9 * Software is furnished to do so, subject to the following conditions:
phonemacro 0:64aee6498091 10 *
phonemacro 0:64aee6498091 11 * The above copyright notice and this permission notice shall be included
phonemacro 0:64aee6498091 12 * in all copies or substantial portions of the Software.
phonemacro 0:64aee6498091 13 *
phonemacro 0:64aee6498091 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
phonemacro 0:64aee6498091 15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
phonemacro 0:64aee6498091 16 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
phonemacro 0:64aee6498091 17 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
phonemacro 0:64aee6498091 18 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
phonemacro 0:64aee6498091 19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
phonemacro 0:64aee6498091 20 * OTHER DEALINGS IN THE SOFTWARE.
phonemacro 0:64aee6498091 21 *
phonemacro 0:64aee6498091 22 * Except as contained in this notice, the name of Maxim Integrated
phonemacro 0:64aee6498091 23 * Products, Inc. shall not be used except as stated in the Maxim Integrated
phonemacro 0:64aee6498091 24 * Products, Inc. Branding Policy.
phonemacro 0:64aee6498091 25 *
phonemacro 0:64aee6498091 26 * The mere transfer of this software does not imply any licenses
phonemacro 0:64aee6498091 27 * of trade secrets, proprietary technology, copyrights, patents,
phonemacro 0:64aee6498091 28 * trademarks, maskwork rights, or any other form of intellectual
phonemacro 0:64aee6498091 29 * property whatsoever. Maxim Integrated Products, Inc. retains all
phonemacro 0:64aee6498091 30 * ownership rights.
phonemacro 0:64aee6498091 31 *******************************************************************************
phonemacro 0:64aee6498091 32 */
phonemacro 0:64aee6498091 33 #include "mbed.h"
phonemacro 0:64aee6498091 34 #include "max32630fthr.h"
phonemacro 0:64aee6498091 35 #include "MAX5216.h"
phonemacro 0:64aee6498091 36 #include "USBSerial.h"
phonemacro 2:5f8cd1facd15 37
phonemacro 0:64aee6498091 38 MAX32630FTHR pegasus(MAX32630FTHR::VIO_3V3);
phonemacro 2:5f8cd1facd15 39
phonemacro 0:64aee6498091 40 DigitalOut rLED(LED1);
phonemacro 0:64aee6498091 41 DigitalOut gLED(LED2);
phonemacro 0:64aee6498091 42 DigitalOut bLED(LED3);
phonemacro 2:5f8cd1facd15 43
phonemacro 0:64aee6498091 44 DigitalOut selectPin(P3_0); // Pin 3_0 is used to drive chip enable low
phonemacro 0:64aee6498091 45 SPI spi(P5_1, P5_2, P5_0); // mosi, miso, sclk
phonemacro 2:5f8cd1facd15 46
phonemacro 0:64aee6498091 47 // main() runs in its own thread in the OS
phonemacro 0:64aee6498091 48 // (note the calls to Thread::wait below for delays)
phonemacro 0:64aee6498091 49 /**
phonemacro 0:64aee6498091 50 * @brief Sample main program for MAX5214, MAX5216
phonemacro 1:fe0cd2999f95 51 * @version 1.0000.1
phonemacro 0:64aee6498091 52 *
phonemacro 2:5f8cd1facd15 53 * @details Sample main program for MAX5214, MAX5216
phonemacro 0:64aee6498091 54 * The prints are sent to the terminal window (9600, 8n1).
phonemacro 1:fe0cd2999f95 55 * The program sets the GPIOs to 3.3V and the program
phonemacro 1:fe0cd2999f95 56 * issues various voltages to the DAC. Then the program
phonemacro 1:fe0cd2999f95 57 * issues a Power Down Command.
phonemacro 0:64aee6498091 58 * To run the program, drag and drop the .bin file into the
phonemacro 0:64aee6498091 59 * DAPLINK folder. After it finishes flashing, cycle the power or
phonemacro 1:fe0cd2999f95 60 * reset the Pegasus (MAX32630FTHR) after flashing by pressing the button on
phonemacro 0:64aee6498091 61 * the Pegasus next to the battery connector or the button
phonemacro 0:64aee6498091 62 * on the MAXREFDES100HDK.
phonemacro 0:64aee6498091 63 */
phonemacro 0:64aee6498091 64 int main()
phonemacro 0:64aee6498091 65 {
phonemacro 0:64aee6498091 66 DigitalOut rLED(LED1, LED_OFF);
phonemacro 0:64aee6498091 67 DigitalOut gLED(LED2, LED_OFF);
phonemacro 0:64aee6498091 68 DigitalOut bLED(LED3, LED_OFF);
phonemacro 0:64aee6498091 69 gLED = LED_ON;
phonemacro 0:64aee6498091 70 printf("MAX5216 16-bit DAC example source code.\r\n");
phonemacro 0:64aee6498091 71 MAX5216 dac(spi, selectPin, MAX5216::MAX5216_IC);
phonemacro 0:64aee6498091 72
phonemacro 0:64aee6498091 73 spi.format(8,0);
phonemacro 1:fe0cd2999f95 74 spi.frequency(24000000); // Use 24 MHz SPI bus
phonemacro 0:64aee6498091 75
phonemacro 1:fe0cd2999f95 76 // Command values to the DAC
phonemacro 3:601454551d3a 77 dac.write_command(MAX5216::WrtThru_Reg, 0xFFFF);
phonemacro 0:64aee6498091 78 wait(1.0);
phonemacro 0:64aee6498091 79 gLED = LED_OFF;
phonemacro 3:601454551d3a 80 dac.write_command(MAX5216::WrtThru_Reg, 0x7FFF);
phonemacro 0:64aee6498091 81 wait(1.0);
phonemacro 0:64aee6498091 82 gLED = LED_ON;
phonemacro 3:601454551d3a 83 dac.write_command(MAX5216::WrtThru_Reg, 0x3FFF);
phonemacro 0:64aee6498091 84 wait(1.0);
phonemacro 0:64aee6498091 85 gLED = LED_OFF;
phonemacro 3:601454551d3a 86 dac.write_command(MAX5216::WrtThru_Reg, 0x1FFF);
phonemacro 0:64aee6498091 87 wait(1.0);
phonemacro 1:fe0cd2999f95 88 rLED = LED_ON;
phonemacro 1:fe0cd2999f95 89 gLED = LED_ON;
phonemacro 2:5f8cd1facd15 90
phonemacro 1:fe0cd2999f95 91 // Issue Power Down Commands
phonemacro 3:601454551d3a 92 // dac.write_command(MAX5216::PwrDwn_Reg, MAX5216::PwrDwnNormalOp);
phonemacro 3:601454551d3a 93 dac.write_command(MAX5216::PwrDwn_Reg, MAX5216::PwrDwnHiZ);
phonemacro 3:601454551d3a 94 // dac.write_command(MAX5216::PwrDwn_Reg, MAX5216::PwrDwn100K);
phonemacro 3:601454551d3a 95 // dac.write_command(MAX5216::PwrDwn_Reg, MAX5216::PwrDwn1K);
phonemacro 0:64aee6498091 96 wait(2.0);
phonemacro 1:fe0cd2999f95 97 rLED = LED_OFF;
phonemacro 2:5f8cd1facd15 98
phonemacro 0:64aee6498091 99 while (true) { // Blink the green LED
phonemacro 0:64aee6498091 100 gLED = !gLED;
phonemacro 0:64aee6498091 101 wait(0.5);
phonemacro 0:64aee6498091 102 }
phonemacro 0:64aee6498091 103 }
phonemacro 2:5f8cd1facd15 104
phonemacro 2:5f8cd1facd15 105