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:
Sun Aug 12 10:18:22 2018 +0000
Revision:
0:64aee6498091
Child:
1:fe0cd2999f95
Initial commit for an example main source code for the MAX5216 spi bus DAC hosted on the MAX32630FTHR Pegasus microcontroller board.

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 0:64aee6498091 37
phonemacro 0:64aee6498091 38 MAX32630FTHR pegasus(MAX32630FTHR::VIO_3V3);
phonemacro 0:64aee6498091 39
phonemacro 0:64aee6498091 40 DigitalOut rLED(LED1);
phonemacro 0:64aee6498091 41 DigitalOut gLED(LED2);
phonemacro 0:64aee6498091 42 DigitalOut bLED(LED3);
phonemacro 0:64aee6498091 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 0:64aee6498091 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 0:64aee6498091 51 * @version 1.0000.0
phonemacro 0:64aee6498091 52 *
phonemacro 0:64aee6498091 53 * @details Sample main program for MAX30101.
phonemacro 0:64aee6498091 54 * The prints are sent to the terminal window (9600, 8n1).
phonemacro 0:64aee6498091 55 * The program sets the GPIOs to 1.8V and the program
phonemacro 0:64aee6498091 56 * blinks green if it's able to communicate with
phonemacro 0:64aee6498091 57 * the MAX30101, otherwise, it blinks red.
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 0:64aee6498091 60 * reset the Pegasus 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 0:64aee6498091 74 spi.frequency(1000000);
phonemacro 0:64aee6498091 75
phonemacro 0:64aee6498091 76 // Write a command
phonemacro 0:64aee6498091 77 dac.writeCommand(MAX5216::WrtThru_Reg, 0xFFFF);
phonemacro 0:64aee6498091 78 wait(1.0);
phonemacro 0:64aee6498091 79 gLED = LED_OFF;
phonemacro 0:64aee6498091 80 dac.writeCommand(MAX5216::WrtThru_Reg, 0x7FFF);
phonemacro 0:64aee6498091 81 wait(1.0);
phonemacro 0:64aee6498091 82 gLED = LED_ON;
phonemacro 0:64aee6498091 83 dac.writeCommand(MAX5216::WrtThru_Reg, 0x3FFF);
phonemacro 0:64aee6498091 84 wait(1.0);
phonemacro 0:64aee6498091 85 gLED = LED_OFF;
phonemacro 0:64aee6498091 86 dac.writeCommand(MAX5216::WrtThru_Reg, 0x1FFF);
phonemacro 0:64aee6498091 87 wait(1.0);
phonemacro 0:64aee6498091 88 bLED = LED_ON;
phonemacro 0:64aee6498091 89 dac.writeCommand(MAX5216::NoOp_Reg, 0xFFFF);
phonemacro 0:64aee6498091 90 wait(2.0);
phonemacro 0:64aee6498091 91 bLED = LED_OFF;
phonemacro 0:64aee6498091 92
phonemacro 0:64aee6498091 93 while (true) { // Blink the green LED
phonemacro 0:64aee6498091 94 gLED = !gLED;
phonemacro 0:64aee6498091 95 wait(0.5);
phonemacro 0:64aee6498091 96 }
phonemacro 0:64aee6498091 97 }