Example host software for the Maxim Integrated MAX5715 12-bit 4-channel voltage-output DAC. Hosted on the MAX32625MBED.
Dependencies: MAX5715
main.cpp@7:0367e520c682, 2019-05-16 (annotated)
- Committer:
- whismanoid
- Date:
- Thu May 16 20:08:09 2019 +0000
- Revision:
- 7:0367e520c682
- Parent:
- 6:0bfe0d990850
- Child:
- 9:1d512984d625
serial port robustness
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
whismanoid | 2:015f0dc1ff16 | 1 | // /******************************************************************************* |
whismanoid | 2:015f0dc1ff16 | 2 | // * Copyright (C) 2019 Maxim Integrated Products, Inc., All Rights Reserved. |
whismanoid | 2:015f0dc1ff16 | 3 | // * |
whismanoid | 2:015f0dc1ff16 | 4 | // * Permission is hereby granted, free of charge, to any person obtaining a |
whismanoid | 2:015f0dc1ff16 | 5 | // * copy of this software and associated documentation files (the "Software"), |
whismanoid | 2:015f0dc1ff16 | 6 | // * to deal in the Software without restriction, including without limitation |
whismanoid | 2:015f0dc1ff16 | 7 | // * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
whismanoid | 2:015f0dc1ff16 | 8 | // * and/or sell copies of the Software, and to permit persons to whom the |
whismanoid | 2:015f0dc1ff16 | 9 | // * Software is furnished to do so, subject to the following conditions: |
whismanoid | 2:015f0dc1ff16 | 10 | // * |
whismanoid | 2:015f0dc1ff16 | 11 | // * The above copyright notice and this permission notice shall be included |
whismanoid | 2:015f0dc1ff16 | 12 | // * in all copies or substantial portions of the Software. |
whismanoid | 2:015f0dc1ff16 | 13 | // * |
whismanoid | 2:015f0dc1ff16 | 14 | // * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
whismanoid | 2:015f0dc1ff16 | 15 | // * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
whismanoid | 2:015f0dc1ff16 | 16 | // * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
whismanoid | 2:015f0dc1ff16 | 17 | // * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES |
whismanoid | 2:015f0dc1ff16 | 18 | // * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
whismanoid | 2:015f0dc1ff16 | 19 | // * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
whismanoid | 2:015f0dc1ff16 | 20 | // * OTHER DEALINGS IN THE SOFTWARE. |
whismanoid | 2:015f0dc1ff16 | 21 | // * |
whismanoid | 2:015f0dc1ff16 | 22 | // * Except as contained in this notice, the name of Maxim Integrated |
whismanoid | 2:015f0dc1ff16 | 23 | // * Products, Inc. shall not be used except as stated in the Maxim Integrated |
whismanoid | 2:015f0dc1ff16 | 24 | // * Products, Inc. Branding Policy. |
whismanoid | 2:015f0dc1ff16 | 25 | // * |
whismanoid | 2:015f0dc1ff16 | 26 | // * The mere transfer of this software does not imply any licenses |
whismanoid | 2:015f0dc1ff16 | 27 | // * of trade secrets, proprietary technology, copyrights, patents, |
whismanoid | 2:015f0dc1ff16 | 28 | // * trademarks, maskwork rights, or any other form of intellectual |
whismanoid | 2:015f0dc1ff16 | 29 | // * property whatsoever. Maxim Integrated Products, Inc. retains all |
whismanoid | 2:015f0dc1ff16 | 30 | // * ownership rights. |
whismanoid | 2:015f0dc1ff16 | 31 | // ******************************************************************************* |
whismanoid | 2:015f0dc1ff16 | 32 | // */ |
whismanoid | 3:9db1ff35500e | 33 | //---------- CODE GENERATOR: testMainCppCodeList |
whismanoid | 3:9db1ff35500e | 34 | // CODE GENERATOR: example code includes |
whismanoid | 2:015f0dc1ff16 | 35 | // example code includes |
whismanoid | 0:cb3754747a08 | 36 | #include "mbed.h" |
whismanoid | 0:cb3754747a08 | 37 | //#include "max32625.h" |
whismanoid | 0:cb3754747a08 | 38 | #include "MAX5715.h" |
whismanoid | 5:e9594321c488 | 39 | |
whismanoid | 5:e9594321c488 | 40 | // optional: serial port |
whismanoid | 6:0bfe0d990850 | 41 | // note: some platforms such as Nucleo-F446RE do not support the USBSerial library. |
whismanoid | 6:0bfe0d990850 | 42 | // In those cases, remove the USBDevice lib from the project and rebuild. |
whismanoid | 6:0bfe0d990850 | 43 | #if defined(TARGET_MAX32625MBED) |
whismanoid | 6:0bfe0d990850 | 44 | #include "USBSerial.h" |
whismanoid | 6:0bfe0d990850 | 45 | USBSerial serial; // virtual serial port over USB (DEV connector) |
whismanoid | 6:0bfe0d990850 | 46 | #elif defined(TARGET_MAX32630MBED) |
whismanoid | 6:0bfe0d990850 | 47 | #include "USBSerial.h" |
whismanoid | 6:0bfe0d990850 | 48 | USBSerial serial; // virtual serial port over USB (DEV connector) |
whismanoid | 6:0bfe0d990850 | 49 | #else |
whismanoid | 5:e9594321c488 | 50 | //#include "USBSerial.h" |
whismanoid | 5:e9594321c488 | 51 | Serial serial(USBTX, USBRX); // tx, rx |
whismanoid | 6:0bfe0d990850 | 52 | #endif |
whismanoid | 0:cb3754747a08 | 53 | |
whismanoid | 2:015f0dc1ff16 | 54 | // example code board support |
whismanoid | 0:cb3754747a08 | 55 | //MAX32630FTHR pegasus(MAX32630FTHR::VIO_3V3); |
whismanoid | 0:cb3754747a08 | 56 | //DigitalOut rLED(LED1); |
whismanoid | 0:cb3754747a08 | 57 | //DigitalOut gLED(LED2); |
whismanoid | 0:cb3754747a08 | 58 | //DigitalOut bLED(LED3); |
whismanoid | 2:015f0dc1ff16 | 59 | // |
whismanoid | 5:e9594321c488 | 60 | // Arduino "shield" connector port definitions (MAX32625MBED shown) |
whismanoid | 5:e9594321c488 | 61 | #if defined(TARGET_MAX32625MBED) |
whismanoid | 5:e9594321c488 | 62 | #define A0 AIN_0 |
whismanoid | 5:e9594321c488 | 63 | #define A1 AIN_1 |
whismanoid | 5:e9594321c488 | 64 | #define A2 AIN_2 |
whismanoid | 5:e9594321c488 | 65 | #define A3 AIN_3 |
whismanoid | 5:e9594321c488 | 66 | #define D0 P0_0 |
whismanoid | 5:e9594321c488 | 67 | #define D1 P0_1 |
whismanoid | 5:e9594321c488 | 68 | #define D2 P0_2 |
whismanoid | 5:e9594321c488 | 69 | #define D3 P0_3 |
whismanoid | 5:e9594321c488 | 70 | #define D4 P0_4 |
whismanoid | 5:e9594321c488 | 71 | #define D5 P0_5 |
whismanoid | 5:e9594321c488 | 72 | #define D6 P0_6 |
whismanoid | 5:e9594321c488 | 73 | #define D7 P0_7 |
whismanoid | 2:015f0dc1ff16 | 74 | #define D8 P1_4 |
whismanoid | 2:015f0dc1ff16 | 75 | #define D9 P1_5 |
whismanoid | 5:e9594321c488 | 76 | #define D10 P1_3 |
whismanoid | 5:e9594321c488 | 77 | #define D11 P1_1 |
whismanoid | 5:e9594321c488 | 78 | #define D12 P1_2 |
whismanoid | 5:e9594321c488 | 79 | #define D13 P1_0 |
whismanoid | 5:e9594321c488 | 80 | #endif |
whismanoid | 2:015f0dc1ff16 | 81 | |
whismanoid | 2:015f0dc1ff16 | 82 | // example code declare SPI interface |
whismanoid | 4:00b24a55a098 | 83 | #if defined(TARGET_MAX32625MBED) |
whismanoid | 4:00b24a55a098 | 84 | 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 | 4:00b24a55a098 | 85 | DigitalOut spi_cs(SPI1_SS); // TARGET_MAX32625MBED: P1_3 Arduino 10-pin header D10 |
whismanoid | 4:00b24a55a098 | 86 | #elif defined(TARGET_MAX32600MBED) |
whismanoid | 4:00b24a55a098 | 87 | SPI spi(SPI2_MOSI, SPI2_MISO, SPI2_SCK); // mosi, miso, sclk spi1 TARGET_MAX32600MBED: Arduino 10-pin header D11 D12 D13 |
whismanoid | 4:00b24a55a098 | 88 | DigitalOut spi_cs(SPI2_SS); // Generic: Arduino 10-pin header D10 |
whismanoid | 4:00b24a55a098 | 89 | #else |
whismanoid | 4:00b24a55a098 | 90 | SPI spi(D11, D12, D13); // mosi, miso, sclk spi1 TARGET_MAX32600MBED: Arduino 10-pin header D11 D12 D13 |
whismanoid | 4:00b24a55a098 | 91 | DigitalOut spi_cs(D10); // Generic: Arduino 10-pin header D10 |
whismanoid | 4:00b24a55a098 | 92 | #endif |
whismanoid | 2:015f0dc1ff16 | 93 | |
whismanoid | 2:015f0dc1ff16 | 94 | // example code declare GPIO interface pins |
whismanoid | 2:015f0dc1ff16 | 95 | DigitalOut LDACb_pin(D9); // Digital Trigger Input to device |
whismanoid | 2:015f0dc1ff16 | 96 | DigitalOut CLRb_pin(D8); // Digital Trigger Input to device |
whismanoid | 3:9db1ff35500e | 97 | // AnalogOut REF_pin(Px_x_PortName_To_Be_Determined); // Reference Input to device |
whismanoid | 3:9db1ff35500e | 98 | // AnalogIn OUTA_pin(A0); // Analog Output from device |
whismanoid | 3:9db1ff35500e | 99 | // AnalogIn OUTB_pin(A1); // Analog Output from device |
whismanoid | 3:9db1ff35500e | 100 | // AnalogIn OUTC_pin(A2); // Analog Output from device |
whismanoid | 3:9db1ff35500e | 101 | // AnalogIn OUTD_pin(A3); // Analog Output from device |
whismanoid | 3:9db1ff35500e | 102 | // DigitalIn RDYb_pin(Px_x_PortName_To_Be_Determined); // Digital DaisyChain Output from device |
whismanoid | 2:015f0dc1ff16 | 103 | // example code declare device instance |
whismanoid | 1:f82c4c7fe134 | 104 | MAX5715 g_MAX5715_device(spi, spi_cs, LDACb_pin, CLRb_pin, MAX5715::MAX5715_IC); |
whismanoid | 0:cb3754747a08 | 105 | |
whismanoid | 2:015f0dc1ff16 | 106 | // example code main function |
whismanoid | 0:cb3754747a08 | 107 | int main() |
whismanoid | 0:cb3754747a08 | 108 | { |
whismanoid | 6:0bfe0d990850 | 109 | while (1) |
whismanoid | 6:0bfe0d990850 | 110 | { |
whismanoid | 6:0bfe0d990850 | 111 | // example code: serial port banner message |
whismanoid | 6:0bfe0d990850 | 112 | #if defined(TARGET_MAX32625MBED) |
whismanoid | 6:0bfe0d990850 | 113 | serial.printf("MAX32625MBED "); |
whismanoid | 6:0bfe0d990850 | 114 | #elif defined(TARGET_MAX32600MBED) |
whismanoid | 6:0bfe0d990850 | 115 | serial.printf("MAX32600MBED "); |
whismanoid | 6:0bfe0d990850 | 116 | #elif defined(TARGET_NUCLEO_F446RE) |
whismanoid | 6:0bfe0d990850 | 117 | serial.printf("NUCLEO_F446RE "); |
whismanoid | 6:0bfe0d990850 | 118 | #endif |
whismanoid | 6:0bfe0d990850 | 119 | serial.printf("MAX5715BOB\r\n"); |
whismanoid | 7:0367e520c682 | 120 | |
whismanoid | 6:0bfe0d990850 | 121 | //MAX5715 dac(spi, spi_cs, MAX5715::MAX5715_IC); |
whismanoid | 6:0bfe0d990850 | 122 | //dac.Init(); |
whismanoid | 7:0367e520c682 | 123 | |
whismanoid | 6:0bfe0d990850 | 124 | // CODE GENERATOR: example code: member function Init |
whismanoid | 6:0bfe0d990850 | 125 | g_MAX5715_device.Init(); |
whismanoid | 7:0367e520c682 | 126 | |
whismanoid | 6:0bfe0d990850 | 127 | // CODE GENERATOR: example code: member function REF |
whismanoid | 6:0bfe0d990850 | 128 | // CODE GENERATOR: example code: device has enumType 'MAX5715_REF_enum_t' |
whismanoid | 6:0bfe0d990850 | 129 | // CODE GENERATOR: TypedefEnum_MAXxxxxx_REF_enum_t_NamesList: REF_EXT, REF_2V500, REF_2V048, REF_4V096, REF_AlwaysOn_EXT, REF_AlwaysOn_2V500, REF_AlwaysOn_2V048, REF_AlwaysOn_4V096 |
whismanoid | 6:0bfe0d990850 | 130 | g_MAX5715_device.REF(MAX5715::REF_AlwaysOn_2V500); |
whismanoid | 7:0367e520c682 | 131 | |
whismanoid | 6:0bfe0d990850 | 132 | // CODE GENERATOR: example code: has no member function CODE_LOAD |
whismanoid | 6:0bfe0d990850 | 133 | // CODE GENERATOR: example code: member function CODEallLOADall |
whismanoid | 6:0bfe0d990850 | 134 | //uint16_t code = 4095; |
whismanoid | 6:0bfe0d990850 | 135 | //g_MAX5715_device.CODEallLOADall(code); |
whismanoid | 7:0367e520c682 | 136 | |
whismanoid | 6:0bfe0d990850 | 137 | // CODE GENERATOR: example code: member function CODEnLOADn |
whismanoid | 6:0bfe0d990850 | 138 | // |
whismanoid | 6:0bfe0d990850 | 139 | uint16_t ch = 0; |
whismanoid | 6:0bfe0d990850 | 140 | uint16_t code = 0xccc; |
whismanoid | 6:0bfe0d990850 | 141 | g_MAX5715_device.CODEnLOADn(ch, code); |
whismanoid | 6:0bfe0d990850 | 142 | // |
whismanoid | 6:0bfe0d990850 | 143 | ch = 1; |
whismanoid | 6:0bfe0d990850 | 144 | code = 0x800; |
whismanoid | 6:0bfe0d990850 | 145 | g_MAX5715_device.CODEnLOADn(ch, code); |
whismanoid | 6:0bfe0d990850 | 146 | // |
whismanoid | 6:0bfe0d990850 | 147 | ch = 2; |
whismanoid | 6:0bfe0d990850 | 148 | code = 0x666; |
whismanoid | 6:0bfe0d990850 | 149 | g_MAX5715_device.CODEnLOADn(ch, code); |
whismanoid | 6:0bfe0d990850 | 150 | // |
whismanoid | 6:0bfe0d990850 | 151 | ch = 3; |
whismanoid | 6:0bfe0d990850 | 152 | code = 0xFFF; |
whismanoid | 6:0bfe0d990850 | 153 | g_MAX5715_device.CODEnLOADn(ch, code); |
whismanoid | 7:0367e520c682 | 154 | |
whismanoid | 6:0bfe0d990850 | 155 | // CODE GENERATOR: example code: has no member function ScanManual |
whismanoid | 6:0bfe0d990850 | 156 | // CODE GENERATOR: example code: has no member function ReadAINcode |
whismanoid | 6:0bfe0d990850 | 157 | wait(3.0); |
whismanoid | 6:0bfe0d990850 | 158 | } |
whismanoid | 0:cb3754747a08 | 159 | } |
whismanoid | 3:9db1ff35500e | 160 | //---------- CODE GENERATOR: end testMainCppCodeList |