Example host software for the Maxim Integrated MAX5171 14-bit Force/Sense DAC. Hosted on the MAX32625MBED.

Dependencies:   MAX5171

Committer:
whismanoid
Date:
Wed Oct 30 15:46:01 2019 -0700
Revision:
3:80bae2311ddb
Parent:
1:8f712114baf7
update docs, remove diagnostic comments, fix utf8 encoding

Who changed what in which revision?

UserRevisionLine numberNew contents of line
whismanoid 0:5da566e61083 1 // /*******************************************************************************
whismanoid 0:5da566e61083 2 // * Copyright (C) 2019 Maxim Integrated Products, Inc., All Rights Reserved.
whismanoid 0:5da566e61083 3 // *
whismanoid 0:5da566e61083 4 // * Permission is hereby granted, free of charge, to any person obtaining a
whismanoid 0:5da566e61083 5 // * copy of this software and associated documentation files (the "Software"),
whismanoid 0:5da566e61083 6 // * to deal in the Software without restriction, including without limitation
whismanoid 0:5da566e61083 7 // * the rights to use, copy, modify, merge, publish, distribute, sublicense,
whismanoid 0:5da566e61083 8 // * and/or sell copies of the Software, and to permit persons to whom the
whismanoid 0:5da566e61083 9 // * Software is furnished to do so, subject to the following conditions:
whismanoid 0:5da566e61083 10 // *
whismanoid 0:5da566e61083 11 // * The above copyright notice and this permission notice shall be included
whismanoid 0:5da566e61083 12 // * in all copies or substantial portions of the Software.
whismanoid 0:5da566e61083 13 // *
whismanoid 0:5da566e61083 14 // * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
whismanoid 0:5da566e61083 15 // * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
whismanoid 0:5da566e61083 16 // * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
whismanoid 0:5da566e61083 17 // * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
whismanoid 0:5da566e61083 18 // * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
whismanoid 0:5da566e61083 19 // * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
whismanoid 0:5da566e61083 20 // * OTHER DEALINGS IN THE SOFTWARE.
whismanoid 0:5da566e61083 21 // *
whismanoid 0:5da566e61083 22 // * Except as contained in this notice, the name of Maxim Integrated
whismanoid 0:5da566e61083 23 // * Products, Inc. shall not be used except as stated in the Maxim Integrated
whismanoid 0:5da566e61083 24 // * Products, Inc. Branding Policy.
whismanoid 0:5da566e61083 25 // *
whismanoid 0:5da566e61083 26 // * The mere transfer of this software does not imply any licenses
whismanoid 0:5da566e61083 27 // * of trade secrets, proprietary technology, copyrights, patents,
whismanoid 0:5da566e61083 28 // * trademarks, maskwork rights, or any other form of intellectual
whismanoid 0:5da566e61083 29 // * property whatsoever. Maxim Integrated Products, Inc. retains all
whismanoid 0:5da566e61083 30 // * ownership rights.
whismanoid 0:5da566e61083 31 // *******************************************************************************
whismanoid 0:5da566e61083 32 // */
whismanoid 0:5da566e61083 33 // example code includes
whismanoid 3:80bae2311ddb 34 // standard include for target platform -- Platform_Include_Boilerplate
whismanoid 0:5da566e61083 35 #include "mbed.h"
whismanoid 3:80bae2311ddb 36 // Platforms:
whismanoid 3:80bae2311ddb 37 // - MAX32625MBED
whismanoid 3:80bae2311ddb 38 // - supports mbed-os-5.11, requires USBDevice library
whismanoid 3:80bae2311ddb 39 // - add https://developer.mbed.org/teams/MaximIntegrated/code/USBDevice/
whismanoid 3:80bae2311ddb 40 // - remove max32630fthr library (if present)
whismanoid 3:80bae2311ddb 41 // - remove MAX32620FTHR library (if present)
whismanoid 3:80bae2311ddb 42 // - MAX32600MBED
whismanoid 3:80bae2311ddb 43 // - remove max32630fthr library (if present)
whismanoid 3:80bae2311ddb 44 // - remove MAX32620FTHR library (if present)
whismanoid 3:80bae2311ddb 45 // - Windows 10 note: Don't connect HDK until you are ready to load new firmware into the board.
whismanoid 3:80bae2311ddb 46 // - NUCLEO_F446RE
whismanoid 3:80bae2311ddb 47 // - remove USBDevice library
whismanoid 3:80bae2311ddb 48 // - remove max32630fthr library (if present)
whismanoid 3:80bae2311ddb 49 // - remove MAX32620FTHR library (if present)
whismanoid 3:80bae2311ddb 50 // - NUCLEO_F401RE
whismanoid 3:80bae2311ddb 51 // - remove USBDevice library
whismanoid 3:80bae2311ddb 52 // - remove max32630fthr library (if present)
whismanoid 3:80bae2311ddb 53 // - remove MAX32620FTHR library (if present)
whismanoid 3:80bae2311ddb 54 // - MAX32630FTHR
whismanoid 3:80bae2311ddb 55 // - #include "max32630fthr.h"
whismanoid 3:80bae2311ddb 56 // - add http://os.mbed.org/teams/MaximIntegrated/code/max32630fthr/
whismanoid 3:80bae2311ddb 57 // - remove MAX32620FTHR library (if present)
whismanoid 3:80bae2311ddb 58 // - MAX32620FTHR
whismanoid 3:80bae2311ddb 59 // - #include "MAX32620FTHR.h"
whismanoid 3:80bae2311ddb 60 // - remove max32630fthr library (if present)
whismanoid 3:80bae2311ddb 61 // - add https://os.mbed.com/teams/MaximIntegrated/code/MAX32620FTHR/
whismanoid 3:80bae2311ddb 62 // - not tested yet
whismanoid 3:80bae2311ddb 63 // - MAX32625PICO
whismanoid 3:80bae2311ddb 64 // - remove max32630fthr library (if present)
whismanoid 3:80bae2311ddb 65 // - remove MAX32620FTHR library (if present)
whismanoid 3:80bae2311ddb 66 // - not tested yet
whismanoid 3:80bae2311ddb 67 //
whismanoid 3:80bae2311ddb 68 // end Platform_Include_Boilerplate
whismanoid 0:5da566e61083 69 #include "MAX5171.h"
whismanoid 0:5da566e61083 70
whismanoid 0:5da566e61083 71 // example code board support
whismanoid 0:5da566e61083 72 //MAX32630FTHR pegasus(MAX32630FTHR::VIO_3V3);
whismanoid 0:5da566e61083 73 //DigitalOut rLED(LED1);
whismanoid 0:5da566e61083 74 //DigitalOut gLED(LED2);
whismanoid 0:5da566e61083 75 //DigitalOut bLED(LED3);
whismanoid 0:5da566e61083 76 //
whismanoid 0:5da566e61083 77 // Arduino "shield" connector port definitions (MAX32625MBED shown)
whismanoid 0:5da566e61083 78 #if defined(TARGET_MAX32625MBED)
whismanoid 0:5da566e61083 79 #define A0 AIN_0
whismanoid 0:5da566e61083 80 #define A1 AIN_1
whismanoid 0:5da566e61083 81 #define A2 AIN_2
whismanoid 0:5da566e61083 82 #define A3 AIN_3
whismanoid 0:5da566e61083 83 #define D0 P0_0
whismanoid 0:5da566e61083 84 #define D1 P0_1
whismanoid 0:5da566e61083 85 #define D2 P0_2
whismanoid 0:5da566e61083 86 #define D3 P0_3
whismanoid 0:5da566e61083 87 #define D4 P0_4
whismanoid 0:5da566e61083 88 #define D5 P0_5
whismanoid 0:5da566e61083 89 #define D6 P0_6
whismanoid 0:5da566e61083 90 #define D7 P0_7
whismanoid 0:5da566e61083 91 #define D8 P1_4
whismanoid 0:5da566e61083 92 #define D9 P1_5
whismanoid 0:5da566e61083 93 #define D10 P1_3
whismanoid 0:5da566e61083 94 #define D11 P1_1
whismanoid 0:5da566e61083 95 #define D12 P1_2
whismanoid 0:5da566e61083 96 #define D13 P1_0
whismanoid 0:5da566e61083 97 #endif
whismanoid 0:5da566e61083 98
whismanoid 0:5da566e61083 99 // example code declare SPI interface
whismanoid 0:5da566e61083 100 #if defined(TARGET_MAX32625MBED)
whismanoid 0:5da566e61083 101 SPI spi(SPI1_MOSI, SPI1_MISO, SPI1_SCK); // mosi, miso, sclk spi1 TARGET_MAX32625MBED: P1_1 P1_2 P1_0 Arduino 10-pin header D11 D12 D13
whismanoid 0:5da566e61083 102 DigitalOut spi_cs(SPI1_SS); // TARGET_MAX32625MBED: P1_3 Arduino 10-pin header D10
whismanoid 0:5da566e61083 103 #elif defined(TARGET_MAX32600MBED)
whismanoid 0:5da566e61083 104 SPI spi(SPI2_MOSI, SPI2_MISO, SPI2_SCK); // mosi, miso, sclk spi1 TARGET_MAX32600MBED: Arduino 10-pin header D11 D12 D13
whismanoid 0:5da566e61083 105 DigitalOut spi_cs(SPI2_SS); // Generic: Arduino 10-pin header D10
whismanoid 0:5da566e61083 106 #else
whismanoid 0:5da566e61083 107 SPI spi(D11, D12, D13); // mosi, miso, sclk spi1 TARGET_MAX32600MBED: Arduino 10-pin header D11 D12 D13
whismanoid 0:5da566e61083 108 DigitalOut spi_cs(D10); // Generic: Arduino 10-pin header D10
whismanoid 0:5da566e61083 109 #endif
whismanoid 0:5da566e61083 110
whismanoid 0:5da566e61083 111 // example code declare GPIO interface pins
whismanoid 0:5da566e61083 112 // AnalogOut FB_pin(Px_x_PortName_To_Be_Determined); // Analog Input to MAX5171 device
whismanoid 0:5da566e61083 113 DigitalOut RS_pin(D9); // Digital Configuration Input to MAX5171 device
whismanoid 0:5da566e61083 114 DigitalOut PDLb_pin(D8); // Digital Configuration Input to MAX5171 device
whismanoid 0:5da566e61083 115 DigitalOut CLRb_pin(D7); // Digital Configuration Input to MAX5171 device
whismanoid 0:5da566e61083 116 DigitalOut SHDN_pin(D6); // Digital Configuration Input to MAX5171 device
whismanoid 0:5da566e61083 117 // AnalogIn OUT_pin(A0); // Analog Output from MAX5171 device
whismanoid 0:5da566e61083 118 DigitalIn UPO_pin(D5); // Digital General-Purpose Output from MAX5171 device
whismanoid 0:5da566e61083 119 // example code declare device instance
whismanoid 0:5da566e61083 120 MAX5171 g_MAX5171_device(spi, spi_cs, RS_pin, PDLb_pin, CLRb_pin, SHDN_pin, UPO_pin, MAX5171::MAX5171_IC);
whismanoid 0:5da566e61083 121
whismanoid 0:5da566e61083 122 // example code main function
whismanoid 0:5da566e61083 123 int main()
whismanoid 0:5da566e61083 124 {
whismanoid 0:5da566e61083 125 while (1)
whismanoid 0:5da566e61083 126 {
whismanoid 0:5da566e61083 127 g_MAX5171_device.Init();
whismanoid 0:5da566e61083 128
whismanoid 3:80bae2311ddb 129 uint16_t code;
whismanoid 3:80bae2311ddb 130 //
whismanoid 3:80bae2311ddb 131 // example #1
whismanoid 3:80bae2311ddb 132 code = 0x3332; // 80.0% of full scale REF(2.50V) = 2.00V
whismanoid 0:5da566e61083 133 g_MAX5171_device.CODE_LOAD(code);
whismanoid 0:5da566e61083 134 //
whismanoid 3:80bae2311ddb 135 // example #2
whismanoid 3:80bae2311ddb 136 code = 0x1fff; // 50.0% of full scale REF(2.50V) = 1.25V
whismanoid 0:5da566e61083 137 g_MAX5171_device.CODE_LOAD(code);
whismanoid 0:5da566e61083 138 //
whismanoid 3:80bae2311ddb 139 // example #3
whismanoid 3:80bae2311ddb 140 code = 0x1999; // 40.0% of full scale REF(2.50V) = 1.00V
whismanoid 0:5da566e61083 141 g_MAX5171_device.CODE_LOAD(code);
whismanoid 0:5da566e61083 142 //
whismanoid 3:80bae2311ddb 143 // example #4
whismanoid 3:80bae2311ddb 144 code = 0x3fff; // 100.0% of full scale REF(2.50V) = 2.50V
whismanoid 0:5da566e61083 145 g_MAX5171_device.CODE_LOAD(code);
whismanoid 0:5da566e61083 146
whismanoid 3:80bae2311ddb 147 // wait(3.0);
whismanoid 0:5da566e61083 148 }
whismanoid 0:5da566e61083 149 }