Example host software for the Maxim Integrated MAX11131 SPI 12-bit 16-channel ADC with SampleSet. Hosted on the MAX32625MBED.

Dependencies:   MAX11131 CmdLine USBDevice

Committer:
whismanoid
Date:
Fri Sep 27 21:14:47 2019 -0700
Revision:
5:05a75fbab7b0
Parent:
4:d7f90142349d
Added tag 2019-09-27_r1.0 for changeset d7f90142349d

Who changed what in which revision?

UserRevisionLine numberNew contents of line
whismanoid 3:7ee531139389 1 // /*******************************************************************************
whismanoid 3:7ee531139389 2 // * Copyright (C) 2019 Maxim Integrated Products, Inc., All Rights Reserved.
whismanoid 3:7ee531139389 3 // *
whismanoid 3:7ee531139389 4 // * Permission is hereby granted, free of charge, to any person obtaining a
whismanoid 3:7ee531139389 5 // * copy of this software and associated documentation files (the "Software"),
whismanoid 3:7ee531139389 6 // * to deal in the Software without restriction, including without limitation
whismanoid 3:7ee531139389 7 // * the rights to use, copy, modify, merge, publish, distribute, sublicense,
whismanoid 3:7ee531139389 8 // * and/or sell copies of the Software, and to permit persons to whom the
whismanoid 3:7ee531139389 9 // * Software is furnished to do so, subject to the following conditions:
whismanoid 3:7ee531139389 10 // *
whismanoid 3:7ee531139389 11 // * The above copyright notice and this permission notice shall be included
whismanoid 3:7ee531139389 12 // * in all copies or substantial portions of the Software.
whismanoid 3:7ee531139389 13 // *
whismanoid 3:7ee531139389 14 // * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
whismanoid 3:7ee531139389 15 // * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
whismanoid 3:7ee531139389 16 // * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
whismanoid 3:7ee531139389 17 // * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
whismanoid 3:7ee531139389 18 // * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
whismanoid 3:7ee531139389 19 // * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
whismanoid 3:7ee531139389 20 // * OTHER DEALINGS IN THE SOFTWARE.
whismanoid 3:7ee531139389 21 // *
whismanoid 3:7ee531139389 22 // * Except as contained in this notice, the name of Maxim Integrated
whismanoid 3:7ee531139389 23 // * Products, Inc. shall not be used except as stated in the Maxim Integrated
whismanoid 3:7ee531139389 24 // * Products, Inc. Branding Policy.
whismanoid 3:7ee531139389 25 // *
whismanoid 3:7ee531139389 26 // * The mere transfer of this software does not imply any licenses
whismanoid 3:7ee531139389 27 // * of trade secrets, proprietary technology, copyrights, patents,
whismanoid 3:7ee531139389 28 // * trademarks, maskwork rights, or any other form of intellectual
whismanoid 3:7ee531139389 29 // * property whatsoever. Maxim Integrated Products, Inc. retains all
whismanoid 3:7ee531139389 30 // * ownership rights.
whismanoid 3:7ee531139389 31 // *******************************************************************************
whismanoid 3:7ee531139389 32 // */
whismanoid 3:7ee531139389 33 // example code includes
whismanoid 3:7ee531139389 34 // standard include for target platform -- Platform_Include_Boilerplate
whismanoid 3:7ee531139389 35 #include "mbed.h"
whismanoid 3:7ee531139389 36 // Platforms:
whismanoid 3:7ee531139389 37 // - MAX32625MBED
whismanoid 3:7ee531139389 38 // - supports mbed-os-5.11, requires USBDevice library
whismanoid 3:7ee531139389 39 // - add https://developer.mbed.org/teams/MaximIntegrated/code/USBDevice/
whismanoid 3:7ee531139389 40 // - remove max32630fthr library (if present)
whismanoid 3:7ee531139389 41 // - remove MAX32620FTHR library (if present)
whismanoid 3:7ee531139389 42 // - MAX32600MBED
whismanoid 3:7ee531139389 43 // - remove max32630fthr library (if present)
whismanoid 3:7ee531139389 44 // - remove MAX32620FTHR library (if present)
whismanoid 3:7ee531139389 45 // - Windows 10 note: Don't connect HDK until you are ready to load new firmware into the board.
whismanoid 3:7ee531139389 46 // - NUCLEO_F446RE
whismanoid 3:7ee531139389 47 // - remove USBDevice library
whismanoid 3:7ee531139389 48 // - remove max32630fthr library (if present)
whismanoid 3:7ee531139389 49 // - remove MAX32620FTHR library (if present)
whismanoid 3:7ee531139389 50 // - NUCLEO_F401RE
whismanoid 3:7ee531139389 51 // - remove USBDevice library
whismanoid 3:7ee531139389 52 // - remove max32630fthr library (if present)
whismanoid 3:7ee531139389 53 // - remove MAX32620FTHR library (if present)
whismanoid 3:7ee531139389 54 // - MAX32630FTHR
whismanoid 3:7ee531139389 55 // - #include "max32630fthr.h"
whismanoid 3:7ee531139389 56 // - add http://os.mbed.org/teams/MaximIntegrated/code/max32630fthr/
whismanoid 3:7ee531139389 57 // - remove MAX32620FTHR library (if present)
whismanoid 3:7ee531139389 58 // - MAX32620FTHR
whismanoid 3:7ee531139389 59 // - #include "MAX32620FTHR.h"
whismanoid 3:7ee531139389 60 // - remove max32630fthr library (if present)
whismanoid 3:7ee531139389 61 // - add https://os.mbed.com/teams/MaximIntegrated/code/MAX32620FTHR/
whismanoid 3:7ee531139389 62 // - not tested yet
whismanoid 3:7ee531139389 63 // - MAX32625PICO
whismanoid 3:7ee531139389 64 // - remove max32630fthr library (if present)
whismanoid 3:7ee531139389 65 // - remove MAX32620FTHR library (if present)
whismanoid 3:7ee531139389 66 // - not tested yet
whismanoid 3:7ee531139389 67 //
whismanoid 3:7ee531139389 68 // end Platform_Include_Boilerplate
whismanoid 3:7ee531139389 69 #include "MAX11131.h"
whismanoid 3:7ee531139389 70
whismanoid 3:7ee531139389 71 // example code board support
whismanoid 3:7ee531139389 72 //MAX32630FTHR pegasus(MAX32630FTHR::VIO_3V3);
whismanoid 3:7ee531139389 73 //DigitalOut rLED(LED1);
whismanoid 3:7ee531139389 74 //DigitalOut gLED(LED2);
whismanoid 3:7ee531139389 75 //DigitalOut bLED(LED3);
whismanoid 3:7ee531139389 76 //
whismanoid 3:7ee531139389 77 // Arduino "shield" connector port definitions (MAX32625MBED shown)
whismanoid 3:7ee531139389 78 #if defined(TARGET_MAX32625MBED)
whismanoid 3:7ee531139389 79 #define A0 AIN_0
whismanoid 3:7ee531139389 80 #define A1 AIN_1
whismanoid 3:7ee531139389 81 #define A2 AIN_2
whismanoid 3:7ee531139389 82 #define A3 AIN_3
whismanoid 3:7ee531139389 83 #define D0 P0_0
whismanoid 3:7ee531139389 84 #define D1 P0_1
whismanoid 3:7ee531139389 85 #define D2 P0_2
whismanoid 3:7ee531139389 86 #define D3 P0_3
whismanoid 3:7ee531139389 87 #define D4 P0_4
whismanoid 3:7ee531139389 88 #define D5 P0_5
whismanoid 3:7ee531139389 89 #define D6 P0_6
whismanoid 3:7ee531139389 90 #define D7 P0_7
whismanoid 3:7ee531139389 91 #define D8 P1_4
whismanoid 3:7ee531139389 92 #define D9 P1_5
whismanoid 3:7ee531139389 93 #define D10 P1_3
whismanoid 3:7ee531139389 94 #define D11 P1_1
whismanoid 3:7ee531139389 95 #define D12 P1_2
whismanoid 3:7ee531139389 96 #define D13 P1_0
whismanoid 3:7ee531139389 97 #endif
whismanoid 3:7ee531139389 98
whismanoid 3:7ee531139389 99 // example code declare SPI interface
whismanoid 3:7ee531139389 100 #if defined(TARGET_MAX32625MBED)
whismanoid 3:7ee531139389 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 3:7ee531139389 102 DigitalOut spi_cs(SPI1_SS); // TARGET_MAX32625MBED: P1_3 Arduino 10-pin header D10
whismanoid 3:7ee531139389 103 #elif defined(TARGET_MAX32600MBED)
whismanoid 3:7ee531139389 104 SPI spi(SPI2_MOSI, SPI2_MISO, SPI2_SCK); // mosi, miso, sclk spi1 TARGET_MAX32600MBED: Arduino 10-pin header D11 D12 D13
whismanoid 3:7ee531139389 105 DigitalOut spi_cs(SPI2_SS); // Generic: Arduino 10-pin header D10
whismanoid 3:7ee531139389 106 #else
whismanoid 3:7ee531139389 107 SPI spi(D11, D12, D13); // mosi, miso, sclk spi1 TARGET_MAX32600MBED: Arduino 10-pin header D11 D12 D13
whismanoid 3:7ee531139389 108 DigitalOut spi_cs(D10); // Generic: Arduino 10-pin header D10
whismanoid 3:7ee531139389 109 #endif
whismanoid 3:7ee531139389 110
whismanoid 3:7ee531139389 111 // example code declare GPIO interface pins
whismanoid 3:7ee531139389 112 DigitalOut CNVST_pin(D9); // Digital Trigger Input to MAX11131 device
whismanoid 3:7ee531139389 113 // AnalogOut REF_plus_pin(Px_x_PortName_To_Be_Determined); // Reference Input to MAX11131 device
whismanoid 3:7ee531139389 114 // AnalogOut REF_minus_slash_AIN15_pin(Px_x_PortName_To_Be_Determined); // Reference Input to MAX11131 device
whismanoid 3:7ee531139389 115 DigitalIn EOC_pin(D2); // Digital Event Output from MAX11131 device
whismanoid 3:7ee531139389 116 // example code declare device instance
whismanoid 3:7ee531139389 117 MAX11131 g_MAX11131_device(spi, spi_cs, CNVST_pin, EOC_pin, MAX11131::MAX11131_IC);
whismanoid 3:7ee531139389 118
whismanoid 3:7ee531139389 119 //--------------------------------------------------
whismanoid 3:7ee531139389 120 // Declare the Serial driver
whismanoid 3:7ee531139389 121 // default baud rate settings are 9600 8N1
whismanoid 3:7ee531139389 122 // install device driver from http://developer.mbed.org/media/downloads/drivers/mbedWinSerial_16466.exe
whismanoid 3:7ee531139389 123 // see docs https://docs.mbed.com/docs/mbed-os-handbook/en/5.5/getting_started/what_need/
whismanoid 3:7ee531139389 124 #if defined(TARGET_MAX32630)
whismanoid 3:7ee531139389 125 #include "USBSerial.h"
whismanoid 3:7ee531139389 126 // Hardware serial port over DAPLink
whismanoid 3:7ee531139389 127 // The default baud rate for the DapLink UART is 9600
whismanoid 3:7ee531139389 128 //Serial DAPLINKserial(P2_1, P2_0); // tx, rx
whismanoid 3:7ee531139389 129 // #define HAS_DAPLINK_SERIAL 1
whismanoid 3:7ee531139389 130 // Virtual serial port over USB
whismanoid 3:7ee531139389 131 // The baud rate does not affect the virtual USBSerial UART.
whismanoid 3:7ee531139389 132 USBSerial serial;
whismanoid 3:7ee531139389 133 //--------------------------------------------------
whismanoid 3:7ee531139389 134 #elif defined(TARGET_MAX32625MBED)
whismanoid 3:7ee531139389 135 #include "USBSerial.h"
whismanoid 3:7ee531139389 136 // Hardware serial port over DAPLink
whismanoid 3:7ee531139389 137 // The default baud rate for the DapLink UART is 9600
whismanoid 3:7ee531139389 138 //Serial DAPLINKserial(P2_1, P2_0); // tx, rx
whismanoid 3:7ee531139389 139 // #define HAS_DAPLINK_SERIAL 1
whismanoid 3:7ee531139389 140 // Virtual serial port over USB
whismanoid 3:7ee531139389 141 // The baud rate does not affect the virtual USBSerial UART.
whismanoid 3:7ee531139389 142 USBSerial serial;
whismanoid 3:7ee531139389 143 //--------------------------------------------------
whismanoid 3:7ee531139389 144 #elif defined(TARGET_MAX32600)
whismanoid 3:7ee531139389 145 #include "USBSerial.h"
whismanoid 3:7ee531139389 146 // Hardware serial port over DAPLink
whismanoid 3:7ee531139389 147 // The default baud rate for the DapLink UART is 9600
whismanoid 3:7ee531139389 148 Serial DAPLINKserial(P1_1, P1_0); // tx, rx
whismanoid 3:7ee531139389 149 #define HAS_DAPLINK_SERIAL 1
whismanoid 3:7ee531139389 150 // Virtual serial port over USB
whismanoid 3:7ee531139389 151 // The baud rate does not affect the virtual USBSerial UART.
whismanoid 3:7ee531139389 152 USBSerial serial;
whismanoid 3:7ee531139389 153 //--------------------------------------------------
whismanoid 3:7ee531139389 154 #elif defined(TARGET_NUCLEO_F446RE) || defined(TARGET_NUCLEO_F401RE)
whismanoid 3:7ee531139389 155 Serial serial(SERIAL_TX, SERIAL_RX); // tx, rx
whismanoid 3:7ee531139389 156 //--------------------------------------------------
whismanoid 3:7ee531139389 157 #else
whismanoid 3:7ee531139389 158 #if defined(SERIAL_TX)
whismanoid 3:7ee531139389 159 #warning "target not previously tested; guess serial pins are SERIAL_TX, SERIAL_RX..."
whismanoid 3:7ee531139389 160 Serial serial(SERIAL_TX, SERIAL_RX); // tx, rx
whismanoid 3:7ee531139389 161 #elif defined(USBTX)
whismanoid 3:7ee531139389 162 #warning "target not previously tested; guess serial pins are USBTX, USBRX..."
whismanoid 3:7ee531139389 163 Serial serial(USBTX, USBRX); // tx, rx
whismanoid 3:7ee531139389 164 #elif defined(UART_TX)
whismanoid 3:7ee531139389 165 #warning "target not previously tested; guess serial pins are UART_TX, UART_RX..."
whismanoid 3:7ee531139389 166 Serial serial(UART_TX, UART_RX); // tx, rx
whismanoid 3:7ee531139389 167 #else
whismanoid 3:7ee531139389 168 #warning "target not previously tested; need to define serial pins..."
whismanoid 3:7ee531139389 169 #endif
whismanoid 3:7ee531139389 170 #endif
whismanoid 3:7ee531139389 171 //
whismanoid 3:7ee531139389 172 #include "CmdLine.h"
whismanoid 3:7ee531139389 173 CmdLine cmdLine(serial, "serial");
whismanoid 3:7ee531139389 174
whismanoid 3:7ee531139389 175 // example code main function
whismanoid 3:7ee531139389 176 int main()
whismanoid 3:7ee531139389 177 {
whismanoid 3:7ee531139389 178 while (1)
whismanoid 3:7ee531139389 179 {
whismanoid 3:7ee531139389 180 g_MAX11131_device.Init();
whismanoid 3:7ee531139389 181
whismanoid 3:7ee531139389 182 while(1) { // this code repeats forever
whismanoid 3:7ee531139389 183 // this code repeats forever
whismanoid 3:7ee531139389 184 // Measure ADC channels in sequence from AIN0 to channelNumber_0_15.
whismanoid 3:7ee531139389 185 // @param[in] g_MAX11131_device.channelNumber_0_15: AIN Channel Number
whismanoid 3:7ee531139389 186 // @param[in] g_MAX11131_device.PowerManagement_0_2: 0=Normal, 1=AutoShutdown, 2=AutoStandby
whismanoid 3:7ee531139389 187 // @param[in] g_MAX11131_device.chan_id_0_1: ADC_MODE_CONTROL.CHAN_ID
whismanoid 3:7ee531139389 188 int channelId_0_15 = 15;
whismanoid 3:7ee531139389 189 g_MAX11131_device.channelNumber_0_15 = channelId_0_15;
whismanoid 3:7ee531139389 190 g_MAX11131_device.PowerManagement_0_2 = 0;
whismanoid 3:7ee531139389 191 g_MAX11131_device.chan_id_0_1 = 1;
whismanoid 3:7ee531139389 192 g_MAX11131_device.NumWords = g_MAX11131_device.ScanStandardExternalClock();
whismanoid 3:7ee531139389 193
whismanoid 3:7ee531139389 194 // Read raw ADC codes from device into AINcode[] and RAW_misoData16[]
whismanoid 3:7ee531139389 195 // @pre one of the MAX11311_Scan functions was called, setting g_MAX11131_device.NumWords
whismanoid 3:7ee531139389 196 g_MAX11131_device.ReadAINcode();
whismanoid 3:7ee531139389 197 // @post RAW_misoData16[index] contains the raw SPI Master-In,Slave-Out data
whismanoid 3:7ee531139389 198 // @post AINcode[NUM_CHANNELS] contains the latest readings in LSBs
whismanoid 3:7ee531139389 199
whismanoid 4:d7f90142349d 200 // wait(3.0);
whismanoid 3:7ee531139389 201 // Use Arduino Serial Plotter to view output: Tools | Serial Plotter
whismanoid 3:7ee531139389 202 cmdLine.serial().printf("%d", g_MAX11131_device.AINcode[0]);
whismanoid 3:7ee531139389 203 for (int index = 1; index <= channelId_0_15; index++) {
whismanoid 3:7ee531139389 204 cmdLine.serial().printf(",%d", g_MAX11131_device.AINcode[index]);
whismanoid 3:7ee531139389 205 }
whismanoid 4:d7f90142349d 206 cmdLine.serial().printf("\r\n");
whismanoid 3:7ee531139389 207
whismanoid 3:7ee531139389 208 } // this code repeats forever
whismanoid 3:7ee531139389 209 }
whismanoid 3:7ee531139389 210 }