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