Test program running on MAX32625MBED. Control through USB Serial commands using a terminal emulator such as teraterm or putty.
Dependencies: MaximTinyTester CmdLine MAX541 USBDevice
MAX11043/MAX11043.cpp@93:6b22269935a6, 2020-03-04 (annotated)
- Committer:
- whismanoid
- Date:
- Wed Mar 04 10:03:12 2020 +0000
- Revision:
- 93:6b22269935a6
- Parent:
- 91:9e78c6194d6e
ADCVoltageOfCode_16bit; fix typo Write_AGain 0x2000=1V/V not 1VV/V; onButton2FallingEdge call optional Configure_Demo(); blue LED on
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
whismanoid | 53:3d5a3d241a5e | 1 | // /******************************************************************************* |
whismanoid | 53:3d5a3d241a5e | 2 | // * Copyright (C) 2020 Maxim Integrated Products, Inc., All Rights Reserved. |
whismanoid | 53:3d5a3d241a5e | 3 | // * |
whismanoid | 53:3d5a3d241a5e | 4 | // * Permission is hereby granted, free of charge, to any person obtaining a |
whismanoid | 53:3d5a3d241a5e | 5 | // * copy of this software and associated documentation files (the "Software"), |
whismanoid | 53:3d5a3d241a5e | 6 | // * to deal in the Software without restriction, including without limitation |
whismanoid | 53:3d5a3d241a5e | 7 | // * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
whismanoid | 53:3d5a3d241a5e | 8 | // * and/or sell copies of the Software, and to permit persons to whom the |
whismanoid | 53:3d5a3d241a5e | 9 | // * Software is furnished to do so, subject to the following conditions: |
whismanoid | 53:3d5a3d241a5e | 10 | // * |
whismanoid | 53:3d5a3d241a5e | 11 | // * The above copyright notice and this permission notice shall be included |
whismanoid | 53:3d5a3d241a5e | 12 | // * in all copies or substantial portions of the Software. |
whismanoid | 53:3d5a3d241a5e | 13 | // * |
whismanoid | 53:3d5a3d241a5e | 14 | // * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
whismanoid | 53:3d5a3d241a5e | 15 | // * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
whismanoid | 53:3d5a3d241a5e | 16 | // * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
whismanoid | 53:3d5a3d241a5e | 17 | // * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES |
whismanoid | 53:3d5a3d241a5e | 18 | // * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
whismanoid | 53:3d5a3d241a5e | 19 | // * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
whismanoid | 53:3d5a3d241a5e | 20 | // * OTHER DEALINGS IN THE SOFTWARE. |
whismanoid | 53:3d5a3d241a5e | 21 | // * |
whismanoid | 53:3d5a3d241a5e | 22 | // * Except as contained in this notice, the name of Maxim Integrated |
whismanoid | 53:3d5a3d241a5e | 23 | // * Products, Inc. shall not be used except as stated in the Maxim Integrated |
whismanoid | 53:3d5a3d241a5e | 24 | // * Products, Inc. Branding Policy. |
whismanoid | 53:3d5a3d241a5e | 25 | // * |
whismanoid | 53:3d5a3d241a5e | 26 | // * The mere transfer of this software does not imply any licenses |
whismanoid | 53:3d5a3d241a5e | 27 | // * of trade secrets, proprietary technology, copyrights, patents, |
whismanoid | 53:3d5a3d241a5e | 28 | // * trademarks, maskwork rights, or any other form of intellectual |
whismanoid | 53:3d5a3d241a5e | 29 | // * property whatsoever. Maxim Integrated Products, Inc. retains all |
whismanoid | 53:3d5a3d241a5e | 30 | // * ownership rights. |
whismanoid | 53:3d5a3d241a5e | 31 | // ******************************************************************************* |
whismanoid | 53:3d5a3d241a5e | 32 | // */ |
whismanoid | 53:3d5a3d241a5e | 33 | // ********************************************************************* |
whismanoid | 53:3d5a3d241a5e | 34 | // @file MAX11043.cpp |
whismanoid | 53:3d5a3d241a5e | 35 | // ********************************************************************* |
whismanoid | 53:3d5a3d241a5e | 36 | // Device Driver file |
whismanoid | 83:29bb86cc45bc | 37 | // DO NOT EDIT; except areas designated "CUSTOMIZE". Automatically generated file. * MANUAL EDITS PRESENT * |
whismanoid | 53:3d5a3d241a5e | 38 | // generated by XMLSystemOfDevicesToMBED.py |
whismanoid | 53:3d5a3d241a5e | 39 | // System Name = ExampleSystem |
whismanoid | 53:3d5a3d241a5e | 40 | // System Description = Device driver example |
whismanoid | 53:3d5a3d241a5e | 41 | |
whismanoid | 53:3d5a3d241a5e | 42 | #include "MAX11043.h" |
whismanoid | 69:989e392cf635 | 43 | //-------------------------------------------------- |
whismanoid | 69:989e392cf635 | 44 | // MAX11043 ADC Read operations must be synchronized to EOC End Of Conversion |
whismanoid | 69:989e392cf635 | 45 | // EOC# asserts low when new data is available. |
whismanoid | 69:989e392cf635 | 46 | // Initiate a data read prior to the next rising edge of EOC# or the result is overwritten. |
whismanoid | 69:989e392cf635 | 47 | #ifndef MAX11043_EOC_INTERRUPT_POLLING |
whismanoid | 81:167dee56c45b | 48 | #define MAX11043_EOC_INTERRUPT_POLLING 1 |
whismanoid | 69:989e392cf635 | 49 | #endif // MAX11043_EOC_INTERRUPT_POLLING |
whismanoid | 73:879578472009 | 50 | //-------------------------------------------------- |
whismanoid | 76:0397493d7baf | 51 | // SPI is not interrupt-safe, so use EventQueue to defer execution to user context. |
whismanoid | 76:0397493d7baf | 52 | #ifndef MAX11043_EOC_INTERRUPT_EVENTQUEUE |
whismanoid | 83:29bb86cc45bc | 53 | #define MAX11043_EOC_INTERRUPT_EVENTQUEUE 0 |
whismanoid | 76:0397493d7baf | 54 | #endif // MAX11043_EOC_INTERRUPT_EVENTQUEUE |
whismanoid | 76:0397493d7baf | 55 | #if MAX11043_EOC_INTERRUPT_EVENTQUEUE |
whismanoid | 76:0397493d7baf | 56 | #else // MAX11043_EOC_INTERRUPT_EVENTQUEUE |
whismanoid | 76:0397493d7baf | 57 | #endif // MAX11043_EOC_INTERRUPT_EVENTQUEUE |
whismanoid | 76:0397493d7baf | 58 | #if MAX11043_EOC_INTERRUPT_EVENTQUEUE |
whismanoid | 76:0397493d7baf | 59 | // SPI is not interrupt-safe, so use EventQueue to defer execution to user context. |
whismanoid | 76:0397493d7baf | 60 | #include "mbed_events.h" |
whismanoid | 76:0397493d7baf | 61 | #define MYONEOCTHREADEVENTFLAG_ENABLE_SPI (1UL << 0) |
whismanoid | 76:0397493d7baf | 62 | EventFlags myOnEOCThread_event_flags; |
whismanoid | 76:0397493d7baf | 63 | Thread myOnEOCThread; |
whismanoid | 82:9ea067fad5c3 | 64 | #if MAX11043_EOC_INTERRUPT_POLLING |
whismanoid | 82:9ea067fad5c3 | 65 | // MAX11043 myOnEOCThread_POLLING_handler needs 18.80us, still too slow |
whismanoid | 82:9ea067fad5c3 | 66 | extern DigitalInOut digitalInOut2; // m_EOC_pin declared in Test_Main_MAX11043.cpp |
whismanoid | 82:9ea067fad5c3 | 67 | extern void myOnEOCThread_POLLING_handler(); |
whismanoid | 82:9ea067fad5c3 | 68 | #else // MAX11043_EOC_INTERRUPT_POLLING |
whismanoid | 82:9ea067fad5c3 | 69 | extern void myOnEOCThread_EVENTFLAG_ENABLE_SPI_handler(); |
whismanoid | 82:9ea067fad5c3 | 70 | #endif // MAX11043_EOC_INTERRUPT_POLLING |
whismanoid | 76:0397493d7baf | 71 | #else // MAX11043_EOC_INTERRUPT_EVENTQUEUE |
whismanoid | 76:0397493d7baf | 72 | #endif // MAX11043_EOC_INTERRUPT_EVENTQUEUE |
whismanoid | 76:0397493d7baf | 73 | //-------------------------------------------------- |
whismanoid | 73:879578472009 | 74 | // Diagnostic: Use MAX32625MBED pin D5 as DigitalOut EOC#-detected |
whismanoid | 73:879578472009 | 75 | #ifndef MAX11043_ScopeTrigger_MAX32625MBED_D5 |
whismanoid | 73:879578472009 | 76 | #define MAX11043_ScopeTrigger_MAX32625MBED_D5 1 |
whismanoid | 73:879578472009 | 77 | #endif // MAX11043_ScopeTrigger_MAX32625MBED_D5 |
whismanoid | 73:879578472009 | 78 | #if MAX11043_ScopeTrigger_MAX32625MBED_D5 |
whismanoid | 73:879578472009 | 79 | // Diagnostic: Use MAX32625MBED pin D5 as DigitalOut EOC#-detected |
whismanoid | 73:879578472009 | 80 | // WIP MAX11043 interrupt EOC echo - moving DigitalOut ScopeTrigger to global scope, it compiles but there is no activity on scope |
whismanoid | 74:f4f969c9a7a9 | 81 | extern DigitalInOut digitalInOut5; // declared in Test_Main_MAX11043.cpp (D5, PIN_INPUT, PullUp, 1) |
whismanoid | 75:0900a57f2e5d | 82 | const size_t byteCount_onEOCFallingEdge = 1 + (2 * 4); |
whismanoid | 75:0900a57f2e5d | 83 | const uint8_t mosiData_onEOCFallingEdge[9] = { |
whismanoid | 75:0900a57f2e5d | 84 | MAX11043::CMD_0001_1010_d16o8_d16o8_d16o8_d16o8_Rd06_ADCabcd, |
whismanoid | 75:0900a57f2e5d | 85 | 0, 0, 0, 0, 0, 0, 0, 0 |
whismanoid | 75:0900a57f2e5d | 86 | }; |
whismanoid | 75:0900a57f2e5d | 87 | uint8_t misoData_onEOCFallingEdge[9]; |
whismanoid | 73:879578472009 | 88 | #endif // MAX11043_ScopeTrigger_MAX32625MBED_D5 |
whismanoid | 53:3d5a3d241a5e | 89 | |
whismanoid | 53:3d5a3d241a5e | 90 | // Device Name = MAX11043 |
whismanoid | 53:3d5a3d241a5e | 91 | // Device Description = 200ksps, Low-Power, Serial SPI 24-Bit, 4-Channel, Differential/Single-Ended Input, Simultaneous-Sampling SD ADC |
whismanoid | 53:3d5a3d241a5e | 92 | // Device DeviceBriefDescription = 24-bit 200ksps Delta-Sigma ADC |
whismanoid | 53:3d5a3d241a5e | 93 | // Device Manufacturer = Maxim Integrated |
whismanoid | 53:3d5a3d241a5e | 94 | // Device PartNumber = MAX11043ATL+ |
whismanoid | 53:3d5a3d241a5e | 95 | // Device RegValue_Width = DataWidth16bit_HL |
whismanoid | 53:3d5a3d241a5e | 96 | // |
whismanoid | 53:3d5a3d241a5e | 97 | // ADC MaxOutputDataRate = 200ksps |
whismanoid | 53:3d5a3d241a5e | 98 | // ADC NumChannels = 4 |
whismanoid | 53:3d5a3d241a5e | 99 | // ADC ResolutionBits = 24 |
whismanoid | 53:3d5a3d241a5e | 100 | // |
whismanoid | 53:3d5a3d241a5e | 101 | // SPI CS = ActiveLow |
whismanoid | 53:3d5a3d241a5e | 102 | // SPI FrameStart = CS |
whismanoid | 53:3d5a3d241a5e | 103 | // SPI CPOL = 0 |
whismanoid | 53:3d5a3d241a5e | 104 | // SPI CPHA = 0 |
whismanoid | 53:3d5a3d241a5e | 105 | // SPI MOSI and MISO Data are both stable on Rising edge of SCLK |
whismanoid | 53:3d5a3d241a5e | 106 | // SPI SCLK Idle Low |
whismanoid | 53:3d5a3d241a5e | 107 | // SPI SCLKMaxMHz = 40 |
whismanoid | 53:3d5a3d241a5e | 108 | // SPI SCLKMinMHz = 0 |
whismanoid | 53:3d5a3d241a5e | 109 | // |
whismanoid | 53:3d5a3d241a5e | 110 | // InputPin Name = CONVRUN |
whismanoid | 53:3d5a3d241a5e | 111 | // InputPin Description = CONVRUN (digital input). Convert Run. Drive high to start continuous conversions on all 4 channels. The device is idle when |
whismanoid | 53:3d5a3d241a5e | 112 | // CONVRUN is low. |
whismanoid | 53:3d5a3d241a5e | 113 | // InputPin Function = Configuration |
whismanoid | 53:3d5a3d241a5e | 114 | // |
whismanoid | 53:3d5a3d241a5e | 115 | // InputPin Name = SHDN |
whismanoid | 53:3d5a3d241a5e | 116 | // InputPin Description = Shutdown (digital input). Active-High Shutdown Input. Drive high to shut down the MAX11043. |
whismanoid | 53:3d5a3d241a5e | 117 | // InputPin Function = Configuration |
whismanoid | 53:3d5a3d241a5e | 118 | // |
whismanoid | 53:3d5a3d241a5e | 119 | // InputPin Name = DACSTEP |
whismanoid | 53:3d5a3d241a5e | 120 | // InputPin Description = DACSTEP (digital input). DAC Step Input. Drive high to move the DAC output in the direction of UP/DWN on the next rising |
whismanoid | 53:3d5a3d241a5e | 121 | // edge of the system clock. |
whismanoid | 53:3d5a3d241a5e | 122 | // InputPin Function = Configuration |
whismanoid | 53:3d5a3d241a5e | 123 | // |
whismanoid | 53:3d5a3d241a5e | 124 | // InputPin Name = UP/DWN# |
whismanoid | 53:3d5a3d241a5e | 125 | // InputPin Description = UP/DWN# (digital input). DAC Step Direction Select. Drive high to step up, drive low to step down when DACSTEP is toggled. |
whismanoid | 53:3d5a3d241a5e | 126 | // InputPin Function = Configuration |
whismanoid | 53:3d5a3d241a5e | 127 | // |
whismanoid | 53:3d5a3d241a5e | 128 | // OutputPin Name = EOC |
whismanoid | 53:3d5a3d241a5e | 129 | // OutputPin Description = End of Conversion Output. Active-Low End-of-Conversion Indicator. EOC asserts low to indicate that new data is ready. |
whismanoid | 53:3d5a3d241a5e | 130 | // OutputPin Function = Event |
whismanoid | 53:3d5a3d241a5e | 131 | // |
whismanoid | 58:2fea32db466b | 132 | // SupplyPin Name = AVDD |
whismanoid | 58:2fea32db466b | 133 | // SupplyPin Description = Analog Power-Supply Input. Bypass each AVDD with a nominal 1uF capacitor to AGND. |
whismanoid | 58:2fea32db466b | 134 | // SupplyPin VinMax = 3.60 |
whismanoid | 58:2fea32db466b | 135 | // SupplyPin VinMin = 3.00 |
whismanoid | 58:2fea32db466b | 136 | // SupplyPin Function = Analog |
whismanoid | 58:2fea32db466b | 137 | // |
whismanoid | 58:2fea32db466b | 138 | // SupplyPin Name = AGND |
whismanoid | 58:2fea32db466b | 139 | // SupplyPin Description = Analog Ground. Connect all AGND inputs together. |
whismanoid | 58:2fea32db466b | 140 | // SupplyPin VinMax = 0 |
whismanoid | 58:2fea32db466b | 141 | // SupplyPin VinMin = 0 |
whismanoid | 58:2fea32db466b | 142 | // SupplyPin Function = Analog |
whismanoid | 58:2fea32db466b | 143 | // |
whismanoid | 58:2fea32db466b | 144 | // SupplyPin Name = DGND |
whismanoid | 58:2fea32db466b | 145 | // SupplyPin Description = Digital Ground. Connect all DGND inputs together. |
whismanoid | 58:2fea32db466b | 146 | // SupplyPin VinMax = 0 |
whismanoid | 58:2fea32db466b | 147 | // SupplyPin VinMin = 0 |
whismanoid | 58:2fea32db466b | 148 | // SupplyPin Function = Digital |
whismanoid | 58:2fea32db466b | 149 | // |
whismanoid | 58:2fea32db466b | 150 | // SupplyPin Name = DVDD |
whismanoid | 58:2fea32db466b | 151 | // SupplyPin Description = Digital Power-Supply Input. Bypass each DVDD with a nominal 1uF capacitor to DGND. |
whismanoid | 83:29bb86cc45bc | 152 | // SupplyPin VinMax = 3.60 |
whismanoid | 83:29bb86cc45bc | 153 | // SupplyPin VinMin = 3.00 |
whismanoid | 58:2fea32db466b | 154 | // SupplyPin Function = Digital |
whismanoid | 58:2fea32db466b | 155 | // |
whismanoid | 58:2fea32db466b | 156 | // SupplyPin Name = DVREG |
whismanoid | 58:2fea32db466b | 157 | // SupplyPin Description = Regulated Digital Core Supply (from internal +2.5V regulator). Bypass DVREG to DGND with a 10uF capacitor. |
whismanoid | 58:2fea32db466b | 158 | // SupplyPin VinMax = 2.50 |
whismanoid | 58:2fea32db466b | 159 | // SupplyPin VinMin = 2.50 |
whismanoid | 58:2fea32db466b | 160 | // SupplyPin Function = Digital |
whismanoid | 58:2fea32db466b | 161 | // |
whismanoid | 53:3d5a3d241a5e | 162 | |
whismanoid | 53:3d5a3d241a5e | 163 | // CODE GENERATOR: class constructor definition |
whismanoid | 53:3d5a3d241a5e | 164 | MAX11043::MAX11043(SPI &spi, DigitalOut &cs_pin, // SPI interface |
whismanoid | 53:3d5a3d241a5e | 165 | // CODE GENERATOR: class constructor definition gpio InputPin pins |
whismanoid | 53:3d5a3d241a5e | 166 | DigitalOut &CONVRUN_pin, // Digital Configuration Input to MAX11043 device |
whismanoid | 53:3d5a3d241a5e | 167 | DigitalOut &SHDN_pin, // Digital Configuration Input to MAX11043 device |
whismanoid | 53:3d5a3d241a5e | 168 | DigitalOut &DACSTEP_pin, // Digital Configuration Input to MAX11043 device |
whismanoid | 53:3d5a3d241a5e | 169 | DigitalOut &UP_slash_DWNb_pin, // Digital Configuration Input to MAX11043 device |
whismanoid | 53:3d5a3d241a5e | 170 | // CODE GENERATOR: class constructor definition gpio OutputPin pins |
whismanoid | 69:989e392cf635 | 171 | // MAX11043 ADC Read operations must be synchronized to EOC End Of Conversion |
whismanoid | 69:989e392cf635 | 172 | #if MAX11043_EOC_INTERRUPT_POLLING |
whismanoid | 69:989e392cf635 | 173 | // MAX11043 EOC End Of Conversion input should be InterruptIn(PinName:EOC_pin).fall(onEOCFallingEdge); |
whismanoid | 69:989e392cf635 | 174 | // Workaround using DigitalIn(PinName:EOC_pin) polled to sync with EOC falling edge for ADC reads |
whismanoid | 69:989e392cf635 | 175 | // TODO: onEOCFallingEdge: replace DigitalIn &EOC_pin with PinName EOC_pin, so that I can create an InterruptIn(PinName:EOC_pin) |
whismanoid | 53:3d5a3d241a5e | 176 | DigitalIn &EOC_pin, // Digital Event Output from MAX11043 device |
whismanoid | 69:989e392cf635 | 177 | #else // MAX11043_EOC_INTERRUPT_POLLING |
whismanoid | 69:989e392cf635 | 178 | // MAX11043 EOC End Of Conversion input is InterruptIn(PinName:EOC_pin).fall(onEOCFallingEdge); |
whismanoid | 69:989e392cf635 | 179 | // TODO: onEOCFallingEdge: replace DigitalIn &EOC_pin with PinName EOC_pin, so that I can create an InterruptIn(PinName:EOC_pin) |
whismanoid | 69:989e392cf635 | 180 | InterruptIn &EOC_pin, // Digital Event Output from MAX11043 device |
whismanoid | 69:989e392cf635 | 181 | #endif // MAX11043_EOC_INTERRUPT_POLLING |
whismanoid | 53:3d5a3d241a5e | 182 | // CODE GENERATOR: class constructor definition ic_variant |
whismanoid | 53:3d5a3d241a5e | 183 | MAX11043_ic_t ic_variant) |
whismanoid | 53:3d5a3d241a5e | 184 | // CODE GENERATOR: class constructor initializer list |
whismanoid | 53:3d5a3d241a5e | 185 | : m_spi(spi), m_cs_pin(cs_pin), // SPI interface |
whismanoid | 53:3d5a3d241a5e | 186 | // CODE GENERATOR: class constructor initializer list gpio InputPin pins |
whismanoid | 53:3d5a3d241a5e | 187 | m_CONVRUN_pin(CONVRUN_pin), // Digital Configuration Input to MAX11043 device |
whismanoid | 53:3d5a3d241a5e | 188 | m_SHDN_pin(SHDN_pin), // Digital Configuration Input to MAX11043 device |
whismanoid | 53:3d5a3d241a5e | 189 | m_DACSTEP_pin(DACSTEP_pin), // Digital Configuration Input to MAX11043 device |
whismanoid | 53:3d5a3d241a5e | 190 | m_UP_slash_DWNb_pin(UP_slash_DWNb_pin), // Digital Configuration Input to MAX11043 device |
whismanoid | 53:3d5a3d241a5e | 191 | // CODE GENERATOR: class constructor initializer list gpio OutputPin pins |
whismanoid | 69:989e392cf635 | 192 | // MAX11043 ADC Read operations must be synchronized to EOC End Of Conversion |
whismanoid | 69:989e392cf635 | 193 | #if MAX11043_EOC_INTERRUPT_POLLING |
whismanoid | 69:989e392cf635 | 194 | // MAX11043 EOC End Of Conversion input should be InterruptIn(PinName:EOC_pin).fall(onEOCFallingEdge); |
whismanoid | 69:989e392cf635 | 195 | // Workaround using DigitalIn(PinName:EOC_pin) polled to sync with EOC falling edge for ADC reads |
whismanoid | 53:3d5a3d241a5e | 196 | m_EOC_pin(EOC_pin), // Digital Event Output from MAX11043 device |
whismanoid | 69:989e392cf635 | 197 | #else // MAX11043_EOC_INTERRUPT_POLLING |
whismanoid | 69:989e392cf635 | 198 | // MAX11043 EOC End Of Conversion input is InterruptIn(PinName:EOC_pin).fall(onEOCFallingEdge); |
whismanoid | 70:f44a577c9e59 | 199 | m_EOC_pin(EOC_pin), // Digital Event Output from MAX11043 device |
whismanoid | 69:989e392cf635 | 200 | #endif // MAX11043_EOC_INTERRUPT_POLLING |
whismanoid | 53:3d5a3d241a5e | 201 | // CODE GENERATOR: class constructor initializer list ic_variant |
whismanoid | 53:3d5a3d241a5e | 202 | m_ic_variant(ic_variant) |
whismanoid | 53:3d5a3d241a5e | 203 | { |
whismanoid | 53:3d5a3d241a5e | 204 | // CODE GENERATOR: class constructor definition SPI interface initialization |
whismanoid | 53:3d5a3d241a5e | 205 | // |
whismanoid | 53:3d5a3d241a5e | 206 | // SPI CS = ActiveLow |
whismanoid | 53:3d5a3d241a5e | 207 | // SPI FrameStart = CS |
whismanoid | 53:3d5a3d241a5e | 208 | m_SPI_cs_state = 1; |
whismanoid | 67:5b8a495dda1c | 209 | if (m_cs_pin.is_connected()) { // avoid mbed runtime error if pin is NC not connected |
whismanoid | 67:5b8a495dda1c | 210 | m_cs_pin = m_SPI_cs_state; |
whismanoid | 67:5b8a495dda1c | 211 | } |
whismanoid | 53:3d5a3d241a5e | 212 | |
whismanoid | 53:3d5a3d241a5e | 213 | // SPI CPOL = 0 |
whismanoid | 53:3d5a3d241a5e | 214 | // SPI CPHA = 0 |
whismanoid | 53:3d5a3d241a5e | 215 | // SPI MOSI and MISO Data are both stable on Rising edge of SCLK |
whismanoid | 53:3d5a3d241a5e | 216 | // SPI SCLK Idle Low |
whismanoid | 53:3d5a3d241a5e | 217 | m_SPI_dataMode = 0; //SPI_MODE0; // CPOL=0,CPHA=0: Rising Edge stable; SCLK idle Low |
whismanoid | 53:3d5a3d241a5e | 218 | m_spi.format(8,m_SPI_dataMode); // int bits_must_be_8, int mode=0_3 CPOL=0,CPHA=0 |
whismanoid | 53:3d5a3d241a5e | 219 | |
whismanoid | 53:3d5a3d241a5e | 220 | // SPI SCLKMaxMHz = 40 |
whismanoid | 53:3d5a3d241a5e | 221 | // SPI SCLKMinMHz = 0 |
whismanoid | 53:3d5a3d241a5e | 222 | //#define SPI_SCLK_Hz 48000000 // 48MHz |
whismanoid | 53:3d5a3d241a5e | 223 | //#define SPI_SCLK_Hz 24000000 // 24MHz |
whismanoid | 53:3d5a3d241a5e | 224 | //#define SPI_SCLK_Hz 12000000 // 12MHz |
whismanoid | 53:3d5a3d241a5e | 225 | //#define SPI_SCLK_Hz 6000000 // 6MHz |
whismanoid | 53:3d5a3d241a5e | 226 | //#define SPI_SCLK_Hz 4000000 // 4MHz |
whismanoid | 53:3d5a3d241a5e | 227 | //#define SPI_SCLK_Hz 2000000 // 2MHz |
whismanoid | 53:3d5a3d241a5e | 228 | //#define SPI_SCLK_Hz 1000000 // 1MHz |
whismanoid | 61:b4f3051578ef | 229 | m_SPI_SCLK_Hz = 24000000; // platform limit 24MHz; MAX11043 limit is 40MHz |
whismanoid | 53:3d5a3d241a5e | 230 | m_spi.frequency(m_SPI_SCLK_Hz); |
whismanoid | 53:3d5a3d241a5e | 231 | |
whismanoid | 53:3d5a3d241a5e | 232 | // |
whismanoid | 53:3d5a3d241a5e | 233 | // CODE GENERATOR: class constructor definition gpio InputPin (Input to device) initialization |
whismanoid | 53:3d5a3d241a5e | 234 | // |
whismanoid | 53:3d5a3d241a5e | 235 | // CONVRUN Configuration Input to MAX11043 device |
whismanoid | 53:3d5a3d241a5e | 236 | m_CONVRUN_pin = 1; // output logic high -- initial value in constructor |
whismanoid | 53:3d5a3d241a5e | 237 | // |
whismanoid | 53:3d5a3d241a5e | 238 | // SHDN Configuration Input to MAX11043 device |
whismanoid | 53:3d5a3d241a5e | 239 | m_SHDN_pin = 1; // output logic high -- initial value in constructor |
whismanoid | 53:3d5a3d241a5e | 240 | // |
whismanoid | 53:3d5a3d241a5e | 241 | // DACSTEP Configuration Input to MAX11043 device |
whismanoid | 53:3d5a3d241a5e | 242 | m_DACSTEP_pin = 1; // output logic high -- initial value in constructor |
whismanoid | 53:3d5a3d241a5e | 243 | // |
whismanoid | 53:3d5a3d241a5e | 244 | // UP_slash_DWNb Configuration Input to MAX11043 device |
whismanoid | 53:3d5a3d241a5e | 245 | m_UP_slash_DWNb_pin = 1; // output logic high -- initial value in constructor |
whismanoid | 53:3d5a3d241a5e | 246 | // |
whismanoid | 53:3d5a3d241a5e | 247 | // CODE GENERATOR: class constructor definition gpio OutputPin (Output from MAX11043 device) initialization |
whismanoid | 53:3d5a3d241a5e | 248 | // |
whismanoid | 53:3d5a3d241a5e | 249 | // EOC Event Output from device |
whismanoid | 69:989e392cf635 | 250 | // MAX11043 ADC Read operations must be synchronized to EOC End Of Conversion |
whismanoid | 82:9ea067fad5c3 | 251 | #if MAX11043_ScopeTrigger_MAX32625MBED_D5 |
whismanoid | 82:9ea067fad5c3 | 252 | digitalInOut5.output(); // ScopeTrigger |
whismanoid | 82:9ea067fad5c3 | 253 | #endif // MAX11043_ScopeTrigger_MAX32625MBED_D5 |
whismanoid | 76:0397493d7baf | 254 | #if MAX11043_EOC_INTERRUPT_EVENTQUEUE |
whismanoid | 76:0397493d7baf | 255 | // SPI is not interrupt-safe, so use EventQueue to defer execution to user context. |
whismanoid | 82:9ea067fad5c3 | 256 | #if MAX11043_EOC_INTERRUPT_POLLING |
whismanoid | 82:9ea067fad5c3 | 257 | myOnEOCThread.start(myOnEOCThread_POLLING_handler); |
whismanoid | 82:9ea067fad5c3 | 258 | #else // MAX11043_EOC_INTERRUPT_POLLING |
whismanoid | 82:9ea067fad5c3 | 259 | myOnEOCThread.start(myOnEOCThread_EVENTFLAG_ENABLE_SPI_handler); |
whismanoid | 82:9ea067fad5c3 | 260 | #endif // MAX11043_EOC_INTERRUPT_POLLING |
whismanoid | 76:0397493d7baf | 261 | #else // MAX11043_EOC_INTERRUPT_EVENTQUEUE |
whismanoid | 76:0397493d7baf | 262 | #endif // MAX11043_EOC_INTERRUPT_EVENTQUEUE |
whismanoid | 76:0397493d7baf | 263 | // MAX11043 ADC Read operations must be synchronized to EOC End Of Conversion |
whismanoid | 69:989e392cf635 | 264 | #if MAX11043_EOC_INTERRUPT_POLLING |
whismanoid | 69:989e392cf635 | 265 | // MAX11043 EOC End Of Conversion input should be InterruptIn(PinName:EOC_pin).fall(onEOCFallingEdge); |
whismanoid | 69:989e392cf635 | 266 | // Workaround using DigitalIn(PinName:EOC_pin) polled to sync with EOC falling edge for ADC reads |
whismanoid | 69:989e392cf635 | 267 | #else // MAX11043_EOC_INTERRUPT_POLLING |
whismanoid | 69:989e392cf635 | 268 | // MAX11043 EOC End Of Conversion input is InterruptIn(PinName:EOC_pin).fall(onEOCFallingEdge); |
whismanoid | 69:989e392cf635 | 269 | // TODO: onEOCFallingEdge: interrupt handler requires global object extern MAX11043 g_MAX11043_device |
whismanoid | 71:62bcd01ea87f | 270 | // InterruptIn interruptEOC(EOC_pin); // InterruptIn constructor requires PinName, not DigitalIn -- Error: No instance of constructor "mbed::InterruptIn::InterruptIn" matches the argument list in "MAX11043/MAX11043.cpp", Line: 187, Col: 31 |
whismanoid | 69:989e392cf635 | 271 | // TODO: onEOCFallingEdge: replace DigitalIn &EOC_pin with PinName EOC_pin, so that I can create an InterruptIn(PinName:EOC_pin) |
whismanoid | 70:f44a577c9e59 | 272 | extern void onEOCFallingEdge(void); |
whismanoid | 71:62bcd01ea87f | 273 | // interruptEOC.fall(&onEOCFallingEdge); |
whismanoid | 71:62bcd01ea87f | 274 | EOC_pin.fall(&onEOCFallingEdge); |
whismanoid | 69:989e392cf635 | 275 | #endif // MAX11043_EOC_INTERRUPT_POLLING |
whismanoid | 76:0397493d7baf | 276 | } |
whismanoid | 69:989e392cf635 | 277 | |
whismanoid | 76:0397493d7baf | 278 | // MAX11043 ADC Read operations must be synchronized to EOC End Of Conversion |
whismanoid | 76:0397493d7baf | 279 | // SPI is not interrupt-safe, so use EventQueue to defer execution to user context. |
whismanoid | 76:0397493d7baf | 280 | #if MAX11043_EOC_INTERRUPT_EVENTQUEUE |
whismanoid | 82:9ea067fad5c3 | 281 | #if MAX11043_EOC_INTERRUPT_POLLING |
whismanoid | 82:9ea067fad5c3 | 282 | void myOnEOCThread_POLLING_handler() |
whismanoid | 76:0397493d7baf | 283 | { |
whismanoid | 76:0397493d7baf | 284 | while (true) { |
whismanoid | 80:96bc693e0f79 | 285 | // MAX11043 EOC End Of Conversion input should be InterruptIn(PinName:EOC_pin).fall(onEOCFallingEdge); |
whismanoid | 80:96bc693e0f79 | 286 | // Workaround using DigitalIn(PinName:EOC_pin) polled to sync with EOC falling edge for ADC reads |
whismanoid | 80:96bc693e0f79 | 287 | // poll m_EOC_pin if CONVRUN is high |
whismanoid | 82:9ea067fad5c3 | 288 | //if (m_CONVRUN_pin) |
whismanoid | 82:9ea067fad5c3 | 289 | //{ |
whismanoid | 82:9ea067fad5c3 | 290 | //#warning "myOnEOCThread_handler() Potential infinite loop if EOC pin not connected" |
whismanoid | 80:96bc693e0f79 | 291 | // possible infinite loop; need a timeout or futility countdown to escape |
whismanoid | 82:9ea067fad5c3 | 292 | #if MAX11043_ScopeTrigger_MAX32625MBED_D5 |
whismanoid | 82:9ea067fad5c3 | 293 | // Diagnostic: Use MAX32625MBED pin D5 as DigitalOut EOC#-detected |
whismanoid | 82:9ea067fad5c3 | 294 | //~ digitalInOut5.write(0); // ScopeTrigger low -- waiting for EOC# high |
whismanoid | 82:9ea067fad5c3 | 295 | //~ digitalInOut5.write(1); // ScopeTrigger |
whismanoid | 82:9ea067fad5c3 | 296 | //~ digitalInOut5.write(0); // ScopeTrigger |
whismanoid | 82:9ea067fad5c3 | 297 | //~ digitalInOut5.write(1); // ScopeTrigger |
whismanoid | 82:9ea067fad5c3 | 298 | #endif // MAX11043_ScopeTrigger_MAX32625MBED_D5 |
whismanoid | 82:9ea067fad5c3 | 299 | //for (int futility_countdown = 100; |
whismanoid | 82:9ea067fad5c3 | 300 | // ((futility_countdown > 0) && |
whismanoid | 82:9ea067fad5c3 | 301 | // (m_EOC_pin != 1)); |
whismanoid | 82:9ea067fad5c3 | 302 | // futility_countdown--) |
whismanoid | 82:9ea067fad5c3 | 303 | //while (digitalInOut2.read() != 1) // digitalInOut2 m_EOC_pin |
whismanoid | 82:9ea067fad5c3 | 304 | //{ |
whismanoid | 82:9ea067fad5c3 | 305 | // // spinlock waiting for logic high pin state (start of new conversion) |
whismanoid | 82:9ea067fad5c3 | 306 | //} |
whismanoid | 82:9ea067fad5c3 | 307 | #if MAX11043_ScopeTrigger_MAX32625MBED_D5 |
whismanoid | 82:9ea067fad5c3 | 308 | // Diagnostic: Use MAX32625MBED pin D5 as DigitalOut EOC#-detected |
whismanoid | 82:9ea067fad5c3 | 309 | //~ digitalInOut5.write(0); // ScopeTrigger |
whismanoid | 82:9ea067fad5c3 | 310 | //~ digitalInOut5.write(1); // ScopeTrigger high -- waiting for EOC# falling edge |
whismanoid | 82:9ea067fad5c3 | 311 | //~ digitalInOut5.write(0); // ScopeTrigger |
whismanoid | 82:9ea067fad5c3 | 312 | //~ digitalInOut5.write(1); // ScopeTrigger |
whismanoid | 82:9ea067fad5c3 | 313 | #endif // MAX11043_ScopeTrigger_MAX32625MBED_D5 |
whismanoid | 82:9ea067fad5c3 | 314 | //for (int futility_countdown = 100; |
whismanoid | 82:9ea067fad5c3 | 315 | // ((futility_countdown > 0) && |
whismanoid | 82:9ea067fad5c3 | 316 | // (m_EOC_pin != 0)); |
whismanoid | 82:9ea067fad5c3 | 317 | // futility_countdown--) |
whismanoid | 82:9ea067fad5c3 | 318 | while (digitalInOut2.read() != 0) // digitalInOut2 m_EOC_pin |
whismanoid | 80:96bc693e0f79 | 319 | { |
whismanoid | 80:96bc693e0f79 | 320 | // spinlock waiting for logic low pin state (new data is available) |
whismanoid | 80:96bc693e0f79 | 321 | } |
whismanoid | 82:9ea067fad5c3 | 322 | //} |
whismanoid | 82:9ea067fad5c3 | 323 | //else |
whismanoid | 82:9ea067fad5c3 | 324 | //{ |
whismanoid | 82:9ea067fad5c3 | 325 | // // CONVRUN pin is being driven low, so conversion result will not change, EOC# remains high |
whismanoid | 82:9ea067fad5c3 | 326 | // continue; |
whismanoid | 82:9ea067fad5c3 | 327 | //} |
whismanoid | 82:9ea067fad5c3 | 328 | // |
whismanoid | 82:9ea067fad5c3 | 329 | //extern MAX11043 g_MAX11043_device; |
whismanoid | 82:9ea067fad5c3 | 330 | #if MAX11043_ScopeTrigger_MAX32625MBED_D5 |
whismanoid | 82:9ea067fad5c3 | 331 | // Diagnostic: Use MAX32625MBED pin D5 as DigitalOut EOC#-detected |
whismanoid | 82:9ea067fad5c3 | 332 | //~ digitalInOut5.write(0); // ScopeTrigger low -- EOC# falling edge detected, about to start SPI |
whismanoid | 82:9ea067fad5c3 | 333 | //~ digitalInOut5.write(1); // ScopeTrigger |
whismanoid | 82:9ea067fad5c3 | 334 | //~ digitalInOut5.write(0); // ScopeTrigger |
whismanoid | 82:9ea067fad5c3 | 335 | //~ digitalInOut5.write(1); // ScopeTrigger |
whismanoid | 82:9ea067fad5c3 | 336 | #endif // MAX11043_ScopeTrigger_MAX32625MBED_D5 |
whismanoid | 82:9ea067fad5c3 | 337 | extern SPI spi; // declared in Test_Main_MAX11043.cpp |
whismanoid | 82:9ea067fad5c3 | 338 | spi.write((char*)mosiData_onEOCFallingEdge, byteCount_onEOCFallingEdge, (char*)misoData_onEOCFallingEdge, byteCount_onEOCFallingEdge); |
whismanoid | 82:9ea067fad5c3 | 339 | // Note: EOC# is high immediately after SPI read ADCabcd |
whismanoid | 82:9ea067fad5c3 | 340 | // SPI timing: CS low 13.30us after EOC# falling edge |
whismanoid | 82:9ea067fad5c3 | 341 | // SPI timing: SCLK first 14.60us after EOC# falling edge |
whismanoid | 82:9ea067fad5c3 | 342 | // SPI timing: SCLK last 17.70us after EOC# falling edge |
whismanoid | 82:9ea067fad5c3 | 343 | // SPI timing: CS high 17.70us after EOC# falling edge |
whismanoid | 82:9ea067fad5c3 | 344 | // |
whismanoid | 82:9ea067fad5c3 | 345 | // TODO1: update adca |
whismanoid | 82:9ea067fad5c3 | 346 | //g_MAX11043_device.adca = (misoData_onEOCFallingEdge[1] << 8) | misoData_onEOCFallingEdge[2]; |
whismanoid | 82:9ea067fad5c3 | 347 | // TODO1: update adcb |
whismanoid | 82:9ea067fad5c3 | 348 | //g_MAX11043_device.adcb = (misoData_onEOCFallingEdge[3] << 8) | misoData_onEOCFallingEdge[4]; |
whismanoid | 82:9ea067fad5c3 | 349 | // TODO1: update adcc |
whismanoid | 82:9ea067fad5c3 | 350 | //g_MAX11043_device.adcc = (misoData_onEOCFallingEdge[5] << 8) | misoData_onEOCFallingEdge[6]; |
whismanoid | 82:9ea067fad5c3 | 351 | // TODO1: update adcd |
whismanoid | 82:9ea067fad5c3 | 352 | //g_MAX11043_device.adcd = (misoData_onEOCFallingEdge[7] << 8) | misoData_onEOCFallingEdge[8]; |
whismanoid | 82:9ea067fad5c3 | 353 | #if MAX11043_ScopeTrigger_MAX32625MBED_D5 |
whismanoid | 82:9ea067fad5c3 | 354 | // Diagnostic: Use MAX32625MBED pin D5 as DigitalOut EOC#-detected |
whismanoid | 82:9ea067fad5c3 | 355 | //~ digitalInOut5.write(0); // ScopeTrigger |
whismanoid | 82:9ea067fad5c3 | 356 | //~ digitalInOut5.write(1); // ScopeTrigger high -- end of while loop |
whismanoid | 82:9ea067fad5c3 | 357 | //~ digitalInOut5.write(0); // ScopeTrigger |
whismanoid | 82:9ea067fad5c3 | 358 | //~ digitalInOut5.write(1); // ScopeTrigger |
whismanoid | 82:9ea067fad5c3 | 359 | #endif // MAX11043_ScopeTrigger_MAX32625MBED_D5 |
whismanoid | 82:9ea067fad5c3 | 360 | } // while (true) |
whismanoid | 82:9ea067fad5c3 | 361 | } // myOnEOCThread_POLLING_handler() |
whismanoid | 80:96bc693e0f79 | 362 | #else // MAX11043_EOC_INTERRUPT_POLLING |
whismanoid | 82:9ea067fad5c3 | 363 | // Waiting for EOC# fall to signal EventQueue is too slow, ~25us to handle event but events happen every 9us. |
whismanoid | 82:9ea067fad5c3 | 364 | void myOnEOCThread_EVENTFLAG_ENABLE_SPI_handler() |
whismanoid | 82:9ea067fad5c3 | 365 | { |
whismanoid | 82:9ea067fad5c3 | 366 | while (true) { |
whismanoid | 80:96bc693e0f79 | 367 | // MAX11043 EOC End Of Conversion input is InterruptIn(PinName:EOC_pin).fall(onEOCFallingEdge); |
whismanoid | 80:96bc693e0f79 | 368 | // Interrupt Handler: EOC Event Output from device |
whismanoid | 80:96bc693e0f79 | 369 | // Wait for MYONEOCTHREADEVENTFLAG_ENABLE_SPI event sent from onEOCFallingEdge interrupt |
whismanoid | 76:0397493d7baf | 370 | //signal_wait(int32_t signals, uint32_t millisec=osWaitForever) |
whismanoid | 76:0397493d7baf | 371 | //flags_read = myOnEOCThread_event_flags.wait_any(MYONEOCTHREADEVENTFLAG_ENABLE_SPI); |
whismanoid | 76:0397493d7baf | 372 | // myOnEOCThread_event_flags.wait_any(MYONEOCTHREADEVENTFLAG_ENABLE_SPI, osWaitForever, false); // clear=false: don't auto clear the flag |
whismanoid | 76:0397493d7baf | 373 | myOnEOCThread_event_flags.wait_any(MYONEOCTHREADEVENTFLAG_ENABLE_SPI, osWaitForever, true); // clear=true: auto clear the flag |
whismanoid | 76:0397493d7baf | 374 | // |
whismanoid | 82:9ea067fad5c3 | 375 | //extern MAX11043 g_MAX11043_device; |
whismanoid | 76:0397493d7baf | 376 | #if MAX11043_ScopeTrigger_MAX32625MBED_D5 |
whismanoid | 76:0397493d7baf | 377 | // Diagnostic: Use MAX32625MBED pin D5 as DigitalOut EOC#-detected |
whismanoid | 77:3a6e2a5cd7d9 | 378 | digitalInOut5.write(0); // ScopeTrigger happens at 1.8us after EOC# falling edge |
whismanoid | 76:0397493d7baf | 379 | digitalInOut5.write(1); // ScopeTrigger |
whismanoid | 76:0397493d7baf | 380 | digitalInOut5.write(0); // ScopeTrigger |
whismanoid | 76:0397493d7baf | 381 | digitalInOut5.write(1); // ScopeTrigger |
whismanoid | 76:0397493d7baf | 382 | #endif // MAX11043_ScopeTrigger_MAX32625MBED_D5 |
whismanoid | 76:0397493d7baf | 383 | extern SPI spi; // declared in Test_Main_MAX11043.cpp |
whismanoid | 76:0397493d7baf | 384 | spi.write((char*)mosiData_onEOCFallingEdge, byteCount_onEOCFallingEdge, (char*)misoData_onEOCFallingEdge, byteCount_onEOCFallingEdge); |
whismanoid | 77:3a6e2a5cd7d9 | 385 | // SPI timing: CS low 13.30us after EOC# falling edge |
whismanoid | 77:3a6e2a5cd7d9 | 386 | // SPI timing: SCLK first 14.60us after EOC# falling edge |
whismanoid | 77:3a6e2a5cd7d9 | 387 | // SPI timing: SCLK last 17.70us after EOC# falling edge |
whismanoid | 77:3a6e2a5cd7d9 | 388 | // SPI timing: CS high 17.70us after EOC# falling edge |
whismanoid | 77:3a6e2a5cd7d9 | 389 | // |
whismanoid | 76:0397493d7baf | 390 | // TODO1: update adca |
whismanoid | 76:0397493d7baf | 391 | //g_MAX11043_device.adca = (misoData_onEOCFallingEdge[1] << 8) | misoData_onEOCFallingEdge[2]; |
whismanoid | 76:0397493d7baf | 392 | // TODO1: update adcb |
whismanoid | 76:0397493d7baf | 393 | //g_MAX11043_device.adcb = (misoData_onEOCFallingEdge[3] << 8) | misoData_onEOCFallingEdge[4]; |
whismanoid | 76:0397493d7baf | 394 | // TODO1: update adcc |
whismanoid | 76:0397493d7baf | 395 | //g_MAX11043_device.adcc = (misoData_onEOCFallingEdge[5] << 8) | misoData_onEOCFallingEdge[6]; |
whismanoid | 76:0397493d7baf | 396 | // TODO1: update adcd |
whismanoid | 76:0397493d7baf | 397 | //g_MAX11043_device.adcd = (misoData_onEOCFallingEdge[7] << 8) | misoData_onEOCFallingEdge[8]; |
whismanoid | 77:3a6e2a5cd7d9 | 398 | #if MAX11043_ScopeTrigger_MAX32625MBED_D5 |
whismanoid | 77:3a6e2a5cd7d9 | 399 | // Diagnostic: Use MAX32625MBED pin D5 as DigitalOut EOC#-detected |
whismanoid | 77:3a6e2a5cd7d9 | 400 | digitalInOut5.write(0); // ScopeTrigger happens at 22.5us after EOC# falling edge |
whismanoid | 77:3a6e2a5cd7d9 | 401 | digitalInOut5.write(1); // ScopeTrigger |
whismanoid | 77:3a6e2a5cd7d9 | 402 | digitalInOut5.write(0); // ScopeTrigger |
whismanoid | 77:3a6e2a5cd7d9 | 403 | digitalInOut5.write(1); // ScopeTrigger |
whismanoid | 77:3a6e2a5cd7d9 | 404 | #endif // MAX11043_ScopeTrigger_MAX32625MBED_D5 |
whismanoid | 80:96bc693e0f79 | 405 | } // while (true) |
whismanoid | 82:9ea067fad5c3 | 406 | } // myOnEOCThread_EVENTFLAG_ENABLE_SPI_handler() |
whismanoid | 82:9ea067fad5c3 | 407 | #endif // MAX11043_EOC_INTERRUPT_POLLING |
whismanoid | 76:0397493d7baf | 408 | #endif // MAX11043_EOC_INTERRUPT_EVENTQUEUE |
whismanoid | 53:3d5a3d241a5e | 409 | |
whismanoid | 69:989e392cf635 | 410 | // MAX11043 ADC Read operations must be synchronized to EOC End Of Conversion |
whismanoid | 69:989e392cf635 | 411 | #if MAX11043_EOC_INTERRUPT_POLLING |
whismanoid | 69:989e392cf635 | 412 | // MAX11043 EOC End Of Conversion input should be InterruptIn(PinName:EOC_pin).fall(onEOCFallingEdge); |
whismanoid | 69:989e392cf635 | 413 | // Workaround using DigitalIn(PinName:EOC_pin) polled to sync with EOC falling edge for ADC reads |
whismanoid | 69:989e392cf635 | 414 | #else // MAX11043_EOC_INTERRUPT_POLLING |
whismanoid | 69:989e392cf635 | 415 | // MAX11043 EOC End Of Conversion input is InterruptIn(PinName:EOC_pin).fall(onEOCFallingEdge); |
whismanoid | 69:989e392cf635 | 416 | // Interrupt Handler: EOC Event Output from device |
whismanoid | 69:989e392cf635 | 417 | void onEOCFallingEdge(void) |
whismanoid | 69:989e392cf635 | 418 | { |
whismanoid | 72:40feab5fd579 | 419 | // VERIFIED: if DO NOTHING inside interrupt service routine, no crash |
whismanoid | 72:40feab5fd579 | 420 | #if 1 |
whismanoid | 72:40feab5fd579 | 421 | // VERIFIED: GPIO PIN pulse in response to EOC# falling edge, no crash on HH, no missed pulses |
whismanoid | 73:879578472009 | 422 | #if MAX11043_ScopeTrigger_MAX32625MBED_D5 |
whismanoid | 73:879578472009 | 423 | // Diagnostic: Use MAX32625MBED pin D5 as DigitalOut EOC#-detected |
whismanoid | 74:f4f969c9a7a9 | 424 | digitalInOut5.write(0); // ScopeTrigger 1.8us after EOC# falling edge |
whismanoid | 74:f4f969c9a7a9 | 425 | digitalInOut5.write(1); // ScopeTrigger |
whismanoid | 74:f4f969c9a7a9 | 426 | digitalInOut5.write(0); // ScopeTrigger |
whismanoid | 74:f4f969c9a7a9 | 427 | digitalInOut5.write(1); // ScopeTrigger |
whismanoid | 73:879578472009 | 428 | #endif // MAX11043_ScopeTrigger_MAX32625MBED_D5 |
whismanoid | 72:40feab5fd579 | 429 | #endif |
whismanoid | 76:0397493d7baf | 430 | #if MAX11043_EOC_INTERRUPT_EVENTQUEUE |
whismanoid | 76:0397493d7baf | 431 | // SPI is not interrupt-safe, so use EventQueue to defer execution to user context. |
whismanoid | 76:0397493d7baf | 432 | myOnEOCThread_event_flags.set(MYONEOCTHREADEVENTFLAG_ENABLE_SPI); |
whismanoid | 76:0397493d7baf | 433 | #else // MAX11043_EOC_INTERRUPT_EVENTQUEUE |
whismanoid | 76:0397493d7baf | 434 | #endif // MAX11043_EOC_INTERRUPT_EVENTQUEUE |
whismanoid | 76:0397493d7baf | 435 | #if 0 |
whismanoid | 72:40feab5fd579 | 436 | // TODO: read 4 channels in response to EOC# falling edge |
whismanoid | 72:40feab5fd579 | 437 | // WIP MAX11043 interrupt CRASH on Menu item HH CONVRUN High |
whismanoid | 72:40feab5fd579 | 438 | // |
whismanoid | 72:40feab5fd579 | 439 | // ++ MbedOS Error Info ++ |
whismanoid | 72:40feab5fd579 | 440 | // Error Status: 0x80020115 Code: 277 Module: 2 |
whismanoid | 72:40feab5fd579 | 441 | // Error Message: Mutex lock failed |
whismanoid | 72:40feab5fd579 | 442 | // Location: 0xBA33 |
whismanoid | 72:40feab5fd579 | 443 | // Error Value: 0xFFFFFFFA |
whismanoid | 72:40feab5fd579 | 444 | // Current Thread: main Id: 0x20002CD0 Entry: 0xBD17 StackSize: 0x1000 StackMem: 0x20001CD0 SP: 0x20027ED0 |
whismanoid | 72:40feab5fd579 | 445 | // For more info, visit: https://armmbed.github.io/mbedos-error/?error=0x80020115 |
whismanoid | 72:40feab5fd579 | 446 | // -- MbedOS Error Info -- |
whismanoid | 69:989e392cf635 | 447 | extern MAX11043 g_MAX11043_device; |
whismanoid | 75:0900a57f2e5d | 448 | //~ g_MAX11043_device.Read_ADCabcd(); |
whismanoid | 74:f4f969c9a7a9 | 449 | // read register ADCabcd -> &adca, &adcb, &adcc, &adcd |
whismanoid | 74:f4f969c9a7a9 | 450 | // g_MAX11043_device.RegRead(CMD_0001_1010_d16o8_d16o8_d16o8_d16o8_Rd06_ADCabcd, 0); |
whismanoid | 75:0900a57f2e5d | 451 | // SPI 8+64 = 72-bit transfer |
whismanoid | 75:0900a57f2e5d | 452 | // 1234 5678 ___[1]_16 ___[2]_24 ___[3]_32 ___[4]_40 ___[5]_48 ___[6]_56 ___[7]_64 ___[8]_72 |
whismanoid | 75:0900a57f2e5d | 453 | // SPI MOSI = 1aaa_aaaa_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000 ... _0000 |
whismanoid | 75:0900a57f2e5d | 454 | // SPI MISO = xxxx_xxxx_dddd_dddd_dddd_dddd_dddd_dddd_dddd_dddd_dddd_dddd_dddd_dddd_dddd_dddd_dddd_dddd ... _xxxx |
whismanoid | 75:0900a57f2e5d | 455 | // global const size_t byteCount_onEOCFallingEdge = 1 + (2 * 4); |
whismanoid | 75:0900a57f2e5d | 456 | // global const uint8_t mosiData_onEOCFallingEdge[9] = { |
whismanoid | 75:0900a57f2e5d | 457 | // global CMD_0001_1010_d16o8_d16o8_d16o8_d16o8_Rd06_ADCabcd, |
whismanoid | 75:0900a57f2e5d | 458 | // global 0, 0, 0, 0, 0, 0, 0, 0 |
whismanoid | 75:0900a57f2e5d | 459 | // global }; |
whismanoid | 75:0900a57f2e5d | 460 | // global uint8_t misoData_onEOCFallingEdge[9]; |
whismanoid | 75:0900a57f2e5d | 461 | // SPIreadWriteWithLowCS(size_t byteCount, uint8_t mosiData[], uint8_t misoData[]); |
whismanoid | 75:0900a57f2e5d | 462 | // SPIreadWriteWithLowCS(byteCount_onEOCFallingEdge, mosiData_onEOCFallingEdge, misoData_onEOCFallingEdge); |
whismanoid | 75:0900a57f2e5d | 463 | // onSPIprint() is not interrupt-safe |
whismanoid | 75:0900a57f2e5d | 464 | // unsigned int numBytesTransferred = m_spi.write((char*)mosiData, byteCount, (char*)misoData, byteCount); |
whismanoid | 75:0900a57f2e5d | 465 | // g_MAX11043_device.m_spi is inaccessible |
whismanoid | 75:0900a57f2e5d | 466 | extern SPI spi; // declared in Test_Main_MAX11043.cpp |
whismanoid | 75:0900a57f2e5d | 467 | spi.write((char*)mosiData_onEOCFallingEdge, byteCount_onEOCFallingEdge, (char*)misoData_onEOCFallingEdge, byteCount_onEOCFallingEdge); |
whismanoid | 75:0900a57f2e5d | 468 | // |
whismanoid | 75:0900a57f2e5d | 469 | // ++ MbedOS Error Info ++ |
whismanoid | 75:0900a57f2e5d | 470 | // Error Status: 0x80020115 Code: 277 Module: 2 |
whismanoid | 75:0900a57f2e5d | 471 | // Error Message: Mutex lock failed |
whismanoid | 75:0900a57f2e5d | 472 | // Location: 0xBABB |
whismanoid | 75:0900a57f2e5d | 473 | // Error Value: 0xFFFFFFFA |
whismanoid | 75:0900a57f2e5d | 474 | // Current Thread: main Id: 0x20002CD0 Entry: 0xBD9F StackSize: 0x1000 StackMem: 0x20001CD0 SP: 0x20027F10 |
whismanoid | 75:0900a57f2e5d | 475 | // For more info, visit: https://armmbed.github.io/mbedos-error/?error=0x80020115 |
whismanoid | 75:0900a57f2e5d | 476 | // -- MbedOS Error Info -- |
whismanoid | 75:0900a57f2e5d | 477 | // |
whismanoid | 75:0900a57f2e5d | 478 | //if (ptrRegData) { (*ptrRegData) = (misoData[1] << 8) | misoData[2]; } |
whismanoid | 75:0900a57f2e5d | 479 | //if (commandByte == CMD_0001_1010_d16o8_d16o8_d16o8_d16o8_Rd06_ADCabcd) { |
whismanoid | 75:0900a57f2e5d | 480 | // TODO1: update adca |
whismanoid | 75:0900a57f2e5d | 481 | //g_MAX11043_device.adca = (misoData_onEOCFallingEdge[1] << 8) | misoData_onEOCFallingEdge[2]; |
whismanoid | 75:0900a57f2e5d | 482 | // TODO1: update adcb |
whismanoid | 75:0900a57f2e5d | 483 | //g_MAX11043_device.adcb = (misoData_onEOCFallingEdge[3] << 8) | misoData_onEOCFallingEdge[4]; |
whismanoid | 75:0900a57f2e5d | 484 | // TODO1: update adcc |
whismanoid | 75:0900a57f2e5d | 485 | //g_MAX11043_device.adcc = (misoData_onEOCFallingEdge[5] << 8) | misoData_onEOCFallingEdge[6]; |
whismanoid | 75:0900a57f2e5d | 486 | // TODO1: update adcd |
whismanoid | 75:0900a57f2e5d | 487 | //g_MAX11043_device.adcd = (misoData_onEOCFallingEdge[7] << 8) | misoData_onEOCFallingEdge[8]; |
whismanoid | 75:0900a57f2e5d | 488 | //} |
whismanoid | 72:40feab5fd579 | 489 | #endif |
whismanoid | 76:0397493d7baf | 490 | #if 0 // MAX11043_ScopeTrigger_MAX32625MBED_D5 |
whismanoid | 75:0900a57f2e5d | 491 | // Diagnostic: Use MAX32625MBED pin D5 as DigitalOut EOC#-detected |
whismanoid | 75:0900a57f2e5d | 492 | digitalInOut5.write(0); // ScopeTrigger |
whismanoid | 75:0900a57f2e5d | 493 | digitalInOut5.write(1); // ScopeTrigger |
whismanoid | 75:0900a57f2e5d | 494 | #endif // MAX11043_ScopeTrigger_MAX32625MBED_D5 |
whismanoid | 69:989e392cf635 | 495 | } |
whismanoid | 69:989e392cf635 | 496 | #endif // MAX11043_EOC_INTERRUPT_POLLING |
whismanoid | 69:989e392cf635 | 497 | |
whismanoid | 53:3d5a3d241a5e | 498 | // CODE GENERATOR: class destructor definition |
whismanoid | 53:3d5a3d241a5e | 499 | MAX11043::~MAX11043() |
whismanoid | 53:3d5a3d241a5e | 500 | { |
whismanoid | 53:3d5a3d241a5e | 501 | // do nothing |
whismanoid | 53:3d5a3d241a5e | 502 | } |
whismanoid | 53:3d5a3d241a5e | 503 | |
whismanoid | 53:3d5a3d241a5e | 504 | // CODE GENERATOR: spi_frequency setter definition |
whismanoid | 53:3d5a3d241a5e | 505 | /// set SPI SCLK frequency |
whismanoid | 53:3d5a3d241a5e | 506 | void MAX11043::spi_frequency(int spi_sclk_Hz) |
whismanoid | 53:3d5a3d241a5e | 507 | { |
whismanoid | 53:3d5a3d241a5e | 508 | m_SPI_SCLK_Hz = spi_sclk_Hz; |
whismanoid | 53:3d5a3d241a5e | 509 | m_spi.frequency(m_SPI_SCLK_Hz); |
whismanoid | 53:3d5a3d241a5e | 510 | } |
whismanoid | 53:3d5a3d241a5e | 511 | |
whismanoid | 53:3d5a3d241a5e | 512 | // CODE GENERATOR: omit global g_MAX11043_device |
whismanoid | 53:3d5a3d241a5e | 513 | // CODE GENERATOR: extern function declarations |
whismanoid | 53:3d5a3d241a5e | 514 | // CODE GENERATOR: extern function requirement MAX11043::SPIoutputCS |
whismanoid | 53:3d5a3d241a5e | 515 | // Assert SPI Chip Select |
whismanoid | 53:3d5a3d241a5e | 516 | // SPI chip-select for MAX11043 |
whismanoid | 53:3d5a3d241a5e | 517 | // |
whismanoid | 62:8223a7253c90 | 518 | inline void MAX11043::SPIoutputCS(int isLogicHigh) |
whismanoid | 53:3d5a3d241a5e | 519 | { |
whismanoid | 53:3d5a3d241a5e | 520 | // CODE GENERATOR: extern function definition for function SPIoutputCS |
whismanoid | 53:3d5a3d241a5e | 521 | // CODE GENERATOR: extern function definition for standard SPI interface function SPIoutputCS(int isLogicHigh) |
whismanoid | 53:3d5a3d241a5e | 522 | m_SPI_cs_state = isLogicHigh; |
whismanoid | 67:5b8a495dda1c | 523 | if (m_cs_pin.is_connected()) { // avoid mbed runtime error if pin is NC not connected |
whismanoid | 67:5b8a495dda1c | 524 | m_cs_pin = m_SPI_cs_state; |
whismanoid | 67:5b8a495dda1c | 525 | } |
whismanoid | 53:3d5a3d241a5e | 526 | } |
whismanoid | 53:3d5a3d241a5e | 527 | |
whismanoid | 62:8223a7253c90 | 528 | // CODE GENERATOR: extern function requirement MAX11043::SPIreadWriteWithLowCS |
whismanoid | 62:8223a7253c90 | 529 | // SPI read and write arbitrary number of 8-bit bytes |
whismanoid | 62:8223a7253c90 | 530 | // SPI interface to MAX11043 shift mosiData into MAX11043 DIN |
whismanoid | 62:8223a7253c90 | 531 | // while simultaneously capturing miso data from MAX11043 DOUT |
whismanoid | 62:8223a7253c90 | 532 | // |
whismanoid | 62:8223a7253c90 | 533 | int MAX11043::SPIreadWriteWithLowCS(size_t byteCount, uint8_t mosiData[], uint8_t misoData[]) |
whismanoid | 62:8223a7253c90 | 534 | { |
whismanoid | 62:8223a7253c90 | 535 | // CODE GENERATOR: extern function definition for function SPIreadWriteWithLowCS |
whismanoid | 63:8f39d21d6157 | 536 | // TODO1: CODE GENERATOR: extern function definition for standard SPI interface function SPIreadWriteWithLowCS(size_t byteCount, uint8_t mosiData[], uint8_t misoData[]) |
whismanoid | 62:8223a7253c90 | 537 | //size_t byteCount = 4; |
whismanoid | 62:8223a7253c90 | 538 | //static char mosiData[4]; |
whismanoid | 62:8223a7253c90 | 539 | //static char misoData[4]; |
whismanoid | 62:8223a7253c90 | 540 | // |
whismanoid | 62:8223a7253c90 | 541 | // Arduino: begin critical section: noInterrupts() masks all interrupt sources; end critical section with interrupts() |
whismanoid | 62:8223a7253c90 | 542 | //~ noInterrupts(); |
whismanoid | 62:8223a7253c90 | 543 | // |
whismanoid | 62:8223a7253c90 | 544 | //~ digitalWrite(Scope_Trigger_Pin, LOW); // diagnostic Scope_Trigger_Pin |
whismanoid | 62:8223a7253c90 | 545 | // |
whismanoid | 67:5b8a495dda1c | 546 | if (m_cs_pin.is_connected()) { // avoid mbed runtime error if pin is NC not connected |
whismanoid | 67:5b8a495dda1c | 547 | m_cs_pin = 0; |
whismanoid | 67:5b8a495dda1c | 548 | } |
whismanoid | 62:8223a7253c90 | 549 | unsigned int numBytesTransferred = m_spi.write((char*)mosiData, byteCount, (char*)misoData, byteCount); |
whismanoid | 67:5b8a495dda1c | 550 | if (m_cs_pin.is_connected()) { // avoid mbed runtime error if pin is NC not connected |
whismanoid | 67:5b8a495dda1c | 551 | m_cs_pin = m_SPI_cs_state; |
whismanoid | 67:5b8a495dda1c | 552 | } |
whismanoid | 62:8223a7253c90 | 553 | // |
whismanoid | 62:8223a7253c90 | 554 | //~ digitalWrite(Scope_Trigger_Pin, HIGH); // diagnostic Scope_Trigger_Pin |
whismanoid | 62:8223a7253c90 | 555 | // |
whismanoid | 62:8223a7253c90 | 556 | // Arduino: begin critical section: noInterrupts() masks all interrupt sources; end critical section with interrupts() |
whismanoid | 62:8223a7253c90 | 557 | //~ interrupts(); |
whismanoid | 62:8223a7253c90 | 558 | // Optional Diagnostic function to print SPI transactions |
whismanoid | 62:8223a7253c90 | 559 | if (onSPIprint) |
whismanoid | 62:8223a7253c90 | 560 | { |
whismanoid | 62:8223a7253c90 | 561 | onSPIprint(byteCount, (uint8_t*)mosiData, (uint8_t*)misoData); |
whismanoid | 62:8223a7253c90 | 562 | } |
whismanoid | 62:8223a7253c90 | 563 | return numBytesTransferred; |
whismanoid | 62:8223a7253c90 | 564 | } |
whismanoid | 62:8223a7253c90 | 565 | |
whismanoid | 53:3d5a3d241a5e | 566 | // TODO1: CODE GENERATOR: extern function GPIOoutputSHDN alias SHDNoutputValue |
whismanoid | 53:3d5a3d241a5e | 567 | // CODE GENERATOR: extern function requirement MAX11043::SHDNoutputValue |
whismanoid | 58:2fea32db466b | 568 | // Assert MAX11043 SHDN pin : High = Shut Down, Low = Normal Operation. |
whismanoid | 53:3d5a3d241a5e | 569 | // |
whismanoid | 53:3d5a3d241a5e | 570 | void MAX11043::SHDNoutputValue(int isLogicHigh) |
whismanoid | 53:3d5a3d241a5e | 571 | { |
whismanoid | 53:3d5a3d241a5e | 572 | // CODE GENERATOR: extern function definition for function SHDNoutputValue |
whismanoid | 53:3d5a3d241a5e | 573 | // TODO1: CODE GENERATOR: extern function definition for gpio interface function SHDNoutputValue |
whismanoid | 53:3d5a3d241a5e | 574 | // TODO1: CODE GENERATOR: gpio pin SHDN assuming member function m_SHDN_pin |
whismanoid | 53:3d5a3d241a5e | 575 | // TODO1: CODE GENERATOR: gpio direction output |
whismanoid | 53:3d5a3d241a5e | 576 | // m_SHDN_pin.output(); // only applicable to DigitalInOut |
whismanoid | 53:3d5a3d241a5e | 577 | // TODO1: CODE GENERATOR: gpio function Value |
whismanoid | 53:3d5a3d241a5e | 578 | m_SHDN_pin = isLogicHigh; |
whismanoid | 53:3d5a3d241a5e | 579 | } |
whismanoid | 52:607010f0c54e | 580 | |
whismanoid | 53:3d5a3d241a5e | 581 | // TODO1: CODE GENERATOR: extern function GPIOoutputCONVRUN alias CONVRUNoutputValue |
whismanoid | 53:3d5a3d241a5e | 582 | // CODE GENERATOR: extern function requirement MAX11043::CONVRUNoutputValue |
whismanoid | 58:2fea32db466b | 583 | // Assert MAX11043 CONVRUN pin : High = start continuous conversions on all 4 channels, Low = Idle. |
whismanoid | 53:3d5a3d241a5e | 584 | // |
whismanoid | 53:3d5a3d241a5e | 585 | void MAX11043::CONVRUNoutputValue(int isLogicHigh) |
whismanoid | 53:3d5a3d241a5e | 586 | { |
whismanoid | 53:3d5a3d241a5e | 587 | // CODE GENERATOR: extern function definition for function CONVRUNoutputValue |
whismanoid | 53:3d5a3d241a5e | 588 | // TODO1: CODE GENERATOR: extern function definition for gpio interface function CONVRUNoutputValue |
whismanoid | 53:3d5a3d241a5e | 589 | // TODO1: CODE GENERATOR: gpio pin CONVRUN assuming member function m_CONVRUN_pin |
whismanoid | 53:3d5a3d241a5e | 590 | // TODO1: CODE GENERATOR: gpio direction output |
whismanoid | 53:3d5a3d241a5e | 591 | // m_CONVRUN_pin.output(); // only applicable to DigitalInOut |
whismanoid | 53:3d5a3d241a5e | 592 | // TODO1: CODE GENERATOR: gpio function Value |
whismanoid | 53:3d5a3d241a5e | 593 | m_CONVRUN_pin = isLogicHigh; |
whismanoid | 69:989e392cf635 | 594 | //-------------------------------------------------- |
whismanoid | 69:989e392cf635 | 595 | // MAX11043 ADC Read operations must be synchronized to EOC End Of Conversion |
whismanoid | 69:989e392cf635 | 596 | // EOC# asserts low when new data is available. |
whismanoid | 69:989e392cf635 | 597 | // Initiate a data read prior to the next rising edge of EOC# or the result is overwritten. |
whismanoid | 69:989e392cf635 | 598 | #if MAX11043_EOC_INTERRUPT_POLLING |
whismanoid | 69:989e392cf635 | 599 | // MAX11043 EOC End Of Conversion input should be InterruptIn(PinName:EOC_pin).fall(onEOCFallingEdge); |
whismanoid | 69:989e392cf635 | 600 | // Workaround using DigitalIn(PinName:EOC_pin) polled to sync with EOC falling edge for ADC reads |
whismanoid | 69:989e392cf635 | 601 | if (m_CONVRUN_pin) |
whismanoid | 69:989e392cf635 | 602 | { |
whismanoid | 69:989e392cf635 | 603 | // CONVRUN was switched high, EOC# will now begin toggling |
whismanoid | 69:989e392cf635 | 604 | } |
whismanoid | 69:989e392cf635 | 605 | else |
whismanoid | 69:989e392cf635 | 606 | { |
whismanoid | 69:989e392cf635 | 607 | // CONVRUN was switched low, so wait until EOC# returns high |
whismanoid | 69:989e392cf635 | 608 | #warning "MAX11043::Read_ADCabcd() Potential infinite loop if EOC pin not connected" |
whismanoid | 69:989e392cf635 | 609 | // possible infinite loop; need a timeout or futility countdown to escape |
whismanoid | 69:989e392cf635 | 610 | for (int futility_countdown = 100; |
whismanoid | 69:989e392cf635 | 611 | ((futility_countdown > 0) && |
whismanoid | 69:989e392cf635 | 612 | (m_EOC_pin != 1)); |
whismanoid | 69:989e392cf635 | 613 | futility_countdown--) |
whismanoid | 69:989e392cf635 | 614 | { |
whismanoid | 69:989e392cf635 | 615 | // spinlock waiting for logic high pin state (start of new conversion) |
whismanoid | 69:989e392cf635 | 616 | } |
whismanoid | 69:989e392cf635 | 617 | } |
whismanoid | 69:989e392cf635 | 618 | #else // MAX11043_EOC_INTERRUPT_POLLING |
whismanoid | 69:989e392cf635 | 619 | // MAX11043 EOC End Of Conversion input is InterruptIn(PinName:EOC_pin).fall(onEOCFallingEdge); |
whismanoid | 69:989e392cf635 | 620 | #endif // MAX11043_EOC_INTERRUPT_POLLING |
whismanoid | 69:989e392cf635 | 621 | //-------------------------------------------------- |
whismanoid | 53:3d5a3d241a5e | 622 | } |
whismanoid | 53:3d5a3d241a5e | 623 | |
whismanoid | 89:20fd6ce5e4dd | 624 | // CODE GENERATOR: extern function requirement MAX11043::CONVRUNoutputGetValue |
whismanoid | 89:20fd6ce5e4dd | 625 | // Return the state being driven onto the MAX11043 CONVRUN pin. |
whismanoid | 89:20fd6ce5e4dd | 626 | // |
whismanoid | 89:20fd6ce5e4dd | 627 | int MAX11043::CONVRUNoutputGetValue() |
whismanoid | 89:20fd6ce5e4dd | 628 | { |
whismanoid | 89:20fd6ce5e4dd | 629 | // CODE GENERATOR: extern function definition for function CONVRUNoutputGetValue |
whismanoid | 89:20fd6ce5e4dd | 630 | // TODO1: CODE GENERATOR: extern function definition for gpio interface function CONVRUNoutputGetValue |
whismanoid | 89:20fd6ce5e4dd | 631 | // TODO1: CODE GENERATOR: gpio pin CONVRUN assuming member function m_CONVRUN_pin |
whismanoid | 89:20fd6ce5e4dd | 632 | // TODO1: CODE GENERATOR: gpio direction output |
whismanoid | 89:20fd6ce5e4dd | 633 | // m_CONVRUN_pin.output(); // only applicable to DigitalInOut |
whismanoid | 89:20fd6ce5e4dd | 634 | // TODO1: CODE GENERATOR: gpio function GetValue |
whismanoid | 89:20fd6ce5e4dd | 635 | return m_CONVRUN_pin; |
whismanoid | 89:20fd6ce5e4dd | 636 | } |
whismanoid | 89:20fd6ce5e4dd | 637 | |
whismanoid | 53:3d5a3d241a5e | 638 | // TODO1: CODE GENERATOR: extern function GPIOoutputDACSTEP alias DACSTEPoutputValue |
whismanoid | 53:3d5a3d241a5e | 639 | // CODE GENERATOR: extern function requirement MAX11043::DACSTEPoutputValue |
whismanoid | 58:2fea32db466b | 640 | // Assert MAX11043 DACSTEP pin : High = Active, Low = Idle. |
whismanoid | 53:3d5a3d241a5e | 641 | // |
whismanoid | 53:3d5a3d241a5e | 642 | void MAX11043::DACSTEPoutputValue(int isLogicHigh) |
whismanoid | 53:3d5a3d241a5e | 643 | { |
whismanoid | 53:3d5a3d241a5e | 644 | // CODE GENERATOR: extern function definition for function DACSTEPoutputValue |
whismanoid | 53:3d5a3d241a5e | 645 | // TODO1: CODE GENERATOR: extern function definition for gpio interface function DACSTEPoutputValue |
whismanoid | 53:3d5a3d241a5e | 646 | // TODO1: CODE GENERATOR: gpio pin DACSTEP assuming member function m_DACSTEP_pin |
whismanoid | 53:3d5a3d241a5e | 647 | // TODO1: CODE GENERATOR: gpio direction output |
whismanoid | 53:3d5a3d241a5e | 648 | // m_DACSTEP_pin.output(); // only applicable to DigitalInOut |
whismanoid | 53:3d5a3d241a5e | 649 | // TODO1: CODE GENERATOR: gpio function Value |
whismanoid | 53:3d5a3d241a5e | 650 | m_DACSTEP_pin = isLogicHigh; |
whismanoid | 53:3d5a3d241a5e | 651 | } |
whismanoid | 53:3d5a3d241a5e | 652 | |
whismanoid | 53:3d5a3d241a5e | 653 | // TODO1: CODE GENERATOR: extern function GPIOoutputUP_slash_DWNb alias UP_slash_DWNboutputValue |
whismanoid | 53:3d5a3d241a5e | 654 | // CODE GENERATOR: extern function requirement MAX11043::UP_slash_DWNboutputValue |
whismanoid | 58:2fea32db466b | 655 | // Assert MAX11043 UP_slash_DWNb pin : High = Up, Low = Down. |
whismanoid | 53:3d5a3d241a5e | 656 | // |
whismanoid | 53:3d5a3d241a5e | 657 | void MAX11043::UP_slash_DWNboutputValue(int isLogicHigh) |
whismanoid | 53:3d5a3d241a5e | 658 | { |
whismanoid | 53:3d5a3d241a5e | 659 | // CODE GENERATOR: extern function definition for function UP_slash_DWNboutputValue |
whismanoid | 53:3d5a3d241a5e | 660 | // TODO1: CODE GENERATOR: extern function definition for gpio interface function UP_slash_DWNboutputValue |
whismanoid | 53:3d5a3d241a5e | 661 | // TODO1: CODE GENERATOR: gpio pin UP_slash_DWNb assuming member function m_UP_slash_DWNb_pin |
whismanoid | 53:3d5a3d241a5e | 662 | // TODO1: CODE GENERATOR: gpio direction output |
whismanoid | 53:3d5a3d241a5e | 663 | // m_UP_slash_DWNb_pin.output(); // only applicable to DigitalInOut |
whismanoid | 53:3d5a3d241a5e | 664 | // TODO1: CODE GENERATOR: gpio function Value |
whismanoid | 53:3d5a3d241a5e | 665 | m_UP_slash_DWNb_pin = isLogicHigh; |
whismanoid | 53:3d5a3d241a5e | 666 | } |
whismanoid | 53:3d5a3d241a5e | 667 | |
whismanoid | 53:3d5a3d241a5e | 668 | // CODE GENERATOR: extern function requirement MAX11043::EOCinputWaitUntilLow |
whismanoid | 53:3d5a3d241a5e | 669 | // Wait for MAX11043 EOC pin low, indicating end of conversion. |
whismanoid | 53:3d5a3d241a5e | 670 | // Required when using any of the InternalClock modes. |
whismanoid | 53:3d5a3d241a5e | 671 | // |
whismanoid | 53:3d5a3d241a5e | 672 | void MAX11043::EOCinputWaitUntilLow() |
whismanoid | 53:3d5a3d241a5e | 673 | { |
whismanoid | 53:3d5a3d241a5e | 674 | // CODE GENERATOR: extern function definition for function EOCinputWaitUntilLow |
whismanoid | 53:3d5a3d241a5e | 675 | // TODO1: CODE GENERATOR: extern function definition for gpio interface function EOCinputWaitUntilLow |
whismanoid | 53:3d5a3d241a5e | 676 | // TODO1: CODE GENERATOR: gpio pin EOC assuming member function m_EOC_pin |
whismanoid | 53:3d5a3d241a5e | 677 | // TODO1: CODE GENERATOR: gpio direction input |
whismanoid | 53:3d5a3d241a5e | 678 | // m_EOC_pin.input(); // only applicable to DigitalInOut |
whismanoid | 53:3d5a3d241a5e | 679 | // TODO1: CODE GENERATOR: gpio function WaitUntilLow |
whismanoid | 53:3d5a3d241a5e | 680 | while (m_EOC_pin != 0) |
whismanoid | 53:3d5a3d241a5e | 681 | { |
whismanoid | 53:3d5a3d241a5e | 682 | // spinlock waiting for logic low pin state |
whismanoid | 53:3d5a3d241a5e | 683 | } |
whismanoid | 53:3d5a3d241a5e | 684 | } |
whismanoid | 53:3d5a3d241a5e | 685 | |
whismanoid | 53:3d5a3d241a5e | 686 | // CODE GENERATOR: extern function requirement MAX11043::EOCinputValue |
whismanoid | 53:3d5a3d241a5e | 687 | // Return the status of the MAX11043 EOC pin. |
whismanoid | 53:3d5a3d241a5e | 688 | // |
whismanoid | 53:3d5a3d241a5e | 689 | int MAX11043::EOCinputValue() |
whismanoid | 53:3d5a3d241a5e | 690 | { |
whismanoid | 53:3d5a3d241a5e | 691 | // CODE GENERATOR: extern function definition for function EOCinputValue |
whismanoid | 53:3d5a3d241a5e | 692 | // TODO1: CODE GENERATOR: extern function definition for gpio interface function EOCinputValue |
whismanoid | 53:3d5a3d241a5e | 693 | // TODO1: CODE GENERATOR: gpio pin EOC assuming member function m_EOC_pin |
whismanoid | 53:3d5a3d241a5e | 694 | // TODO1: CODE GENERATOR: gpio direction input |
whismanoid | 53:3d5a3d241a5e | 695 | // m_EOC_pin.input(); // only applicable to DigitalInOut |
whismanoid | 53:3d5a3d241a5e | 696 | // TODO1: CODE GENERATOR: gpio function Value |
whismanoid | 53:3d5a3d241a5e | 697 | return m_EOC_pin.read(); |
whismanoid | 53:3d5a3d241a5e | 698 | } |
whismanoid | 53:3d5a3d241a5e | 699 | |
whismanoid | 53:3d5a3d241a5e | 700 | // CODE GENERATOR: class member function definitions |
whismanoid | 53:3d5a3d241a5e | 701 | //---------------------------------------- |
whismanoid | 53:3d5a3d241a5e | 702 | // Menu item '!' |
whismanoid | 53:3d5a3d241a5e | 703 | // Initialize device |
whismanoid | 53:3d5a3d241a5e | 704 | // @return 1 on success; 0 on failure |
whismanoid | 53:3d5a3d241a5e | 705 | uint8_t MAX11043::Init(void) |
whismanoid | 53:3d5a3d241a5e | 706 | { |
whismanoid | 53:3d5a3d241a5e | 707 | |
whismanoid | 53:3d5a3d241a5e | 708 | //---------------------------------------- |
whismanoid | 59:47538bcf6cda | 709 | // reference voltage, in Volts |
whismanoid | 59:47538bcf6cda | 710 | VRef = 2.500; |
whismanoid | 59:47538bcf6cda | 711 | |
whismanoid | 59:47538bcf6cda | 712 | //---------------------------------------- |
whismanoid | 90:d6ed8a8c5f26 | 713 | // shadow of register config CMD_0010_0000_d16_Wr08_Configuration |
whismanoid | 59:47538bcf6cda | 714 | config = 0x6000; |
whismanoid | 59:47538bcf6cda | 715 | |
whismanoid | 59:47538bcf6cda | 716 | //---------------------------------------- |
whismanoid | 59:47538bcf6cda | 717 | // shadow of register status CMD_0001_1110_d8_Rd07_Status |
whismanoid | 59:47538bcf6cda | 718 | status = 0x00; |
whismanoid | 53:3d5a3d241a5e | 719 | |
whismanoid | 53:3d5a3d241a5e | 720 | //---------------------------------------- |
whismanoid | 59:47538bcf6cda | 721 | // shadow of register ADCa CMD_0000_0010_d16o8_Rd00_ADCa |
whismanoid | 59:47538bcf6cda | 722 | adca = 0x0000; |
whismanoid | 53:3d5a3d241a5e | 723 | |
whismanoid | 53:3d5a3d241a5e | 724 | //---------------------------------------- |
whismanoid | 59:47538bcf6cda | 725 | // shadow of register ADCb CMD_0000_0110_d16o8_Rd01_ADCb |
whismanoid | 59:47538bcf6cda | 726 | adcb = 0x0000; |
whismanoid | 59:47538bcf6cda | 727 | |
whismanoid | 59:47538bcf6cda | 728 | //---------------------------------------- |
whismanoid | 59:47538bcf6cda | 729 | // shadow of register ADCc CMD_0000_1010_d16o8_Rd02_ADCc |
whismanoid | 59:47538bcf6cda | 730 | adcc = 0x0000; |
whismanoid | 59:47538bcf6cda | 731 | |
whismanoid | 59:47538bcf6cda | 732 | //---------------------------------------- |
whismanoid | 59:47538bcf6cda | 733 | // shadow of register ADCd CMD_0000_1110_d16o8_Rd03_ADCd |
whismanoid | 59:47538bcf6cda | 734 | adcd = 0x0000; |
whismanoid | 53:3d5a3d241a5e | 735 | |
whismanoid | 53:3d5a3d241a5e | 736 | //---------------------------------------- |
whismanoid | 53:3d5a3d241a5e | 737 | // init (based on old EV kit GUI) |
whismanoid | 53:3d5a3d241a5e | 738 | #warning "Not Implemented Yet: MAX11043::Init init..." |
whismanoid | 53:3d5a3d241a5e | 739 | // bool bOpResult = false; |
whismanoid | 53:3d5a3d241a5e | 740 | // String FWVersionString = "00"; |
whismanoid | 53:3d5a3d241a5e | 741 | // bool bDemoMode = true; |
whismanoid | 53:3d5a3d241a5e | 742 | // int scan_resolution = 0; |
whismanoid | 53:3d5a3d241a5e | 743 | // int scan_channels = 0; |
whismanoid | 53:3d5a3d241a5e | 744 | // int scan_bits = 0; |
whismanoid | 53:3d5a3d241a5e | 745 | // int sampleRateFactore = 0; |
whismanoid | 53:3d5a3d241a5e | 746 | // double sampleRate = 0; |
whismanoid | 53:3d5a3d241a5e | 747 | // unsigned long banks_requested = 0; |
whismanoid | 53:3d5a3d241a5e | 748 | // bool bScanMode = 0; |
whismanoid | 53:3d5a3d241a5e | 749 | |
whismanoid | 53:3d5a3d241a5e | 750 | //---------------------------------------- |
whismanoid | 59:47538bcf6cda | 751 | // Device ID Validation -- not used, no device ID register |
whismanoid | 53:3d5a3d241a5e | 752 | #warning "Not Implemented Yet: MAX11043::Init Device ID Validation..." |
whismanoid | 53:3d5a3d241a5e | 753 | // const uint32_t part_id_expect = 0x000F02; |
whismanoid | 53:3d5a3d241a5e | 754 | // uint32_t part_id_readback; |
whismanoid | 53:3d5a3d241a5e | 755 | // RegRead(xxxxxxxxxxxxCMD_r001_0001_xxxx_xxxx_xxxx_xxxx_xxxx_xddd_PART_ID, &part_id_readback); |
whismanoid | 53:3d5a3d241a5e | 756 | // if (part_id_readback != part_id_expect) return 0; |
whismanoid | 53:3d5a3d241a5e | 757 | |
whismanoid | 53:3d5a3d241a5e | 758 | //---------------------------------------- |
whismanoid | 58:2fea32db466b | 759 | // Active-High Shutdown Input. Drive high to shut down the MAX11043. |
whismanoid | 58:2fea32db466b | 760 | SHDNoutputValue(0); // SHDN Inactive |
whismanoid | 58:2fea32db466b | 761 | |
whismanoid | 58:2fea32db466b | 762 | //---------------------------------------- |
whismanoid | 58:2fea32db466b | 763 | // Convert Run. Drive high to start continuous conversions on all 4 channels. The device is idle when |
whismanoid | 58:2fea32db466b | 764 | // CONVRUN is low. |
whismanoid | 58:2fea32db466b | 765 | CONVRUNoutputValue(0); // CONVRUN Idle |
whismanoid | 58:2fea32db466b | 766 | |
whismanoid | 58:2fea32db466b | 767 | //---------------------------------------- |
whismanoid | 58:2fea32db466b | 768 | // DAC Step Input. Drive high to move the DAC output in the direction of UP/DWN on the next rising |
whismanoid | 58:2fea32db466b | 769 | // edge of the system clock. |
whismanoid | 58:2fea32db466b | 770 | DACSTEPoutputValue(0); // DACSTEP Idle |
whismanoid | 58:2fea32db466b | 771 | |
whismanoid | 58:2fea32db466b | 772 | //---------------------------------------- |
whismanoid | 58:2fea32db466b | 773 | // DAC Step Direction Select. Drive high to step up, drive low to step down when DACSTEP is toggled. |
whismanoid | 58:2fea32db466b | 774 | UP_slash_DWNboutputValue(0); // UP/DWN# Down |
whismanoid | 58:2fea32db466b | 775 | |
whismanoid | 58:2fea32db466b | 776 | //---------------------------------------- |
whismanoid | 53:3d5a3d241a5e | 777 | // success |
whismanoid | 53:3d5a3d241a5e | 778 | return 1; |
whismanoid | 53:3d5a3d241a5e | 779 | } |
whismanoid | 53:3d5a3d241a5e | 780 | |
whismanoid | 53:3d5a3d241a5e | 781 | //---------------------------------------- |
whismanoid | 93:6b22269935a6 | 782 | // Return the physical voltage corresponding to conversion result |
whismanoid | 93:6b22269935a6 | 783 | // (conversion format is Bipolar mode, 2's complement) |
whismanoid | 93:6b22269935a6 | 784 | // Does not perform any offset or gain correction. |
whismanoid | 93:6b22269935a6 | 785 | // |
whismanoid | 93:6b22269935a6 | 786 | // @pre CONFIG_xxxx_xxxx_xx1x_xxxx_24BIT is 0: 16-bit mode is configured |
whismanoid | 93:6b22269935a6 | 787 | // @pre VRef = Voltage of REF input, in Volts |
whismanoid | 93:6b22269935a6 | 788 | // @param[in] value_u24: raw 24-bit MAX11043 code (right justified). |
whismanoid | 93:6b22269935a6 | 789 | // @return physical voltage corresponding to MAX11043 code. |
whismanoid | 93:6b22269935a6 | 790 | // @test group BIP2C16 ADCVoltageOfCode_16bit(0x7FFF) expect 2.500 within 0.030 Full Scale |
whismanoid | 93:6b22269935a6 | 791 | // @test group BIP2C16 ADCVoltageOfCode_16bit(0x7FFF) expect 2.500 Full Scale |
whismanoid | 93:6b22269935a6 | 792 | // @test group BIP2C16 ADCVoltageOfCode_16bit(0x6666) expect 2.000 Two Volts |
whismanoid | 93:6b22269935a6 | 793 | // @test group BIP2C16 ADCVoltageOfCode_16bit(0x6000) expect 1.875 75% Scale |
whismanoid | 93:6b22269935a6 | 794 | // @test group BIP2C16 ADCVoltageOfCode_16bit(0x4000) expect 1.250 Mid Scale |
whismanoid | 93:6b22269935a6 | 795 | // @test group BIP2C16 ADCVoltageOfCode_16bit(0x3333) expect 1.000 One Volt |
whismanoid | 93:6b22269935a6 | 796 | // @test group BIP2C16 ADCVoltageOfCode_16bit(0x2000) expect 0.625 25% Scale |
whismanoid | 93:6b22269935a6 | 797 | // @test group BIP2C16 ADCVoltageOfCode_16bit(0x051e) expect 0.100 100mV |
whismanoid | 93:6b22269935a6 | 798 | // @test group BIP2C16 ADCVoltageOfCode_16bit(0x0000) expect 0.00000894069671 Three LSB |
whismanoid | 93:6b22269935a6 | 799 | // @test group BIP2C16 ADCVoltageOfCode_16bit(0x0000) expect 0.00000596046447 Two LSB |
whismanoid | 93:6b22269935a6 | 800 | // @test group BIP2C16 ADCVoltageOfCode_16bit(0x0000) expect 0.0000029802326 One LSB |
whismanoid | 93:6b22269935a6 | 801 | // @test group BIP2C16 ADCVoltageOfCode_16bit(0x0000) expect 0.0 Zero Scale |
whismanoid | 93:6b22269935a6 | 802 | // @test group BIP2C16 ADCVoltageOfCode_16bit(0xFFFF) expect -0.0000029802326 Negative One LSB |
whismanoid | 93:6b22269935a6 | 803 | // @test group BIP2C16 ADCVoltageOfCode_16bit(0xFFFF) expect -0.0000059604644 Negative Two LSB |
whismanoid | 93:6b22269935a6 | 804 | // @test group BIP2C16 ADCVoltageOfCode_16bit(0xFFFF) expect -0.0000089406967 Negative Three LSB |
whismanoid | 93:6b22269935a6 | 805 | // @test group BIP2C16 ADCVoltageOfCode_16bit(0xFAE1) expect -0.100 Negative 100mV |
whismanoid | 93:6b22269935a6 | 806 | // @test group BIP2C16 ADCVoltageOfCode_16bit(0xE000) expect -0.625 Negative 25% Scale |
whismanoid | 93:6b22269935a6 | 807 | // @test group BIP2C16 ADCVoltageOfCode_16bit(0xCCCC) expect -1.000 Negative One Volt |
whismanoid | 93:6b22269935a6 | 808 | // @test group BIP2C16 ADCVoltageOfCode_16bit(0xC000) expect -1.250 Negative Mid Scale |
whismanoid | 93:6b22269935a6 | 809 | // @test group BIP2C16 ADCVoltageOfCode_16bit(0xA000) expect -1.875 Negative 75% Scale |
whismanoid | 93:6b22269935a6 | 810 | // @test group BIP2C16 ADCVoltageOfCode_16bit(0x9999) expect -2.000 Negative Two Volts |
whismanoid | 93:6b22269935a6 | 811 | // @test group BIP2C16 ADCVoltageOfCode_16bit(0x8000) expect -2.500 Negative Full Scale |
whismanoid | 93:6b22269935a6 | 812 | // @test group BIP2C16 ADCVoltageOfCode_16bit(0x8000) expect -2.500 Negative Full Scale |
whismanoid | 93:6b22269935a6 | 813 | // |
whismanoid | 93:6b22269935a6 | 814 | double MAX11043::ADCVoltageOfCode_16bit(uint32_t value_u16) |
whismanoid | 93:6b22269935a6 | 815 | { |
whismanoid | 93:6b22269935a6 | 816 | |
whismanoid | 93:6b22269935a6 | 817 | //---------------------------------------- |
whismanoid | 93:6b22269935a6 | 818 | // Linear map min and max endpoints |
whismanoid | 93:6b22269935a6 | 819 | double MaxScaleVoltage = 2 * VRef; // voltage of maximum code 0x7fff |
whismanoid | 93:6b22269935a6 | 820 | double MinScaleVoltage = 0; // voltage of minimum code 0x8000 |
whismanoid | 93:6b22269935a6 | 821 | const int32_t FULL_SCALE_CODE_16BIT_2S_COMPLEMENT = 0x7fff; |
whismanoid | 93:6b22269935a6 | 822 | const int32_t SIGN_BIT_16BIT_2S_COMPLEMENT = 0x8000; |
whismanoid | 93:6b22269935a6 | 823 | if (value_u16 >= SIGN_BIT_16BIT_2S_COMPLEMENT) { value_u16 = value_u16 - (2 * SIGN_BIT_16BIT_2S_COMPLEMENT); } |
whismanoid | 93:6b22269935a6 | 824 | const int32_t MaxCode = FULL_SCALE_CODE_16BIT_2S_COMPLEMENT; |
whismanoid | 93:6b22269935a6 | 825 | const int32_t CodeSpan = 0x10000; |
whismanoid | 93:6b22269935a6 | 826 | const int32_t MinCode = 0; |
whismanoid | 93:6b22269935a6 | 827 | double codeFraction = ((double)((int32_t)value_u16) - MinCode) / CodeSpan; |
whismanoid | 93:6b22269935a6 | 828 | return (MinScaleVoltage + ((MaxScaleVoltage - MinScaleVoltage) * codeFraction)); // / pgaGain; |
whismanoid | 93:6b22269935a6 | 829 | } |
whismanoid | 93:6b22269935a6 | 830 | |
whismanoid | 93:6b22269935a6 | 831 | //---------------------------------------- |
whismanoid | 93:6b22269935a6 | 832 | // Return the physical voltage corresponding to conversion result |
whismanoid | 93:6b22269935a6 | 833 | // (conversion format is Bipolar mode, 2's complement) |
whismanoid | 93:6b22269935a6 | 834 | // Does not perform any offset or gain correction. |
whismanoid | 93:6b22269935a6 | 835 | // |
whismanoid | 93:6b22269935a6 | 836 | // @pre CONFIG_xxxx_xxxx_xx1x_xxxx_24BIT is 1: 24-bit mode is configured |
whismanoid | 93:6b22269935a6 | 837 | // @pre VRef = Voltage of REF input, in Volts |
whismanoid | 93:6b22269935a6 | 838 | // @param[in] value_u24: raw 24-bit MAX11043 code (right justified). |
whismanoid | 93:6b22269935a6 | 839 | // @return physical voltage corresponding to MAX11043 code. |
whismanoid | 93:6b22269935a6 | 840 | // @test group BIP2C24 ADCVoltageOfCode_24bit(0x7FFFFF) expect 2.500 within 0.030 Full Scale |
whismanoid | 93:6b22269935a6 | 841 | // @test group BIP2C24 ADCVoltageOfCode_24bit(0x7FFFFE) expect 2.500 Full Scale |
whismanoid | 93:6b22269935a6 | 842 | // @test group BIP2C24 ADCVoltageOfCode_24bit(0x666666) expect 2.000 Two Volts |
whismanoid | 93:6b22269935a6 | 843 | // @test group BIP2C24 ADCVoltageOfCode_24bit(0x600000) expect 1.875 75% Scale |
whismanoid | 93:6b22269935a6 | 844 | // @test group BIP2C24 ADCVoltageOfCode_24bit(0x400000) expect 1.250 Mid Scale |
whismanoid | 93:6b22269935a6 | 845 | // @test group BIP2C24 ADCVoltageOfCode_24bit(0x333333) expect 1.000 One Volt |
whismanoid | 93:6b22269935a6 | 846 | // @test group BIP2C24 ADCVoltageOfCode_24bit(0x200000) expect 0.625 25% Scale |
whismanoid | 93:6b22269935a6 | 847 | // @test group BIP2C24 ADCVoltageOfCode_24bit(0x051eb8) expect 0.100 100mV |
whismanoid | 93:6b22269935a6 | 848 | // @test group BIP2C24 ADCVoltageOfCode_24bit(0x000003) expect 0.00000894069671 Three LSB |
whismanoid | 93:6b22269935a6 | 849 | // @test group BIP2C24 ADCVoltageOfCode_24bit(0x000002) expect 0.00000596046447 Two LSB |
whismanoid | 93:6b22269935a6 | 850 | // @test group BIP2C24 ADCVoltageOfCode_24bit(0x000001) expect 0.0000029802326 One LSB |
whismanoid | 93:6b22269935a6 | 851 | // @test group BIP2C24 ADCVoltageOfCode_24bit(0x000000) expect 0.0 Zero Scale |
whismanoid | 93:6b22269935a6 | 852 | // @test group BIP2C24 ADCVoltageOfCode_24bit(0xFFFFFF) expect -0.0000029802326 Negative One LSB |
whismanoid | 93:6b22269935a6 | 853 | // @test group BIP2C24 ADCVoltageOfCode_24bit(0xFFFFFE) expect -0.0000059604644 Negative Two LSB |
whismanoid | 93:6b22269935a6 | 854 | // @test group BIP2C24 ADCVoltageOfCode_24bit(0xFFFFFD) expect -0.0000089406967 Negative Three LSB |
whismanoid | 93:6b22269935a6 | 855 | // @test group BIP2C24 ADCVoltageOfCode_24bit(0xFAE148) expect -0.100 Negative 100mV |
whismanoid | 93:6b22269935a6 | 856 | // @test group BIP2C24 ADCVoltageOfCode_24bit(0xE00000) expect -0.625 Negative 25% Scale |
whismanoid | 93:6b22269935a6 | 857 | // @test group BIP2C24 ADCVoltageOfCode_24bit(0xCCCCCD) expect -1.000 Negative One Volt |
whismanoid | 93:6b22269935a6 | 858 | // @test group BIP2C24 ADCVoltageOfCode_24bit(0xC00000) expect -1.250 Negative Mid Scale |
whismanoid | 93:6b22269935a6 | 859 | // @test group BIP2C24 ADCVoltageOfCode_24bit(0xA00000) expect -1.875 Negative 75% Scale |
whismanoid | 93:6b22269935a6 | 860 | // @test group BIP2C24 ADCVoltageOfCode_24bit(0x99999A) expect -2.000 Negative Two Volts |
whismanoid | 93:6b22269935a6 | 861 | // @test group BIP2C24 ADCVoltageOfCode_24bit(0x800001) expect -2.500 Negative Full Scale |
whismanoid | 93:6b22269935a6 | 862 | // @test group BIP2C24 ADCVoltageOfCode_24bit(0x800000) expect -2.500 Negative Full Scale |
whismanoid | 93:6b22269935a6 | 863 | // |
whismanoid | 93:6b22269935a6 | 864 | double MAX11043::ADCVoltageOfCode_24bit(uint32_t value_u24) |
whismanoid | 93:6b22269935a6 | 865 | { |
whismanoid | 93:6b22269935a6 | 866 | |
whismanoid | 93:6b22269935a6 | 867 | //---------------------------------------- |
whismanoid | 93:6b22269935a6 | 868 | // Linear map min and max endpoints |
whismanoid | 93:6b22269935a6 | 869 | double MaxScaleVoltage = 2 * VRef; // voltage of maximum code 0x7fffff |
whismanoid | 93:6b22269935a6 | 870 | double MinScaleVoltage = 0; // voltage of minimum code 0x800000 |
whismanoid | 93:6b22269935a6 | 871 | const int32_t FULL_SCALE_CODE_24BIT_2S_COMPLEMENT = 0x7fffff; |
whismanoid | 93:6b22269935a6 | 872 | const int32_t SIGN_BIT_24BIT_2S_COMPLEMENT = 0x800000; |
whismanoid | 93:6b22269935a6 | 873 | if (value_u24 >= SIGN_BIT_24BIT_2S_COMPLEMENT) { value_u24 = value_u24 - (2 * SIGN_BIT_24BIT_2S_COMPLEMENT); } |
whismanoid | 93:6b22269935a6 | 874 | const int32_t MaxCode = FULL_SCALE_CODE_24BIT_2S_COMPLEMENT; |
whismanoid | 93:6b22269935a6 | 875 | const int32_t CodeSpan = 0x1000000; |
whismanoid | 93:6b22269935a6 | 876 | const int32_t MinCode = 0; |
whismanoid | 93:6b22269935a6 | 877 | double codeFraction = ((double)((int32_t)value_u24) - MinCode) / CodeSpan; |
whismanoid | 93:6b22269935a6 | 878 | return (MinScaleVoltage + ((MaxScaleVoltage - MinScaleVoltage) * codeFraction)); // / pgaGain; |
whismanoid | 93:6b22269935a6 | 879 | } |
whismanoid | 93:6b22269935a6 | 880 | |
whismanoid | 93:6b22269935a6 | 881 | //---------------------------------------- |
whismanoid | 53:3d5a3d241a5e | 882 | // Write a MAX11043 register. |
whismanoid | 53:3d5a3d241a5e | 883 | // |
whismanoid | 57:1c9da8e90737 | 884 | // CMDOP_1aaa_aaaa_ReadRegister bit is cleared 0 indicating a write operation. |
whismanoid | 53:3d5a3d241a5e | 885 | // |
whismanoid | 53:3d5a3d241a5e | 886 | // MAX11043 register length can be determined by function RegSize. |
whismanoid | 53:3d5a3d241a5e | 887 | // |
whismanoid | 53:3d5a3d241a5e | 888 | // For 8-bit register size: |
whismanoid | 53:3d5a3d241a5e | 889 | // |
whismanoid | 53:3d5a3d241a5e | 890 | // SPI 16-bit transfer |
whismanoid | 53:3d5a3d241a5e | 891 | // |
whismanoid | 53:3d5a3d241a5e | 892 | // SPI MOSI = 0aaa_aaaa_dddd_dddd |
whismanoid | 53:3d5a3d241a5e | 893 | // |
whismanoid | 53:3d5a3d241a5e | 894 | // SPI MISO = xxxx_xxxx_xxxx_xxxx |
whismanoid | 53:3d5a3d241a5e | 895 | // |
whismanoid | 53:3d5a3d241a5e | 896 | // For 16-bit register size: |
whismanoid | 53:3d5a3d241a5e | 897 | // |
whismanoid | 53:3d5a3d241a5e | 898 | // SPI 24-bit or 32-bit transfer |
whismanoid | 53:3d5a3d241a5e | 899 | // |
whismanoid | 53:3d5a3d241a5e | 900 | // SPI MOSI = 0aaa_aaaa_dddd_dddd_dddd_dddd |
whismanoid | 53:3d5a3d241a5e | 901 | // |
whismanoid | 53:3d5a3d241a5e | 902 | // SPI MISO = xxxx_xxxx_xxxx_xxxx_xxxx_xxxx |
whismanoid | 53:3d5a3d241a5e | 903 | // |
whismanoid | 53:3d5a3d241a5e | 904 | // For 24-bit register size: |
whismanoid | 53:3d5a3d241a5e | 905 | // |
whismanoid | 53:3d5a3d241a5e | 906 | // SPI 32-bit transfer |
whismanoid | 53:3d5a3d241a5e | 907 | // |
whismanoid | 53:3d5a3d241a5e | 908 | // SPI MOSI = 0aaa_aaaa_dddd_dddd_dddd_dddd_dddd_dddd |
whismanoid | 53:3d5a3d241a5e | 909 | // |
whismanoid | 53:3d5a3d241a5e | 910 | // SPI MISO = xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx |
whismanoid | 53:3d5a3d241a5e | 911 | // |
whismanoid | 53:3d5a3d241a5e | 912 | // @return 1 on success; 0 on failure |
whismanoid | 53:3d5a3d241a5e | 913 | uint8_t MAX11043::RegWrite(MAX11043_CMD_enum_t commandByte, uint32_t regData) |
whismanoid | 53:3d5a3d241a5e | 914 | { |
whismanoid | 53:3d5a3d241a5e | 915 | |
whismanoid | 53:3d5a3d241a5e | 916 | //---------------------------------------- |
whismanoid | 53:3d5a3d241a5e | 917 | // switch based on register address szie RegSize(commandByte) |
whismanoid | 57:1c9da8e90737 | 918 | //commandByte = (MAX11043_CMD_enum_t)((commandByte &~ CMDOP_0aaa_aa10_ReadRegister) & 0xFF); |
whismanoid | 53:3d5a3d241a5e | 919 | switch(RegSize(commandByte)) |
whismanoid | 53:3d5a3d241a5e | 920 | { |
whismanoid | 53:3d5a3d241a5e | 921 | case 8: // 8-bit register size |
whismanoid | 53:3d5a3d241a5e | 922 | { |
whismanoid | 63:8f39d21d6157 | 923 | // SPI 8+8 = 16-bit transfer |
whismanoid | 63:8f39d21d6157 | 924 | // 1234 5678 ___[1]_16 |
whismanoid | 63:8f39d21d6157 | 925 | // SPI MOSI = 0aaa_aaaa_dddd_dddd ... _0000 |
whismanoid | 63:8f39d21d6157 | 926 | // SPI MISO = xxxx_xxxx_xxxx_xxxx ... _xxxx |
whismanoid | 63:8f39d21d6157 | 927 | size_t byteCount = 1 + 1; |
whismanoid | 63:8f39d21d6157 | 928 | uint8_t mosiData[2]; |
whismanoid | 63:8f39d21d6157 | 929 | uint8_t misoData[2]; |
whismanoid | 63:8f39d21d6157 | 930 | mosiData[0] = commandByte; |
whismanoid | 63:8f39d21d6157 | 931 | mosiData[1] = regData; |
whismanoid | 63:8f39d21d6157 | 932 | // SPIreadWriteWithLowCS(size_t byteCount, uint8_t mosiData[], uint8_t misoData[]); |
whismanoid | 63:8f39d21d6157 | 933 | SPIreadWriteWithLowCS(byteCount, mosiData, misoData); |
whismanoid | 63:8f39d21d6157 | 934 | // TODO: cache CMD_0101_0100_d8_Wr15_FilterCAddress |
whismanoid | 63:8f39d21d6157 | 935 | // if (commandByte == CMD_0101_0100_d8_Wr15_FilterCAddress) { |
whismanoid | 63:8f39d21d6157 | 936 | // FilterCAddress = regData; |
whismanoid | 63:8f39d21d6157 | 937 | // } |
whismanoid | 63:8f39d21d6157 | 938 | // TODO: cache CMD_0110_0000_d8_Wr18_FlashMode |
whismanoid | 63:8f39d21d6157 | 939 | // if (commandByte == CMD_0110_0000_d8_Wr18_FlashMode) { |
whismanoid | 63:8f39d21d6157 | 940 | // FlashMode = regData; |
whismanoid | 63:8f39d21d6157 | 941 | // } |
whismanoid | 53:3d5a3d241a5e | 942 | } |
whismanoid | 53:3d5a3d241a5e | 943 | break; |
whismanoid | 53:3d5a3d241a5e | 944 | case 16: // 16-bit register size |
whismanoid | 63:8f39d21d6157 | 945 | #warning "Not Verified Yet: MAX11043::RegWrite 16-bit" |
whismanoid | 53:3d5a3d241a5e | 946 | { |
whismanoid | 63:8f39d21d6157 | 947 | // SPI 8+16 = 24-bit transfer |
whismanoid | 63:8f39d21d6157 | 948 | // 1234 5678 ___[1]_16 ___[2]_24 |
whismanoid | 63:8f39d21d6157 | 949 | // SPI MOSI = 0aaa_aaaa_dddd_dddd_dddd_dddd ... _0000 |
whismanoid | 63:8f39d21d6157 | 950 | // SPI MISO = xxxx_xxxx_xxxx_xxxx_xxxx_xxxx ... _xxxx |
whismanoid | 63:8f39d21d6157 | 951 | size_t byteCount = 1 + 2; |
whismanoid | 63:8f39d21d6157 | 952 | uint8_t mosiData[3]; |
whismanoid | 63:8f39d21d6157 | 953 | uint8_t misoData[3]; |
whismanoid | 63:8f39d21d6157 | 954 | mosiData[0] = commandByte; |
whismanoid | 63:8f39d21d6157 | 955 | mosiData[1] = (uint8_t)((regData >> 8) & 0xFF); |
whismanoid | 63:8f39d21d6157 | 956 | mosiData[2] = (uint8_t)((regData >> 0) & 0xFF); |
whismanoid | 63:8f39d21d6157 | 957 | // SPIreadWriteWithLowCS(size_t byteCount, uint8_t mosiData[], uint8_t misoData[]); |
whismanoid | 63:8f39d21d6157 | 958 | SPIreadWriteWithLowCS(byteCount, mosiData, misoData); |
whismanoid | 63:8f39d21d6157 | 959 | // cache CMD_0010_0000_d16_Wr08_Configuration |
whismanoid | 63:8f39d21d6157 | 960 | if (commandByte == CMD_0010_0000_d16_Wr08_Configuration) { |
whismanoid | 63:8f39d21d6157 | 961 | config = regData; |
whismanoid | 63:8f39d21d6157 | 962 | } |
whismanoid | 63:8f39d21d6157 | 963 | // TODO: cache CMD_0010_0100_d16_Wr09_DAC |
whismanoid | 63:8f39d21d6157 | 964 | // TODO: cache CMD_0010_1000_d16_Wr0A_DACStep |
whismanoid | 63:8f39d21d6157 | 965 | // TODO: cache CMD_0010_1100_d16_Wr0B_DACHDACL |
whismanoid | 63:8f39d21d6157 | 966 | // TODO: cache CMD_0011_0000_d16_Wr0C_ConfigA |
whismanoid | 63:8f39d21d6157 | 967 | // TODO: cache CMD_0011_0100_d16_Wr0D_ConfigB |
whismanoid | 63:8f39d21d6157 | 968 | // TODO: cache CMD_0011_1000_d16_Wr0E_ConfigC |
whismanoid | 63:8f39d21d6157 | 969 | // TODO: cache CMD_0011_1100_d16_Wr0F_ConfigD |
whismanoid | 63:8f39d21d6157 | 970 | // TODO: cache CMD_0100_0000_d16_Wr10_Reference |
whismanoid | 63:8f39d21d6157 | 971 | // TODO: cache CMD_0100_0100_d16_Wr11_AGain |
whismanoid | 63:8f39d21d6157 | 972 | // TODO: cache CMD_0100_1000_d16_Wr12_BGain |
whismanoid | 63:8f39d21d6157 | 973 | // TODO: cache CMD_0100_1100_d16_Wr13_CGain |
whismanoid | 63:8f39d21d6157 | 974 | // TODO: cache CMD_0101_0000_d16_Wr14_DGain |
whismanoid | 63:8f39d21d6157 | 975 | // TODO: cache CMD_0110_0100_d16_Wr19_FlashAddr |
whismanoid | 63:8f39d21d6157 | 976 | // TODO: cache CMD_0110_1000_d16_Wr1A_FlashDataIn |
whismanoid | 53:3d5a3d241a5e | 977 | } |
whismanoid | 53:3d5a3d241a5e | 978 | break; |
whismanoid | 63:8f39d21d6157 | 979 | case 32: // 32-bit register size |
whismanoid | 63:8f39d21d6157 | 980 | #warning "Not Verified Yet: MAX11043::RegWrite 32-bit" |
whismanoid | 53:3d5a3d241a5e | 981 | { |
whismanoid | 63:8f39d21d6157 | 982 | // SPI 8+32 = 40-bit transfer |
whismanoid | 63:8f39d21d6157 | 983 | // 1234 5678 ___[1]_16 ___[2]_24 ___[3]_32 ___[4]_40 |
whismanoid | 63:8f39d21d6157 | 984 | // SPI MOSI = 1aaa_aaaa_dddd_dddd_dddd_dddd_dddd_dddd_dddd_dddd ... _0000 |
whismanoid | 63:8f39d21d6157 | 985 | // SPI MISO = xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx ... _xxxx |
whismanoid | 63:8f39d21d6157 | 986 | // |
whismanoid | 63:8f39d21d6157 | 987 | size_t byteCount = 1 + (2 * 2); |
whismanoid | 63:8f39d21d6157 | 988 | uint8_t mosiData[5]; |
whismanoid | 63:8f39d21d6157 | 989 | uint8_t misoData[5]; |
whismanoid | 63:8f39d21d6157 | 990 | mosiData[0] = commandByte; |
whismanoid | 63:8f39d21d6157 | 991 | mosiData[1] = (uint8_t)((regData >> 24) & 0xFF); |
whismanoid | 63:8f39d21d6157 | 992 | mosiData[2] = (uint8_t)((regData >> 16) & 0xFF); |
whismanoid | 63:8f39d21d6157 | 993 | mosiData[3] = (uint8_t)((regData >> 8) & 0xFF); |
whismanoid | 63:8f39d21d6157 | 994 | mosiData[4] = (uint8_t)((regData >> 0) & 0xFF); |
whismanoid | 63:8f39d21d6157 | 995 | // SPIreadWriteWithLowCS(size_t byteCount, uint8_t mosiData[], uint8_t misoData[]); |
whismanoid | 63:8f39d21d6157 | 996 | SPIreadWriteWithLowCS(byteCount, mosiData, misoData); |
whismanoid | 63:8f39d21d6157 | 997 | // TODO: cache CMD_0101_1000_d32_Wr16_FilterCDataOut |
whismanoid | 63:8f39d21d6157 | 998 | // if (commandByte == CMD_0101_1000_d32_Wr16_FilterCDataOut) { |
whismanoid | 63:8f39d21d6157 | 999 | // FilterCDataOut = regData; |
whismanoid | 63:8f39d21d6157 | 1000 | // } |
whismanoid | 63:8f39d21d6157 | 1001 | // TODO: cache CMD_0101_1100_d32_Wr17_FilterCDataIn |
whismanoid | 63:8f39d21d6157 | 1002 | // if (commandByte == CMD_0101_1000_d32_Wr16_FilterCDataOut) { |
whismanoid | 63:8f39d21d6157 | 1003 | // FilterCDataOut = regData; |
whismanoid | 63:8f39d21d6157 | 1004 | // } |
whismanoid | 53:3d5a3d241a5e | 1005 | } |
whismanoid | 53:3d5a3d241a5e | 1006 | break; |
whismanoid | 53:3d5a3d241a5e | 1007 | } |
whismanoid | 53:3d5a3d241a5e | 1008 | |
whismanoid | 53:3d5a3d241a5e | 1009 | //---------------------------------------- |
whismanoid | 53:3d5a3d241a5e | 1010 | // success |
whismanoid | 53:3d5a3d241a5e | 1011 | return 1; |
whismanoid | 53:3d5a3d241a5e | 1012 | } |
whismanoid | 53:3d5a3d241a5e | 1013 | |
whismanoid | 53:3d5a3d241a5e | 1014 | //---------------------------------------- |
whismanoid | 53:3d5a3d241a5e | 1015 | // Read an 8-bit MAX11043 register |
whismanoid | 53:3d5a3d241a5e | 1016 | // |
whismanoid | 57:1c9da8e90737 | 1017 | // CMDOP_1aaa_aaaa_ReadRegister bit is set 1 indicating a read operation. |
whismanoid | 53:3d5a3d241a5e | 1018 | // |
whismanoid | 53:3d5a3d241a5e | 1019 | // MAX11043 register length can be determined by function RegSize. |
whismanoid | 53:3d5a3d241a5e | 1020 | // |
whismanoid | 53:3d5a3d241a5e | 1021 | // For 8-bit register size: |
whismanoid | 53:3d5a3d241a5e | 1022 | // |
whismanoid | 53:3d5a3d241a5e | 1023 | // SPI 16-bit transfer |
whismanoid | 53:3d5a3d241a5e | 1024 | // |
whismanoid | 53:3d5a3d241a5e | 1025 | // SPI MOSI = 1aaa_aaaa_0000_0000 |
whismanoid | 53:3d5a3d241a5e | 1026 | // |
whismanoid | 53:3d5a3d241a5e | 1027 | // SPI MISO = xxxx_xxxx_dddd_dddd |
whismanoid | 53:3d5a3d241a5e | 1028 | // |
whismanoid | 53:3d5a3d241a5e | 1029 | // For 16-bit register size: |
whismanoid | 53:3d5a3d241a5e | 1030 | // |
whismanoid | 53:3d5a3d241a5e | 1031 | // SPI 24-bit or 32-bit transfer |
whismanoid | 53:3d5a3d241a5e | 1032 | // |
whismanoid | 53:3d5a3d241a5e | 1033 | // SPI MOSI = 1aaa_aaaa_0000_0000_0000_0000 |
whismanoid | 53:3d5a3d241a5e | 1034 | // |
whismanoid | 53:3d5a3d241a5e | 1035 | // SPI MISO = xxxx_xxxx_dddd_dddd_dddd_dddd |
whismanoid | 53:3d5a3d241a5e | 1036 | // |
whismanoid | 53:3d5a3d241a5e | 1037 | // For 24-bit register size: |
whismanoid | 53:3d5a3d241a5e | 1038 | // |
whismanoid | 53:3d5a3d241a5e | 1039 | // SPI 32-bit transfer |
whismanoid | 53:3d5a3d241a5e | 1040 | // |
whismanoid | 53:3d5a3d241a5e | 1041 | // SPI MOSI = 1aaa_aaaa_0000_0000_0000_0000_0000_0000 |
whismanoid | 53:3d5a3d241a5e | 1042 | // |
whismanoid | 53:3d5a3d241a5e | 1043 | // SPI MISO = xxxx_xxxx_dddd_dddd_dddd_dddd_dddd_dddd |
whismanoid | 53:3d5a3d241a5e | 1044 | // |
whismanoid | 53:3d5a3d241a5e | 1045 | // |
whismanoid | 53:3d5a3d241a5e | 1046 | // @return 1 on success; 0 on failure |
whismanoid | 53:3d5a3d241a5e | 1047 | uint8_t MAX11043::RegRead(MAX11043_CMD_enum_t commandByte, uint32_t* ptrRegData) |
whismanoid | 53:3d5a3d241a5e | 1048 | { |
whismanoid | 53:3d5a3d241a5e | 1049 | |
whismanoid | 53:3d5a3d241a5e | 1050 | //---------------------------------------- |
whismanoid | 53:3d5a3d241a5e | 1051 | // switch based on register address szie RegSize(regAddress) |
whismanoid | 93:6b22269935a6 | 1052 | #define SIGN_EXTEND_INT16_VALUE(x) (((x)&(0x8000))?((x)-65536):(x)) |
whismanoid | 57:1c9da8e90737 | 1053 | //commandByte = (MAX11043_CMD_enum_t)((commandByte &~ CMDOP_0aaa_aa10_ReadRegister) & 0xFF); |
whismanoid | 53:3d5a3d241a5e | 1054 | switch(RegSize(commandByte)) |
whismanoid | 53:3d5a3d241a5e | 1055 | { |
whismanoid | 53:3d5a3d241a5e | 1056 | case 8: // 8-bit register size |
whismanoid | 53:3d5a3d241a5e | 1057 | { |
whismanoid | 60:d1d1eaa90fb7 | 1058 | // SPI 8+8 = 16-bit transfer |
whismanoid | 62:8223a7253c90 | 1059 | // 1234 5678 ___[1]_16 |
whismanoid | 63:8f39d21d6157 | 1060 | // SPI MOSI = 1aaa_aaaa_0000_0000 ... _0000 |
whismanoid | 63:8f39d21d6157 | 1061 | // SPI MISO = xxxx_xxxx_dddd_dddd ... _xxxx |
whismanoid | 63:8f39d21d6157 | 1062 | size_t byteCount = 1 + 1; |
whismanoid | 63:8f39d21d6157 | 1063 | uint8_t mosiData[2]; |
whismanoid | 63:8f39d21d6157 | 1064 | uint8_t misoData[2]; |
whismanoid | 63:8f39d21d6157 | 1065 | mosiData[0] = CMDOP_0aaa_aa10_ReadRegister | commandByte; |
whismanoid | 63:8f39d21d6157 | 1066 | mosiData[1] = 0; // CMDOP_1111_1111_NoOperationMOSIidleHigh; |
whismanoid | 63:8f39d21d6157 | 1067 | // SPIreadWriteWithLowCS(size_t byteCount, uint8_t mosiData[], uint8_t misoData[]); |
whismanoid | 63:8f39d21d6157 | 1068 | SPIreadWriteWithLowCS(byteCount, mosiData, misoData); |
whismanoid | 63:8f39d21d6157 | 1069 | if (ptrRegData) { (*ptrRegData) = misoData[1]; } |
whismanoid | 59:47538bcf6cda | 1070 | if (commandByte == CMD_0001_1110_d8_Rd07_Status) { |
whismanoid | 59:47538bcf6cda | 1071 | // TODO1: update status |
whismanoid | 63:8f39d21d6157 | 1072 | status = misoData[1]; |
whismanoid | 59:47538bcf6cda | 1073 | } |
whismanoid | 53:3d5a3d241a5e | 1074 | } |
whismanoid | 53:3d5a3d241a5e | 1075 | break; |
whismanoid | 53:3d5a3d241a5e | 1076 | case 16: // 16-bit register size |
whismanoid | 63:8f39d21d6157 | 1077 | #warning "Not Verified Yet: MAX11043::RegRead 16-bit" |
whismanoid | 53:3d5a3d241a5e | 1078 | { |
whismanoid | 60:d1d1eaa90fb7 | 1079 | // SPI 8+16 = 24-bit transfer |
whismanoid | 62:8223a7253c90 | 1080 | // 1234 5678 ___[1]_16 ___[2]_24 |
whismanoid | 60:d1d1eaa90fb7 | 1081 | // SPI MOSI = 1aaa_aaaa_0000_0000_0000_0000 ... _0000 |
whismanoid | 60:d1d1eaa90fb7 | 1082 | // SPI MISO = xxxx_xxxx_dddd_dddd_dddd_dddd ... _xxxx |
whismanoid | 63:8f39d21d6157 | 1083 | size_t byteCount = 1 + 2; |
whismanoid | 63:8f39d21d6157 | 1084 | uint8_t mosiData[3]; |
whismanoid | 63:8f39d21d6157 | 1085 | uint8_t misoData[3]; |
whismanoid | 63:8f39d21d6157 | 1086 | mosiData[0] = CMDOP_0aaa_aa10_ReadRegister | commandByte; |
whismanoid | 63:8f39d21d6157 | 1087 | mosiData[1] = 0; // CMDOP_1111_1111_NoOperationMOSIidleHigh; |
whismanoid | 63:8f39d21d6157 | 1088 | mosiData[2] = 0; // CMDOP_1111_1111_NoOperationMOSIidleHigh; |
whismanoid | 63:8f39d21d6157 | 1089 | // SPIreadWriteWithLowCS(size_t byteCount, uint8_t mosiData[], uint8_t misoData[]); |
whismanoid | 63:8f39d21d6157 | 1090 | SPIreadWriteWithLowCS(byteCount, mosiData, misoData); |
whismanoid | 63:8f39d21d6157 | 1091 | if (ptrRegData) { (*ptrRegData) = (misoData[1] << 8) | misoData[2]; } |
whismanoid | 59:47538bcf6cda | 1092 | if (commandByte == CMD_0010_0010_d16_Rd08_Configuration) { |
whismanoid | 59:47538bcf6cda | 1093 | // TODO1: update config |
whismanoid | 63:8f39d21d6157 | 1094 | config = (misoData[1] << 8) | misoData[2]; |
whismanoid | 59:47538bcf6cda | 1095 | } |
whismanoid | 59:47538bcf6cda | 1096 | if (commandByte == CMD_0000_0010_d16o8_Rd00_ADCa) { |
whismanoid | 59:47538bcf6cda | 1097 | // TODO1: update adca |
whismanoid | 91:9e78c6194d6e | 1098 | // adca = (misoData[1] << 8) | misoData[2]; |
whismanoid | 91:9e78c6194d6e | 1099 | // TODO1: update adca as 2's complement |
whismanoid | 91:9e78c6194d6e | 1100 | // int raw_code = (misoData[1] << 8) | misoData[2]; |
whismanoid | 91:9e78c6194d6e | 1101 | // if (raw_code & 0x8000) { adca = raw_code - 65536; } else { adca = raw_code; } |
whismanoid | 91:9e78c6194d6e | 1102 | adca = SIGN_EXTEND_INT16_VALUE((int)(misoData[1] << 8) | misoData[2]); |
whismanoid | 59:47538bcf6cda | 1103 | } |
whismanoid | 59:47538bcf6cda | 1104 | if (commandByte == CMD_0000_0110_d16o8_Rd01_ADCb) { |
whismanoid | 59:47538bcf6cda | 1105 | // TODO1: update adcb |
whismanoid | 91:9e78c6194d6e | 1106 | // adcb = (misoData[1] << 8) | misoData[2]; |
whismanoid | 91:9e78c6194d6e | 1107 | // TODO1: update adca as 2's complement |
whismanoid | 91:9e78c6194d6e | 1108 | // int raw_code = (misoData[1] << 8) | misoData[2]; |
whismanoid | 91:9e78c6194d6e | 1109 | // if (raw_code & 0x8000) { adca = raw_code - 65536; } else { adca = raw_code; } |
whismanoid | 91:9e78c6194d6e | 1110 | adcb = SIGN_EXTEND_INT16_VALUE((int)(misoData[1] << 8) | misoData[2]); |
whismanoid | 59:47538bcf6cda | 1111 | } |
whismanoid | 59:47538bcf6cda | 1112 | if (commandByte == CMD_0000_1010_d16o8_Rd02_ADCc) { |
whismanoid | 59:47538bcf6cda | 1113 | // TODO1: update adcc |
whismanoid | 91:9e78c6194d6e | 1114 | // adcc = (misoData[1] << 8) | misoData[2]; |
whismanoid | 91:9e78c6194d6e | 1115 | // TODO1: update adca as 2's complement |
whismanoid | 91:9e78c6194d6e | 1116 | // int raw_code = (misoData[1] << 8) | misoData[2]; |
whismanoid | 91:9e78c6194d6e | 1117 | // if (raw_code & 0x8000) { adca = raw_code - 65536; } else { adca = raw_code; } |
whismanoid | 91:9e78c6194d6e | 1118 | adcc = SIGN_EXTEND_INT16_VALUE((int)(misoData[1] << 8) | misoData[2]); |
whismanoid | 59:47538bcf6cda | 1119 | } |
whismanoid | 59:47538bcf6cda | 1120 | if (commandByte == CMD_0000_1110_d16o8_Rd03_ADCd) { |
whismanoid | 59:47538bcf6cda | 1121 | // TODO1: update adcd |
whismanoid | 91:9e78c6194d6e | 1122 | // adcd = (misoData[1] << 8) | misoData[2]; |
whismanoid | 91:9e78c6194d6e | 1123 | // TODO1: update adca as 2's complement |
whismanoid | 91:9e78c6194d6e | 1124 | // int raw_code = (misoData[1] << 8) | misoData[2]; |
whismanoid | 91:9e78c6194d6e | 1125 | // if (raw_code & 0x8000) { adca = raw_code - 65536; } else { adca = raw_code; } |
whismanoid | 91:9e78c6194d6e | 1126 | adcd = SIGN_EXTEND_INT16_VALUE((int)(misoData[1] << 8) | misoData[2]); |
whismanoid | 59:47538bcf6cda | 1127 | } |
whismanoid | 53:3d5a3d241a5e | 1128 | } |
whismanoid | 53:3d5a3d241a5e | 1129 | break; |
whismanoid | 53:3d5a3d241a5e | 1130 | case 24: // 24-bit register size |
whismanoid | 53:3d5a3d241a5e | 1131 | { |
whismanoid | 60:d1d1eaa90fb7 | 1132 | // SPI 8+24 = 32-bit transfer |
whismanoid | 62:8223a7253c90 | 1133 | // 1234 5678 ___[1]_16 ___[2]_24 ___[3]_32 |
whismanoid | 63:8f39d21d6157 | 1134 | // SPI MOSI = 1aaa_aaaa_0000_0000_0000_0000_0000_0000 ... _0000 |
whismanoid | 63:8f39d21d6157 | 1135 | // SPI MISO = xxxx_xxxx_dddd_dddd_dddd_dddd_dddd_dddd ... _xxxx |
whismanoid | 63:8f39d21d6157 | 1136 | size_t byteCount = 1 + 3; |
whismanoid | 63:8f39d21d6157 | 1137 | uint8_t mosiData[4]; |
whismanoid | 63:8f39d21d6157 | 1138 | uint8_t misoData[4]; |
whismanoid | 63:8f39d21d6157 | 1139 | mosiData[0] = CMDOP_0aaa_aa10_ReadRegister | commandByte; |
whismanoid | 63:8f39d21d6157 | 1140 | mosiData[1] = 0; // CMDOP_1111_1111_NoOperationMOSIidleHigh; |
whismanoid | 63:8f39d21d6157 | 1141 | mosiData[2] = 0; // CMDOP_1111_1111_NoOperationMOSIidleHigh; |
whismanoid | 63:8f39d21d6157 | 1142 | mosiData[3] = 0; // CMDOP_1111_1111_NoOperationMOSIidleHigh; |
whismanoid | 63:8f39d21d6157 | 1143 | // SPIreadWriteWithLowCS(size_t byteCount, uint8_t mosiData[], uint8_t misoData[]); |
whismanoid | 63:8f39d21d6157 | 1144 | SPIreadWriteWithLowCS(byteCount, mosiData, misoData); |
whismanoid | 63:8f39d21d6157 | 1145 | if (ptrRegData) { (*ptrRegData) = (misoData[1] << 16) | (misoData[2] << 8) | misoData[3]; } |
whismanoid | 59:47538bcf6cda | 1146 | if (commandByte == CMD_0000_0010_d16o8_Rd00_ADCa) { |
whismanoid | 59:47538bcf6cda | 1147 | // TODO1: update adca |
whismanoid | 63:8f39d21d6157 | 1148 | adca = (misoData[1] << 16) | (misoData[2] << 8) | misoData[3]; |
whismanoid | 59:47538bcf6cda | 1149 | } |
whismanoid | 59:47538bcf6cda | 1150 | if (commandByte == CMD_0000_0110_d16o8_Rd01_ADCb) { |
whismanoid | 59:47538bcf6cda | 1151 | // TODO1: update adcb |
whismanoid | 63:8f39d21d6157 | 1152 | adcb = (misoData[1] << 16) | (misoData[2] << 8) | misoData[3]; |
whismanoid | 59:47538bcf6cda | 1153 | } |
whismanoid | 59:47538bcf6cda | 1154 | if (commandByte == CMD_0000_1010_d16o8_Rd02_ADCc) { |
whismanoid | 59:47538bcf6cda | 1155 | // TODO1: update adcc |
whismanoid | 63:8f39d21d6157 | 1156 | adcc = (misoData[1] << 16) | (misoData[2] << 8) | misoData[3]; |
whismanoid | 59:47538bcf6cda | 1157 | } |
whismanoid | 59:47538bcf6cda | 1158 | if (commandByte == CMD_0000_1110_d16o8_Rd03_ADCd) { |
whismanoid | 59:47538bcf6cda | 1159 | // TODO1: update adcd |
whismanoid | 63:8f39d21d6157 | 1160 | adcd = (misoData[1] << 16) | (misoData[2] << 8) | misoData[3]; |
whismanoid | 59:47538bcf6cda | 1161 | } |
whismanoid | 59:47538bcf6cda | 1162 | } |
whismanoid | 59:47538bcf6cda | 1163 | break; |
whismanoid | 63:8f39d21d6157 | 1164 | case 32: // 32-bit register size CMD_0001_0010_d16o8_d16o8_Rd04_ADCab, CMD_0001_0110_d16o8_d16o8_Rd05_ADCcd |
whismanoid | 59:47538bcf6cda | 1165 | // |
whismanoid | 63:8f39d21d6157 | 1166 | #warning "Not Implemented Yet: MAX11043::RegRead 32-bit CMD_0001_0010_d16o8_d16o8_Rd04_ADCab" |
whismanoid | 63:8f39d21d6157 | 1167 | // TODO: support long SPI read CMD_0001_0010_d16o8_d16o8_Rd04_ADCab |
whismanoid | 59:47538bcf6cda | 1168 | // %SW 0x12 (0 0) (0 0) -- for 16-bit read A,B |
whismanoid | 59:47538bcf6cda | 1169 | // update adca, adcb |
whismanoid | 59:47538bcf6cda | 1170 | // |
whismanoid | 63:8f39d21d6157 | 1171 | // TODO: support long SPI read CMD_0001_0110_d16o8_d16o8_Rd05_ADCcd |
whismanoid | 59:47538bcf6cda | 1172 | // %SW 0x16 (0 0) (0 0) -- for 16-bit read C,D |
whismanoid | 59:47538bcf6cda | 1173 | // update adcc, adcd |
whismanoid | 59:47538bcf6cda | 1174 | // |
whismanoid | 59:47538bcf6cda | 1175 | { |
whismanoid | 60:d1d1eaa90fb7 | 1176 | // SPI 8+32 = 40-bit transfer |
whismanoid | 62:8223a7253c90 | 1177 | // 1234 5678 ___[1]_16 ___[2]_24 ___[3]_32 ___[4]_40 |
whismanoid | 60:d1d1eaa90fb7 | 1178 | // SPI MOSI = 1aaa_aaaa_0000_0000_0000_0000_0000_0000_0000_0000 ... _0000 |
whismanoid | 60:d1d1eaa90fb7 | 1179 | // SPI MISO = xxxx_xxxx_dddd_dddd_dddd_dddd_dddd_dddd_dddd_dddd ... _xxxx |
whismanoid | 62:8223a7253c90 | 1180 | size_t byteCount = 1 + (2 * 2); |
whismanoid | 62:8223a7253c90 | 1181 | uint8_t mosiData[5]; |
whismanoid | 62:8223a7253c90 | 1182 | uint8_t misoData[5]; |
whismanoid | 62:8223a7253c90 | 1183 | mosiData[0] = CMDOP_0aaa_aa10_ReadRegister | commandByte; |
whismanoid | 62:8223a7253c90 | 1184 | mosiData[1] = 0; // CMDOP_1111_1111_NoOperationMOSIidleHigh; |
whismanoid | 62:8223a7253c90 | 1185 | mosiData[2] = 0; // CMDOP_1111_1111_NoOperationMOSIidleHigh; |
whismanoid | 62:8223a7253c90 | 1186 | mosiData[3] = 0; // CMDOP_1111_1111_NoOperationMOSIidleHigh; |
whismanoid | 62:8223a7253c90 | 1187 | mosiData[4] = 0; // CMDOP_1111_1111_NoOperationMOSIidleHigh; |
whismanoid | 62:8223a7253c90 | 1188 | // SPIreadWriteWithLowCS(size_t byteCount, uint8_t mosiData[], uint8_t misoData[]); |
whismanoid | 62:8223a7253c90 | 1189 | SPIreadWriteWithLowCS(byteCount, mosiData, misoData); |
whismanoid | 62:8223a7253c90 | 1190 | if (ptrRegData) { (*ptrRegData) = (misoData[1] << 8) | misoData[2]; } |
whismanoid | 63:8f39d21d6157 | 1191 | if (commandByte == CMD_0001_0010_d16o8_d16o8_Rd04_ADCab) { |
whismanoid | 59:47538bcf6cda | 1192 | // TODO1: update adca |
whismanoid | 91:9e78c6194d6e | 1193 | // adca = (misoData[1] << 8) | misoData[2]; |
whismanoid | 91:9e78c6194d6e | 1194 | // TODO1: update adca as 2's complement |
whismanoid | 91:9e78c6194d6e | 1195 | // int raw_code = (misoData[1] << 8) | misoData[2]; |
whismanoid | 91:9e78c6194d6e | 1196 | // if (raw_code & 0x8000) { adca = raw_code - 65536; } else { adca = raw_code; } |
whismanoid | 91:9e78c6194d6e | 1197 | adca = SIGN_EXTEND_INT16_VALUE((int)(misoData[1] << 8) | misoData[2]); |
whismanoid | 59:47538bcf6cda | 1198 | // TODO1: update adcb |
whismanoid | 91:9e78c6194d6e | 1199 | // adcb = (misoData[3] << 8) | misoData[4]; |
whismanoid | 91:9e78c6194d6e | 1200 | // TODO1: update adca as 2's complement |
whismanoid | 91:9e78c6194d6e | 1201 | // int raw_code = (misoData[1] << 8) | misoData[2]; |
whismanoid | 91:9e78c6194d6e | 1202 | // if (raw_code & 0x8000) { adca = raw_code - 65536; } else { adca = raw_code; } |
whismanoid | 91:9e78c6194d6e | 1203 | adcb = SIGN_EXTEND_INT16_VALUE((int)(misoData[3] << 8) | misoData[4]); |
whismanoid | 59:47538bcf6cda | 1204 | } |
whismanoid | 63:8f39d21d6157 | 1205 | if (commandByte == CMD_0001_0110_d16o8_d16o8_Rd05_ADCcd) { |
whismanoid | 59:47538bcf6cda | 1206 | // TODO1: update adcc |
whismanoid | 62:8223a7253c90 | 1207 | adcc = (misoData[1] << 8) | misoData[2]; |
whismanoid | 91:9e78c6194d6e | 1208 | // TODO1: update adca as 2's complement |
whismanoid | 91:9e78c6194d6e | 1209 | // int raw_code = (misoData[1] << 8) | misoData[2]; |
whismanoid | 91:9e78c6194d6e | 1210 | // if (raw_code & 0x8000) { adca = raw_code - 65536; } else { adca = raw_code; } |
whismanoid | 91:9e78c6194d6e | 1211 | adcc = SIGN_EXTEND_INT16_VALUE((int)(misoData[1] << 8) | misoData[2]); |
whismanoid | 59:47538bcf6cda | 1212 | // TODO1: update adcd |
whismanoid | 91:9e78c6194d6e | 1213 | // adcd = (misoData[3] << 8) | misoData[4]; |
whismanoid | 91:9e78c6194d6e | 1214 | // TODO1: update adca as 2's complement |
whismanoid | 91:9e78c6194d6e | 1215 | // int raw_code = (misoData[1] << 8) | misoData[2]; |
whismanoid | 91:9e78c6194d6e | 1216 | // if (raw_code & 0x8000) { adca = raw_code - 65536; } else { adca = raw_code; } |
whismanoid | 91:9e78c6194d6e | 1217 | adcd = SIGN_EXTEND_INT16_VALUE((int)(misoData[3] << 8) | misoData[4]); |
whismanoid | 59:47538bcf6cda | 1218 | } |
whismanoid | 59:47538bcf6cda | 1219 | } |
whismanoid | 59:47538bcf6cda | 1220 | break; |
whismanoid | 63:8f39d21d6157 | 1221 | case 48: // 48-bit register size CMD_0001_0010_d16o8_d16o8_Rd04_ADCab, CMD_0001_0110_d16o8_d16o8_Rd05_ADCcd |
whismanoid | 59:47538bcf6cda | 1222 | // |
whismanoid | 63:8f39d21d6157 | 1223 | #warning "Not Verified Yet: MAX11043::RegRead 48-bit CMD_0001_0010_d16o8_d16o8_Rd04_ADCab" |
whismanoid | 63:8f39d21d6157 | 1224 | // TODO: support long SPI read CMD_0001_0010_d16o8_d16o8_Rd04_ADCab |
whismanoid | 59:47538bcf6cda | 1225 | // %SW 0x12 (0 0 0) (0 0 0) -- for 24-bit read A,B |
whismanoid | 59:47538bcf6cda | 1226 | // update adca, adcb |
whismanoid | 59:47538bcf6cda | 1227 | // |
whismanoid | 63:8f39d21d6157 | 1228 | // TODO: support long SPI read CMD_0001_0110_d16o8_d16o8_Rd05_ADCcd |
whismanoid | 59:47538bcf6cda | 1229 | // %SW 0x16 (0 0 0) (0 0 0) -- for 24-bit read C,D |
whismanoid | 59:47538bcf6cda | 1230 | // update adcc, adcd |
whismanoid | 59:47538bcf6cda | 1231 | // |
whismanoid | 59:47538bcf6cda | 1232 | { |
whismanoid | 60:d1d1eaa90fb7 | 1233 | // SPI 8+48 = 56-bit transfer |
whismanoid | 62:8223a7253c90 | 1234 | // 1234 5678 ___[1]_16 ___[2]_24 ___[3]_32 ___[4]_40 ___[5]_48 ___[6]_56 |
whismanoid | 60:d1d1eaa90fb7 | 1235 | // SPI MOSI = 1aaa_aaaa_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000 ... _0000 |
whismanoid | 60:d1d1eaa90fb7 | 1236 | // SPI MISO = xxxx_xxxx_dddd_dddd_dddd_dddd_dddd_dddd_dddd_dddd_dddd_dddd_dddd_dddd ... _xxxx |
whismanoid | 62:8223a7253c90 | 1237 | size_t byteCount = 1 + (3 * 2); |
whismanoid | 62:8223a7253c90 | 1238 | uint8_t mosiData[7]; |
whismanoid | 62:8223a7253c90 | 1239 | uint8_t misoData[7]; |
whismanoid | 62:8223a7253c90 | 1240 | mosiData[0] = CMDOP_0aaa_aa10_ReadRegister | commandByte; |
whismanoid | 62:8223a7253c90 | 1241 | mosiData[1] = 0; // CMDOP_1111_1111_NoOperationMOSIidleHigh; |
whismanoid | 62:8223a7253c90 | 1242 | mosiData[2] = 0; // CMDOP_1111_1111_NoOperationMOSIidleHigh; |
whismanoid | 62:8223a7253c90 | 1243 | mosiData[3] = 0; // CMDOP_1111_1111_NoOperationMOSIidleHigh; |
whismanoid | 62:8223a7253c90 | 1244 | mosiData[4] = 0; // CMDOP_1111_1111_NoOperationMOSIidleHigh; |
whismanoid | 62:8223a7253c90 | 1245 | mosiData[5] = 0; // CMDOP_1111_1111_NoOperationMOSIidleHigh; |
whismanoid | 62:8223a7253c90 | 1246 | mosiData[6] = 0; // CMDOP_1111_1111_NoOperationMOSIidleHigh; |
whismanoid | 62:8223a7253c90 | 1247 | // SPIreadWriteWithLowCS(size_t byteCount, uint8_t mosiData[], uint8_t misoData[]); |
whismanoid | 62:8223a7253c90 | 1248 | SPIreadWriteWithLowCS(byteCount, mosiData, misoData); |
whismanoid | 62:8223a7253c90 | 1249 | if (ptrRegData) { (*ptrRegData) = (misoData[1] << 16) | (misoData[2] << 8) | misoData[3]; } |
whismanoid | 63:8f39d21d6157 | 1250 | if (commandByte == CMD_0001_0010_d16o8_d16o8_Rd04_ADCab) { |
whismanoid | 59:47538bcf6cda | 1251 | // TODO1: update adca |
whismanoid | 62:8223a7253c90 | 1252 | adca = (misoData[1] << 16) | (misoData[2] << 8) | misoData[3]; |
whismanoid | 59:47538bcf6cda | 1253 | // TODO1: update adcb |
whismanoid | 62:8223a7253c90 | 1254 | adcb = (misoData[4] << 16) | (misoData[5] << 8) | misoData[6]; |
whismanoid | 59:47538bcf6cda | 1255 | } |
whismanoid | 63:8f39d21d6157 | 1256 | if (commandByte == CMD_0001_0110_d16o8_d16o8_Rd05_ADCcd) { |
whismanoid | 59:47538bcf6cda | 1257 | // TODO1: update adcc |
whismanoid | 62:8223a7253c90 | 1258 | adcc = (misoData[1] << 16) | (misoData[2] << 8) | misoData[3]; |
whismanoid | 59:47538bcf6cda | 1259 | // TODO1: update adcd |
whismanoid | 62:8223a7253c90 | 1260 | adcd = (misoData[4] << 16) | (misoData[5] << 8) | misoData[6]; |
whismanoid | 59:47538bcf6cda | 1261 | } |
whismanoid | 59:47538bcf6cda | 1262 | } |
whismanoid | 59:47538bcf6cda | 1263 | break; |
whismanoid | 63:8f39d21d6157 | 1264 | case 64: // 64-bit register size CMD_0001_1010_d16o8_d16o8_d16o8_d16o8_Rd06_ADCabcd |
whismanoid | 59:47538bcf6cda | 1265 | // |
whismanoid | 63:8f39d21d6157 | 1266 | #warning "Not Verified Yet: MAX11043::RegRead 64-bit CMD_0001_1010_d16o8_d16o8_d16o8_d16o8_Rd06_ADCabcd" |
whismanoid | 63:8f39d21d6157 | 1267 | // TODO: support long SPI read CMD_0001_1010_d16o8_d16o8_d16o8_d16o8_Rd06_ADCabcd |
whismanoid | 59:47538bcf6cda | 1268 | // %SW 0x1A (0 0) (0 0) (0 0) (0 0) -- for 16-bit read A,B,C,D |
whismanoid | 59:47538bcf6cda | 1269 | // update adca, adcb, adcc, adcd |
whismanoid | 59:47538bcf6cda | 1270 | // |
whismanoid | 59:47538bcf6cda | 1271 | { |
whismanoid | 60:d1d1eaa90fb7 | 1272 | // SPI 8+64 = 72-bit transfer |
whismanoid | 62:8223a7253c90 | 1273 | // 1234 5678 ___[1]_16 ___[2]_24 ___[3]_32 ___[4]_40 ___[5]_48 ___[6]_56 ___[7]_64 ___[8]_72 |
whismanoid | 60:d1d1eaa90fb7 | 1274 | // SPI MOSI = 1aaa_aaaa_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000 ... _0000 |
whismanoid | 60:d1d1eaa90fb7 | 1275 | // SPI MISO = xxxx_xxxx_dddd_dddd_dddd_dddd_dddd_dddd_dddd_dddd_dddd_dddd_dddd_dddd_dddd_dddd_dddd_dddd ... _xxxx |
whismanoid | 62:8223a7253c90 | 1276 | size_t byteCount = 1 + (2 * 4); |
whismanoid | 62:8223a7253c90 | 1277 | uint8_t mosiData[9]; |
whismanoid | 62:8223a7253c90 | 1278 | uint8_t misoData[9]; |
whismanoid | 62:8223a7253c90 | 1279 | mosiData[0] = CMDOP_0aaa_aa10_ReadRegister | commandByte; |
whismanoid | 62:8223a7253c90 | 1280 | mosiData[1] = 0; // CMDOP_1111_1111_NoOperationMOSIidleHigh; |
whismanoid | 62:8223a7253c90 | 1281 | mosiData[2] = 0; // CMDOP_1111_1111_NoOperationMOSIidleHigh; |
whismanoid | 62:8223a7253c90 | 1282 | mosiData[3] = 0; // CMDOP_1111_1111_NoOperationMOSIidleHigh; |
whismanoid | 62:8223a7253c90 | 1283 | mosiData[4] = 0; // CMDOP_1111_1111_NoOperationMOSIidleHigh; |
whismanoid | 62:8223a7253c90 | 1284 | mosiData[5] = 0; // CMDOP_1111_1111_NoOperationMOSIidleHigh; |
whismanoid | 62:8223a7253c90 | 1285 | mosiData[6] = 0; // CMDOP_1111_1111_NoOperationMOSIidleHigh; |
whismanoid | 62:8223a7253c90 | 1286 | mosiData[7] = 0; // CMDOP_1111_1111_NoOperationMOSIidleHigh; |
whismanoid | 62:8223a7253c90 | 1287 | mosiData[8] = 0; // CMDOP_1111_1111_NoOperationMOSIidleHigh; |
whismanoid | 62:8223a7253c90 | 1288 | // SPIreadWriteWithLowCS(size_t byteCount, uint8_t mosiData[], uint8_t misoData[]); |
whismanoid | 62:8223a7253c90 | 1289 | SPIreadWriteWithLowCS(byteCount, mosiData, misoData); |
whismanoid | 62:8223a7253c90 | 1290 | if (ptrRegData) { (*ptrRegData) = (misoData[1] << 8) | misoData[2]; } |
whismanoid | 63:8f39d21d6157 | 1291 | if (commandByte == CMD_0001_1010_d16o8_d16o8_d16o8_d16o8_Rd06_ADCabcd) { |
whismanoid | 59:47538bcf6cda | 1292 | // TODO1: update adca |
whismanoid | 91:9e78c6194d6e | 1293 | // adca = (misoData[1] << 8) | misoData[2]; |
whismanoid | 91:9e78c6194d6e | 1294 | // TODO1: update adca as 2's complement |
whismanoid | 91:9e78c6194d6e | 1295 | // int raw_code = (misoData[1] << 8) | misoData[2]; |
whismanoid | 91:9e78c6194d6e | 1296 | // if (raw_code & 0x8000) { adca = raw_code - 65536; } else { adca = raw_code; } |
whismanoid | 91:9e78c6194d6e | 1297 | adca = SIGN_EXTEND_INT16_VALUE((int)(misoData[1] << 8) | misoData[2]); |
whismanoid | 91:9e78c6194d6e | 1298 | // |
whismanoid | 59:47538bcf6cda | 1299 | // TODO1: update adcb |
whismanoid | 91:9e78c6194d6e | 1300 | // adcb = (misoData[3] << 8) | misoData[4]; |
whismanoid | 91:9e78c6194d6e | 1301 | // TODO1: update adcb as 2's complement |
whismanoid | 91:9e78c6194d6e | 1302 | // raw_code = (misoData[3] << 8) | misoData[4]; |
whismanoid | 91:9e78c6194d6e | 1303 | // if (raw_code & 0x8000) { adcb = raw_code - 65536; } else { adcb = raw_code; } |
whismanoid | 91:9e78c6194d6e | 1304 | adcb = SIGN_EXTEND_INT16_VALUE((int)(misoData[3] << 8) | misoData[4]); |
whismanoid | 91:9e78c6194d6e | 1305 | // |
whismanoid | 59:47538bcf6cda | 1306 | // TODO1: update adcc |
whismanoid | 91:9e78c6194d6e | 1307 | // adcc = (misoData[5] << 8) | misoData[6]; |
whismanoid | 91:9e78c6194d6e | 1308 | // TODO1: update adcc as 2's complement |
whismanoid | 91:9e78c6194d6e | 1309 | // raw_code = (misoData[5] << 8) | misoData[6]; |
whismanoid | 91:9e78c6194d6e | 1310 | // if (raw_code & 0x8000) { adcc = raw_code - 65536; } else { adcc = raw_code; } |
whismanoid | 91:9e78c6194d6e | 1311 | adcc = SIGN_EXTEND_INT16_VALUE((int)(misoData[5] << 8) | misoData[6]); |
whismanoid | 91:9e78c6194d6e | 1312 | // |
whismanoid | 59:47538bcf6cda | 1313 | // TODO1: update adcd |
whismanoid | 91:9e78c6194d6e | 1314 | // adcd = (misoData[7] << 8) | misoData[8]; |
whismanoid | 91:9e78c6194d6e | 1315 | // TODO1: update adcd as 2's complement |
whismanoid | 91:9e78c6194d6e | 1316 | // raw_code = (misoData[7] << 8) | misoData[8]; |
whismanoid | 91:9e78c6194d6e | 1317 | // if (raw_code & 0x8000) { adcd = raw_code - 65536; } else { adcd = raw_code; } |
whismanoid | 91:9e78c6194d6e | 1318 | adcd = SIGN_EXTEND_INT16_VALUE((int)(misoData[7] << 8) | misoData[8]); |
whismanoid | 91:9e78c6194d6e | 1319 | // |
whismanoid | 59:47538bcf6cda | 1320 | } |
whismanoid | 59:47538bcf6cda | 1321 | } |
whismanoid | 59:47538bcf6cda | 1322 | break; |
whismanoid | 63:8f39d21d6157 | 1323 | case 96: // 96-bit register size CMD_0001_1010_d16o8_d16o8_d16o8_d16o8_Rd06_ADCabcd |
whismanoid | 59:47538bcf6cda | 1324 | // |
whismanoid | 63:8f39d21d6157 | 1325 | #warning "Not Verified Yet: MAX11043::RegRead 96-bit CMD_0001_1010_d16o8_d16o8_d16o8_d16o8_Rd06_ADCabcd" |
whismanoid | 63:8f39d21d6157 | 1326 | // TODO: support long SPI read CMD_0001_1010_d16o8_d16o8_d16o8_d16o8_Rd06_ADCabcd |
whismanoid | 59:47538bcf6cda | 1327 | // %SW 0x1A (0 0 0) (0 0 0) (0 0 0) (0 0 0) -- for 24-bit read A,B,C,D |
whismanoid | 59:47538bcf6cda | 1328 | // update adca, adcb, adcc, adcd |
whismanoid | 59:47538bcf6cda | 1329 | // |
whismanoid | 59:47538bcf6cda | 1330 | { |
whismanoid | 60:d1d1eaa90fb7 | 1331 | // SPI 8+96 = 104-bit transfer |
whismanoid | 62:8223a7253c90 | 1332 | // 1234 5678 ___[1]_16 ___[2]_24 ___[3]_32 ___[4]_40 ___[5]_48 ___[6]_56 ___[7]_64 ___[8]_72 ___[9]_80 __[10]_88 __[11]_96 __[12]104 |
whismanoid | 60:d1d1eaa90fb7 | 1333 | // SPI MOSI = 1aaa_aaaa_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000 ... _0000 |
whismanoid | 60:d1d1eaa90fb7 | 1334 | // SPI MISO = xxxx_xxxx_dddd_dddd_dddd_dddd_dddd_dddd_dddd_dddd_dddd_dddd_dddd_dddd_dddd_dddd_dddd_dddd_dddd_dddd_dddd_dddd_dddd_dddd_dddd_dddd ... _xxxx |
whismanoid | 62:8223a7253c90 | 1335 | size_t byteCount = 1 + (3 * 4); |
whismanoid | 62:8223a7253c90 | 1336 | uint8_t mosiData[13]; |
whismanoid | 62:8223a7253c90 | 1337 | uint8_t misoData[13]; |
whismanoid | 62:8223a7253c90 | 1338 | mosiData[0] = CMDOP_0aaa_aa10_ReadRegister | commandByte; |
whismanoid | 62:8223a7253c90 | 1339 | mosiData[1] = 0; // CMDOP_1111_1111_NoOperationMOSIidleHigh; |
whismanoid | 62:8223a7253c90 | 1340 | mosiData[2] = 0; // CMDOP_1111_1111_NoOperationMOSIidleHigh; |
whismanoid | 62:8223a7253c90 | 1341 | mosiData[3] = 0; // CMDOP_1111_1111_NoOperationMOSIidleHigh; |
whismanoid | 62:8223a7253c90 | 1342 | mosiData[4] = 0; // CMDOP_1111_1111_NoOperationMOSIidleHigh; |
whismanoid | 62:8223a7253c90 | 1343 | mosiData[5] = 0; // CMDOP_1111_1111_NoOperationMOSIidleHigh; |
whismanoid | 62:8223a7253c90 | 1344 | mosiData[6] = 0; // CMDOP_1111_1111_NoOperationMOSIidleHigh; |
whismanoid | 62:8223a7253c90 | 1345 | mosiData[7] = 0; // CMDOP_1111_1111_NoOperationMOSIidleHigh; |
whismanoid | 62:8223a7253c90 | 1346 | mosiData[8] = 0; // CMDOP_1111_1111_NoOperationMOSIidleHigh; |
whismanoid | 62:8223a7253c90 | 1347 | mosiData[9] = 0; // CMDOP_1111_1111_NoOperationMOSIidleHigh; |
whismanoid | 62:8223a7253c90 | 1348 | mosiData[10] = 0; // CMDOP_1111_1111_NoOperationMOSIidleHigh; |
whismanoid | 62:8223a7253c90 | 1349 | mosiData[11] = 0; // CMDOP_1111_1111_NoOperationMOSIidleHigh; |
whismanoid | 62:8223a7253c90 | 1350 | mosiData[12] = 0; // CMDOP_1111_1111_NoOperationMOSIidleHigh; |
whismanoid | 62:8223a7253c90 | 1351 | // SPIreadWriteWithLowCS(size_t byteCount, uint8_t mosiData[], uint8_t misoData[]); |
whismanoid | 62:8223a7253c90 | 1352 | SPIreadWriteWithLowCS(byteCount, mosiData, misoData); |
whismanoid | 62:8223a7253c90 | 1353 | if (ptrRegData) { (*ptrRegData) = (misoData[1] << 16) | (misoData[2] << 8) | misoData[3]; } |
whismanoid | 63:8f39d21d6157 | 1354 | if (commandByte == CMD_0001_1010_d16o8_d16o8_d16o8_d16o8_Rd06_ADCabcd) { |
whismanoid | 59:47538bcf6cda | 1355 | // TODO1: update adca |
whismanoid | 62:8223a7253c90 | 1356 | adca = (misoData[1] << 16) | (misoData[2] << 8) | misoData[3]; |
whismanoid | 59:47538bcf6cda | 1357 | // TODO1: update adcb |
whismanoid | 62:8223a7253c90 | 1358 | adcb = (misoData[4] << 16) | (misoData[5] << 8) | misoData[6]; |
whismanoid | 59:47538bcf6cda | 1359 | // TODO1: update adcc |
whismanoid | 62:8223a7253c90 | 1360 | adcc = (misoData[7] << 16) | (misoData[8] << 8) | misoData[9]; |
whismanoid | 59:47538bcf6cda | 1361 | // TODO1: update adcd |
whismanoid | 62:8223a7253c90 | 1362 | adcd = (misoData[10] << 16) | (misoData[11] << 8) | misoData[12]; |
whismanoid | 59:47538bcf6cda | 1363 | } |
whismanoid | 53:3d5a3d241a5e | 1364 | } |
whismanoid | 53:3d5a3d241a5e | 1365 | break; |
whismanoid | 53:3d5a3d241a5e | 1366 | } |
whismanoid | 53:3d5a3d241a5e | 1367 | |
whismanoid | 53:3d5a3d241a5e | 1368 | //---------------------------------------- |
whismanoid | 53:3d5a3d241a5e | 1369 | // success |
whismanoid | 53:3d5a3d241a5e | 1370 | return 1; |
whismanoid | 53:3d5a3d241a5e | 1371 | } |
whismanoid | 53:3d5a3d241a5e | 1372 | |
whismanoid | 53:3d5a3d241a5e | 1373 | //---------------------------------------- |
whismanoid | 53:3d5a3d241a5e | 1374 | // Return the size of a MAX11043 register |
whismanoid | 53:3d5a3d241a5e | 1375 | // |
whismanoid | 53:3d5a3d241a5e | 1376 | // @return 8 for 8-bit, 16 for 16-bit, 24 for 24-bit, else 0 for undefined register size |
whismanoid | 53:3d5a3d241a5e | 1377 | uint8_t MAX11043::RegSize(MAX11043_CMD_enum_t commandByte) |
whismanoid | 53:3d5a3d241a5e | 1378 | { |
whismanoid | 53:3d5a3d241a5e | 1379 | |
whismanoid | 53:3d5a3d241a5e | 1380 | //---------------------------------------- |
whismanoid | 53:3d5a3d241a5e | 1381 | // switch based on register address value regAddress |
whismanoid | 57:1c9da8e90737 | 1382 | // commandByte = (MAX11043_CMD_enum_t)((commandByte &~ CMDOP_0aaa_aa10_ReadRegister) & 0xFF); |
whismanoid | 53:3d5a3d241a5e | 1383 | switch(commandByte) |
whismanoid | 53:3d5a3d241a5e | 1384 | { |
whismanoid | 53:3d5a3d241a5e | 1385 | default: |
whismanoid | 57:1c9da8e90737 | 1386 | // case CMDOP_0aaa_aa00_WriteRegister: |
whismanoid | 57:1c9da8e90737 | 1387 | // case CMDOP_0aaa_aa10_ReadRegister: |
whismanoid | 57:1c9da8e90737 | 1388 | // case CMDOP_1111_1111_NoOperationMOSIidleHigh: |
whismanoid | 53:3d5a3d241a5e | 1389 | return 0; // undefined register size |
whismanoid | 53:3d5a3d241a5e | 1390 | case CMD_0001_1110_d8_Rd07_Status: |
whismanoid | 53:3d5a3d241a5e | 1391 | case CMD_0101_0100_d8_Wr15_FilterCAddress: |
whismanoid | 53:3d5a3d241a5e | 1392 | case CMD_0101_0110_d8_Rd15_FilterCAddress: |
whismanoid | 53:3d5a3d241a5e | 1393 | case CMD_0110_0000_d8_Wr18_FlashMode: |
whismanoid | 53:3d5a3d241a5e | 1394 | case CMD_0110_0010_d8_Rd18_FlashMode: |
whismanoid | 53:3d5a3d241a5e | 1395 | return 8; // 8-bit register size |
whismanoid | 53:3d5a3d241a5e | 1396 | case CMD_0010_0000_d16_Wr08_Configuration: |
whismanoid | 53:3d5a3d241a5e | 1397 | case CMD_0010_0010_d16_Rd08_Configuration: |
whismanoid | 53:3d5a3d241a5e | 1398 | case CMD_0010_0100_d16_Wr09_DAC: |
whismanoid | 53:3d5a3d241a5e | 1399 | case CMD_0010_0110_d16_Rd09_DAC: |
whismanoid | 53:3d5a3d241a5e | 1400 | case CMD_0010_1000_d16_Wr0A_DACStep: |
whismanoid | 53:3d5a3d241a5e | 1401 | case CMD_0010_1010_d16_Rd0A_DACStep: |
whismanoid | 53:3d5a3d241a5e | 1402 | case CMD_0010_1100_d16_Wr0B_DACHDACL: |
whismanoid | 53:3d5a3d241a5e | 1403 | case CMD_0010_1110_d16_Rd0B_DACHDACL: |
whismanoid | 53:3d5a3d241a5e | 1404 | case CMD_0011_0000_d16_Wr0C_ConfigA: |
whismanoid | 53:3d5a3d241a5e | 1405 | case CMD_0011_0010_d16_Rd0C_ConfigA: |
whismanoid | 53:3d5a3d241a5e | 1406 | case CMD_0011_0100_d16_Wr0D_ConfigB: |
whismanoid | 53:3d5a3d241a5e | 1407 | case CMD_0011_0110_d16_Rd0D_ConfigB: |
whismanoid | 53:3d5a3d241a5e | 1408 | case CMD_0011_1000_d16_Wr0E_ConfigC: |
whismanoid | 53:3d5a3d241a5e | 1409 | case CMD_0011_1010_d16_Rd0E_ConfigC: |
whismanoid | 53:3d5a3d241a5e | 1410 | case CMD_0011_1100_d16_Wr0F_ConfigD: |
whismanoid | 53:3d5a3d241a5e | 1411 | case CMD_0011_1110_d16_Rd0F_ConfigD: |
whismanoid | 53:3d5a3d241a5e | 1412 | case CMD_0100_0000_d16_Wr10_Reference: |
whismanoid | 53:3d5a3d241a5e | 1413 | case CMD_0100_0010_d16_Rd10_Reference: |
whismanoid | 53:3d5a3d241a5e | 1414 | case CMD_0100_0100_d16_Wr11_AGain: |
whismanoid | 53:3d5a3d241a5e | 1415 | case CMD_0100_0110_d16_Rd11_AGain: |
whismanoid | 53:3d5a3d241a5e | 1416 | case CMD_0100_1000_d16_Wr12_BGain: |
whismanoid | 53:3d5a3d241a5e | 1417 | case CMD_0100_1010_d16_Rd12_BGain: |
whismanoid | 53:3d5a3d241a5e | 1418 | case CMD_0100_1100_d16_Wr13_CGain: |
whismanoid | 53:3d5a3d241a5e | 1419 | case CMD_0100_1110_d16_Rd13_CGain: |
whismanoid | 53:3d5a3d241a5e | 1420 | case CMD_0101_0000_d16_Wr14_DGain: |
whismanoid | 53:3d5a3d241a5e | 1421 | case CMD_0101_0010_d16_Rd14_DGain: |
whismanoid | 53:3d5a3d241a5e | 1422 | case CMD_0110_0100_d16_Wr19_FlashAddr: |
whismanoid | 53:3d5a3d241a5e | 1423 | case CMD_0110_0110_d16_Rd19_FlashAddr: |
whismanoid | 53:3d5a3d241a5e | 1424 | case CMD_0110_1000_d16_Wr1A_FlashDataIn: |
whismanoid | 53:3d5a3d241a5e | 1425 | case CMD_0110_1010_d16_Rd1A_FlashDataIn: |
whismanoid | 53:3d5a3d241a5e | 1426 | case CMD_0110_1110_d16_Rd1B_FlashDataOut: |
whismanoid | 53:3d5a3d241a5e | 1427 | return 16; // 16-bit register size |
whismanoid | 59:47538bcf6cda | 1428 | case CMD_0000_0010_d16o8_Rd00_ADCa: |
whismanoid | 59:47538bcf6cda | 1429 | case CMD_0000_0110_d16o8_Rd01_ADCb: |
whismanoid | 59:47538bcf6cda | 1430 | case CMD_0000_1010_d16o8_Rd02_ADCc: |
whismanoid | 59:47538bcf6cda | 1431 | case CMD_0000_1110_d16o8_Rd03_ADCd: |
whismanoid | 59:47538bcf6cda | 1432 | if (config & CONFIG_xxxx_xxxx_xx1x_xxxx_24BIT) |
whismanoid | 59:47538bcf6cda | 1433 | { |
whismanoid | 59:47538bcf6cda | 1434 | // %SW 0x02 (0 0 0) -- for 24-bit read |
whismanoid | 59:47538bcf6cda | 1435 | return 24; // 24-bit register size |
whismanoid | 59:47538bcf6cda | 1436 | } |
whismanoid | 59:47538bcf6cda | 1437 | // %SW 0x02 (0 0) -- for 16-bit read |
whismanoid | 59:47538bcf6cda | 1438 | // |
whismanoid | 59:47538bcf6cda | 1439 | return 16; // 16-bit register size |
whismanoid | 63:8f39d21d6157 | 1440 | case CMD_0001_0010_d16o8_d16o8_Rd04_ADCab: |
whismanoid | 63:8f39d21d6157 | 1441 | case CMD_0001_0110_d16o8_d16o8_Rd05_ADCcd: |
whismanoid | 59:47538bcf6cda | 1442 | // |
whismanoid | 59:47538bcf6cda | 1443 | // TODO: support long SPI read |
whismanoid | 59:47538bcf6cda | 1444 | if (config & CONFIG_xxxx_xxxx_xx1x_xxxx_24BIT) |
whismanoid | 59:47538bcf6cda | 1445 | { |
whismanoid | 59:47538bcf6cda | 1446 | // %SW 0x12 (0 0 0) (0 0 0) -- for 24-bit read A,B |
whismanoid | 59:47538bcf6cda | 1447 | // %SW 0x16 (0 0 0) (0 0 0) -- for 24-bit read C,D |
whismanoid | 59:47538bcf6cda | 1448 | return 48; // 48-bit register size: 2*(24) |
whismanoid | 59:47538bcf6cda | 1449 | } |
whismanoid | 59:47538bcf6cda | 1450 | // %SW 0x12 (0 0) (0 0) -- for 16-bit read A,B |
whismanoid | 59:47538bcf6cda | 1451 | // %SW 0x16 (0 0) (0 0) -- for 16-bit read C,D |
whismanoid | 59:47538bcf6cda | 1452 | // |
whismanoid | 59:47538bcf6cda | 1453 | return 32; // 32-bit register size: 2*(16) |
whismanoid | 63:8f39d21d6157 | 1454 | case CMD_0001_1010_d16o8_d16o8_d16o8_d16o8_Rd06_ADCabcd: |
whismanoid | 59:47538bcf6cda | 1455 | // |
whismanoid | 59:47538bcf6cda | 1456 | // TODO: support long SPI read |
whismanoid | 59:47538bcf6cda | 1457 | if (config & CONFIG_xxxx_xxxx_xx1x_xxxx_24BIT) |
whismanoid | 59:47538bcf6cda | 1458 | { |
whismanoid | 59:47538bcf6cda | 1459 | // %SW 0x1A (0 0 0) (0 0 0) (0 0 0) (0 0 0) -- for 24-bit read A,B,C,D |
whismanoid | 59:47538bcf6cda | 1460 | return 96; // 96-bit register size: 4*(24) |
whismanoid | 59:47538bcf6cda | 1461 | } |
whismanoid | 59:47538bcf6cda | 1462 | // %SW 0x1A (0 0) (0 0) (0 0) (0 0) -- for 16-bit read A,B,C,D |
whismanoid | 59:47538bcf6cda | 1463 | // |
whismanoid | 59:47538bcf6cda | 1464 | return 64; // 64-bit register size: 4*(16) |
whismanoid | 53:3d5a3d241a5e | 1465 | case CMD_0101_1000_d32_Wr16_FilterCDataOut: |
whismanoid | 53:3d5a3d241a5e | 1466 | case CMD_0101_1010_d32_Rd16_FilterCDataOut: |
whismanoid | 53:3d5a3d241a5e | 1467 | case CMD_0101_1100_d32_Wr17_FilterCDataIn: |
whismanoid | 53:3d5a3d241a5e | 1468 | case CMD_0101_1110_d32_Rd17_FilterCDataIn: |
whismanoid | 53:3d5a3d241a5e | 1469 | return 32; // 32-bit register size |
whismanoid | 53:3d5a3d241a5e | 1470 | } |
whismanoid | 53:3d5a3d241a5e | 1471 | } |
whismanoid | 53:3d5a3d241a5e | 1472 | |
whismanoid | 53:3d5a3d241a5e | 1473 | //---------------------------------------- |
whismanoid | 57:1c9da8e90737 | 1474 | // Decode operation from commandByte |
whismanoid | 57:1c9da8e90737 | 1475 | // |
whismanoid | 57:1c9da8e90737 | 1476 | // @return operation such as idle, read register, write register, etc. |
whismanoid | 57:1c9da8e90737 | 1477 | MAX11043::MAX11043_CMDOP_enum_t MAX11043::DecodeCommand(MAX11043_CMD_enum_t commandByte) |
whismanoid | 57:1c9da8e90737 | 1478 | { |
whismanoid | 57:1c9da8e90737 | 1479 | |
whismanoid | 57:1c9da8e90737 | 1480 | //---------------------------------------- |
whismanoid | 57:1c9da8e90737 | 1481 | // decode operation from command byte |
whismanoid | 57:1c9da8e90737 | 1482 | switch (commandByte & 0x83) |
whismanoid | 57:1c9da8e90737 | 1483 | { |
whismanoid | 57:1c9da8e90737 | 1484 | case CMDOP_0aaa_aa10_ReadRegister: |
whismanoid | 57:1c9da8e90737 | 1485 | return CMDOP_0aaa_aa10_ReadRegister; |
whismanoid | 57:1c9da8e90737 | 1486 | case CMDOP_0aaa_aa00_WriteRegister: |
whismanoid | 57:1c9da8e90737 | 1487 | return CMDOP_0aaa_aa00_WriteRegister; |
whismanoid | 57:1c9da8e90737 | 1488 | default: |
whismanoid | 57:1c9da8e90737 | 1489 | return CMDOP_1111_1111_NoOperationMOSIidleHigh; |
whismanoid | 57:1c9da8e90737 | 1490 | } |
whismanoid | 57:1c9da8e90737 | 1491 | } |
whismanoid | 57:1c9da8e90737 | 1492 | |
whismanoid | 57:1c9da8e90737 | 1493 | //---------------------------------------- |
whismanoid | 53:3d5a3d241a5e | 1494 | // Return the address field of a MAX11043 register |
whismanoid | 53:3d5a3d241a5e | 1495 | // |
whismanoid | 53:3d5a3d241a5e | 1496 | // @return register address field as given in datasheet |
whismanoid | 53:3d5a3d241a5e | 1497 | uint8_t MAX11043::RegAddrOfCommand(MAX11043_CMD_enum_t commandByte) |
whismanoid | 53:3d5a3d241a5e | 1498 | { |
whismanoid | 53:3d5a3d241a5e | 1499 | |
whismanoid | 53:3d5a3d241a5e | 1500 | //---------------------------------------- |
whismanoid | 53:3d5a3d241a5e | 1501 | // extract register address value from command byte |
whismanoid | 57:1c9da8e90737 | 1502 | return (uint8_t)((commandByte &~ 0x83) >> 2); // CMDOP_0aaa_aa10_ReadRegister |
whismanoid | 53:3d5a3d241a5e | 1503 | } |
whismanoid | 53:3d5a3d241a5e | 1504 | |
whismanoid | 53:3d5a3d241a5e | 1505 | //---------------------------------------- |
whismanoid | 53:3d5a3d241a5e | 1506 | // Test whether a command byte is a register read command |
whismanoid | 53:3d5a3d241a5e | 1507 | // |
whismanoid | 53:3d5a3d241a5e | 1508 | // @return true if command byte is a register read command |
whismanoid | 53:3d5a3d241a5e | 1509 | uint8_t MAX11043::IsRegReadCommand(MAX11043_CMD_enum_t commandByte) |
whismanoid | 53:3d5a3d241a5e | 1510 | { |
whismanoid | 53:3d5a3d241a5e | 1511 | |
whismanoid | 53:3d5a3d241a5e | 1512 | //---------------------------------------- |
whismanoid | 53:3d5a3d241a5e | 1513 | // Test whether a command byte is a register read command |
whismanoid | 57:1c9da8e90737 | 1514 | return (commandByte &~ 0x02) ? 1 : 0; // CMDOP_0aaa_aa10_ReadRegister |
whismanoid | 53:3d5a3d241a5e | 1515 | } |
whismanoid | 53:3d5a3d241a5e | 1516 | |
whismanoid | 53:3d5a3d241a5e | 1517 | //---------------------------------------- |
whismanoid | 53:3d5a3d241a5e | 1518 | // Return the name of a MAX11043 register |
whismanoid | 53:3d5a3d241a5e | 1519 | // |
whismanoid | 53:3d5a3d241a5e | 1520 | // @return null-terminated constant C string containing register name or empty string |
whismanoid | 53:3d5a3d241a5e | 1521 | const char* MAX11043::RegName(MAX11043_CMD_enum_t commandByte) |
whismanoid | 53:3d5a3d241a5e | 1522 | { |
whismanoid | 53:3d5a3d241a5e | 1523 | |
whismanoid | 53:3d5a3d241a5e | 1524 | //---------------------------------------- |
whismanoid | 53:3d5a3d241a5e | 1525 | // switch based on register address value regAddress |
whismanoid | 57:1c9da8e90737 | 1526 | // commandByte = (MAX11043_CMD_enum_t)((commandByte &~ CMDOP_0aaa_aa10_ReadRegister) & 0xFF); |
whismanoid | 53:3d5a3d241a5e | 1527 | switch(commandByte) |
whismanoid | 53:3d5a3d241a5e | 1528 | { |
whismanoid | 53:3d5a3d241a5e | 1529 | default: |
whismanoid | 53:3d5a3d241a5e | 1530 | return ""; // undefined register |
whismanoid | 57:1c9da8e90737 | 1531 | // case CMDOP_0aaa_aa00_WriteRegister: return "_______"; |
whismanoid | 57:1c9da8e90737 | 1532 | // case CMDOP_0aaa_aa10_ReadRegister: return "_______"; |
whismanoid | 57:1c9da8e90737 | 1533 | // case CMDOP_1111_1111_NoOperationMOSIidleHigh: return "_______"; |
whismanoid | 59:47538bcf6cda | 1534 | case CMD_0000_0010_d16o8_Rd00_ADCa: return "ADCa"; |
whismanoid | 59:47538bcf6cda | 1535 | case CMD_0000_0110_d16o8_Rd01_ADCb: return "ADCb"; |
whismanoid | 59:47538bcf6cda | 1536 | case CMD_0000_1010_d16o8_Rd02_ADCc: return "ADCc"; |
whismanoid | 59:47538bcf6cda | 1537 | case CMD_0000_1110_d16o8_Rd03_ADCd: return "ADCd"; |
whismanoid | 63:8f39d21d6157 | 1538 | case CMD_0001_0010_d16o8_d16o8_Rd04_ADCab: return "ADCab"; |
whismanoid | 63:8f39d21d6157 | 1539 | case CMD_0001_0110_d16o8_d16o8_Rd05_ADCcd: return "ADCcd"; |
whismanoid | 63:8f39d21d6157 | 1540 | case CMD_0001_1010_d16o8_d16o8_d16o8_d16o8_Rd06_ADCabcd: return "ADCabcd"; |
whismanoid | 53:3d5a3d241a5e | 1541 | case CMD_0001_1110_d8_Rd07_Status: return "Status"; |
whismanoid | 53:3d5a3d241a5e | 1542 | case CMD_0010_0000_d16_Wr08_Configuration: return "Configuration"; |
whismanoid | 53:3d5a3d241a5e | 1543 | case CMD_0010_0010_d16_Rd08_Configuration: return "Configuration"; |
whismanoid | 53:3d5a3d241a5e | 1544 | case CMD_0010_0100_d16_Wr09_DAC: return "DAC"; |
whismanoid | 53:3d5a3d241a5e | 1545 | case CMD_0010_0110_d16_Rd09_DAC: return "DAC"; |
whismanoid | 53:3d5a3d241a5e | 1546 | case CMD_0010_1000_d16_Wr0A_DACStep: return "DACStep"; |
whismanoid | 53:3d5a3d241a5e | 1547 | case CMD_0010_1010_d16_Rd0A_DACStep: return "DACStep"; |
whismanoid | 53:3d5a3d241a5e | 1548 | case CMD_0010_1100_d16_Wr0B_DACHDACL: return "DACHDACL"; |
whismanoid | 53:3d5a3d241a5e | 1549 | case CMD_0010_1110_d16_Rd0B_DACHDACL: return "DACHDACL"; |
whismanoid | 53:3d5a3d241a5e | 1550 | case CMD_0011_0000_d16_Wr0C_ConfigA: return "ConfigA"; |
whismanoid | 53:3d5a3d241a5e | 1551 | case CMD_0011_0010_d16_Rd0C_ConfigA: return "ConfigA"; |
whismanoid | 53:3d5a3d241a5e | 1552 | case CMD_0011_0100_d16_Wr0D_ConfigB: return "ConfigB"; |
whismanoid | 53:3d5a3d241a5e | 1553 | case CMD_0011_0110_d16_Rd0D_ConfigB: return "ConfigB"; |
whismanoid | 53:3d5a3d241a5e | 1554 | case CMD_0011_1000_d16_Wr0E_ConfigC: return "ConfigC"; |
whismanoid | 53:3d5a3d241a5e | 1555 | case CMD_0011_1010_d16_Rd0E_ConfigC: return "ConfigC"; |
whismanoid | 53:3d5a3d241a5e | 1556 | case CMD_0011_1100_d16_Wr0F_ConfigD: return "ConfigD"; |
whismanoid | 53:3d5a3d241a5e | 1557 | case CMD_0011_1110_d16_Rd0F_ConfigD: return "ConfigD"; |
whismanoid | 53:3d5a3d241a5e | 1558 | case CMD_0100_0000_d16_Wr10_Reference: return "Reference"; |
whismanoid | 53:3d5a3d241a5e | 1559 | case CMD_0100_0010_d16_Rd10_Reference: return "Reference"; |
whismanoid | 53:3d5a3d241a5e | 1560 | case CMD_0100_0100_d16_Wr11_AGain: return "AGain"; |
whismanoid | 53:3d5a3d241a5e | 1561 | case CMD_0100_0110_d16_Rd11_AGain: return "AGain"; |
whismanoid | 53:3d5a3d241a5e | 1562 | case CMD_0100_1000_d16_Wr12_BGain: return "BGain"; |
whismanoid | 53:3d5a3d241a5e | 1563 | case CMD_0100_1010_d16_Rd12_BGain: return "BGain"; |
whismanoid | 53:3d5a3d241a5e | 1564 | case CMD_0100_1100_d16_Wr13_CGain: return "CGain"; |
whismanoid | 53:3d5a3d241a5e | 1565 | case CMD_0100_1110_d16_Rd13_CGain: return "CGain"; |
whismanoid | 53:3d5a3d241a5e | 1566 | case CMD_0101_0000_d16_Wr14_DGain: return "DGain"; |
whismanoid | 53:3d5a3d241a5e | 1567 | case CMD_0101_0010_d16_Rd14_DGain: return "DGain"; |
whismanoid | 53:3d5a3d241a5e | 1568 | case CMD_0101_0100_d8_Wr15_FilterCAddress: return "FilterCAddress"; |
whismanoid | 53:3d5a3d241a5e | 1569 | case CMD_0101_0110_d8_Rd15_FilterCAddress: return "FilterCAddress"; |
whismanoid | 53:3d5a3d241a5e | 1570 | case CMD_0101_1000_d32_Wr16_FilterCDataOut: return "FilterCDataOut"; |
whismanoid | 53:3d5a3d241a5e | 1571 | case CMD_0101_1010_d32_Rd16_FilterCDataOut: return "FilterCDataOut"; |
whismanoid | 53:3d5a3d241a5e | 1572 | case CMD_0101_1100_d32_Wr17_FilterCDataIn: return "FilterCDataIn"; |
whismanoid | 53:3d5a3d241a5e | 1573 | case CMD_0101_1110_d32_Rd17_FilterCDataIn: return "FilterCDataIn"; |
whismanoid | 53:3d5a3d241a5e | 1574 | case CMD_0110_0000_d8_Wr18_FlashMode: return "FlashMode"; |
whismanoid | 53:3d5a3d241a5e | 1575 | case CMD_0110_0010_d8_Rd18_FlashMode: return "FlashMode"; |
whismanoid | 53:3d5a3d241a5e | 1576 | case CMD_0110_0100_d16_Wr19_FlashAddr: return "FlashAddr"; |
whismanoid | 53:3d5a3d241a5e | 1577 | case CMD_0110_0110_d16_Rd19_FlashAddr: return "FlashAddr"; |
whismanoid | 53:3d5a3d241a5e | 1578 | case CMD_0110_1000_d16_Wr1A_FlashDataIn: return "FlashDataIn"; |
whismanoid | 53:3d5a3d241a5e | 1579 | case CMD_0110_1010_d16_Rd1A_FlashDataIn: return "FlashDataIn"; |
whismanoid | 53:3d5a3d241a5e | 1580 | case CMD_0110_1110_d16_Rd1B_FlashDataOut: return "FlashDataOut"; |
whismanoid | 53:3d5a3d241a5e | 1581 | } |
whismanoid | 53:3d5a3d241a5e | 1582 | } |
whismanoid | 53:3d5a3d241a5e | 1583 | |
whismanoid | 59:47538bcf6cda | 1584 | //---------------------------------------- |
whismanoid | 64:a667cfd83492 | 1585 | // Menu item '$' -> adca, adcb, adcc, adcd |
whismanoid | 64:a667cfd83492 | 1586 | // Read ADCabcd |
whismanoid | 64:a667cfd83492 | 1587 | // |
whismanoid | 64:a667cfd83492 | 1588 | // @return 1 on success; 0 on failure |
whismanoid | 64:a667cfd83492 | 1589 | uint8_t MAX11043::Read_ADCabcd(void) |
whismanoid | 64:a667cfd83492 | 1590 | { |
whismanoid | 64:a667cfd83492 | 1591 | |
whismanoid | 64:a667cfd83492 | 1592 | //---------------------------------------- |
whismanoid | 64:a667cfd83492 | 1593 | // warning -- WIP work in progress |
whismanoid | 64:a667cfd83492 | 1594 | #warning "Not Tested Yet: MAX11043::Read_ADCabcd..." |
whismanoid | 64:a667cfd83492 | 1595 | |
whismanoid | 69:989e392cf635 | 1596 | //-------------------------------------------------- |
whismanoid | 69:989e392cf635 | 1597 | // MAX11043 ADC Read operations must be synchronized to EOC End Of Conversion |
whismanoid | 89:20fd6ce5e4dd | 1598 | //---------------------------------------- |
whismanoid | 89:20fd6ce5e4dd | 1599 | // warning -- WIP work in progress |
whismanoid | 89:20fd6ce5e4dd | 1600 | #warning "need CONVRUNoutputGetValue() -- is CONVRUN being driven high?" |
whismanoid | 89:20fd6ce5e4dd | 1601 | |
whismanoid | 89:20fd6ce5e4dd | 1602 | //---------------------------------------- |
whismanoid | 89:20fd6ce5e4dd | 1603 | // Synchronize with EOC End Of Conversion |
whismanoid | 89:20fd6ce5e4dd | 1604 | // MAX11043 ADC Read operations must be synchronized to EOC End Of Conversion |
whismanoid | 69:989e392cf635 | 1605 | // EOC# asserts low when new data is available. |
whismanoid | 69:989e392cf635 | 1606 | // Initiate a data read prior to the next rising edge of EOC# or the result is overwritten. |
whismanoid | 69:989e392cf635 | 1607 | #if MAX11043_EOC_INTERRUPT_POLLING |
whismanoid | 69:989e392cf635 | 1608 | // MAX11043 EOC End Of Conversion input should be InterruptIn(PinName:EOC_pin).fall(onEOCFallingEdge); |
whismanoid | 69:989e392cf635 | 1609 | // Workaround using DigitalIn(PinName:EOC_pin) polled to sync with EOC falling edge for ADC reads |
whismanoid | 69:989e392cf635 | 1610 | // 2020-02-20 MAX11043_EOC_INTERRUPT_POLLING works on MAX32625MBED at 9us conversion rate, with 1us timing margin |
whismanoid | 69:989e392cf635 | 1611 | // TODO: poll m_EOC_pin if CONVRUN is high |
whismanoid | 89:20fd6ce5e4dd | 1612 | if (CONVRUNoutputGetValue()) // is CONVRUN being driven high? |
whismanoid | 69:989e392cf635 | 1613 | { |
whismanoid | 89:20fd6ce5e4dd | 1614 | // CONVRUN pin is being driven high, so EOC# will be changing. |
whismanoid | 89:20fd6ce5e4dd | 1615 | // Try to read as close as possible to EOC# falling edge, |
whismanoid | 89:20fd6ce5e4dd | 1616 | // because if EOC# falling edge happens during SPI data readout, |
whismanoid | 89:20fd6ce5e4dd | 1617 | // the data will be corrupted. |
whismanoid | 69:989e392cf635 | 1618 | #warning "MAX11043::Read_ADCabcd() Potential infinite loop if EOC pin not connected" |
whismanoid | 69:989e392cf635 | 1619 | // possible infinite loop; need a timeout or futility countdown to escape |
whismanoid | 69:989e392cf635 | 1620 | for (int futility_countdown = 100; |
whismanoid | 69:989e392cf635 | 1621 | ((futility_countdown > 0) && |
whismanoid | 89:20fd6ce5e4dd | 1622 | (EOCinputValue() != 1)); |
whismanoid | 69:989e392cf635 | 1623 | futility_countdown--) |
whismanoid | 69:989e392cf635 | 1624 | { |
whismanoid | 69:989e392cf635 | 1625 | // spinlock waiting for logic high pin state (start of new conversion) |
whismanoid | 69:989e392cf635 | 1626 | } |
whismanoid | 69:989e392cf635 | 1627 | for (int futility_countdown = 100; |
whismanoid | 69:989e392cf635 | 1628 | ((futility_countdown > 0) && |
whismanoid | 89:20fd6ce5e4dd | 1629 | (EOCinputValue() != 0)); |
whismanoid | 69:989e392cf635 | 1630 | futility_countdown--) |
whismanoid | 69:989e392cf635 | 1631 | { |
whismanoid | 69:989e392cf635 | 1632 | // spinlock waiting for logic low pin state (new data is available) |
whismanoid | 69:989e392cf635 | 1633 | } |
whismanoid | 69:989e392cf635 | 1634 | } |
whismanoid | 69:989e392cf635 | 1635 | else |
whismanoid | 69:989e392cf635 | 1636 | { |
whismanoid | 69:989e392cf635 | 1637 | // CONVRUN pin is being driven low, so conversion result will not change, EOC# remains high |
whismanoid | 69:989e392cf635 | 1638 | } |
whismanoid | 69:989e392cf635 | 1639 | #else // MAX11043_EOC_INTERRUPT_POLLING |
whismanoid | 69:989e392cf635 | 1640 | // MAX11043 EOC End Of Conversion input is InterruptIn(PinName:EOC_pin).fall(onEOCFallingEdge); |
whismanoid | 69:989e392cf635 | 1641 | #endif // MAX11043_EOC_INTERRUPT_POLLING |
whismanoid | 69:989e392cf635 | 1642 | //-------------------------------------------------- |
whismanoid | 69:989e392cf635 | 1643 | |
whismanoid | 64:a667cfd83492 | 1644 | //---------------------------------------- |
whismanoid | 64:a667cfd83492 | 1645 | // read register ADCabcd -> &adca, &adcb, &adcc, &adcd |
whismanoid | 90:d6ed8a8c5f26 | 1646 | RegRead(CMD_0001_1010_d16o8_d16o8_d16o8_d16o8_Rd06_ADCabcd, 0); // updates &adca, &adcb, &adcc, &adcd |
whismanoid | 64:a667cfd83492 | 1647 | |
whismanoid | 64:a667cfd83492 | 1648 | //---------------------------------------- |
whismanoid | 64:a667cfd83492 | 1649 | // success |
whismanoid | 64:a667cfd83492 | 1650 | return 1; |
whismanoid | 64:a667cfd83492 | 1651 | } |
whismanoid | 64:a667cfd83492 | 1652 | |
whismanoid | 64:a667cfd83492 | 1653 | //---------------------------------------- |
whismanoid | 66:3fe92f6f1cfa | 1654 | // Menu item 'GA' |
whismanoid | 64:a667cfd83492 | 1655 | // Write AGain register |
whismanoid | 64:a667cfd83492 | 1656 | // |
whismanoid | 93:6b22269935a6 | 1657 | // @param[in] gain 2's complement, 0x800=0.25V/V, 0x1000=0.5V/V, 0x2000=1V/V, 0x4000=2V/V, default=0x2000 |
whismanoid | 64:a667cfd83492 | 1658 | // |
whismanoid | 64:a667cfd83492 | 1659 | // @return 1 on success; 0 on failure |
whismanoid | 64:a667cfd83492 | 1660 | uint8_t MAX11043::Write_AGain(uint32_t gain) |
whismanoid | 64:a667cfd83492 | 1661 | { |
whismanoid | 64:a667cfd83492 | 1662 | |
whismanoid | 64:a667cfd83492 | 1663 | //---------------------------------------- |
whismanoid | 64:a667cfd83492 | 1664 | // warning -- WIP work in progress |
whismanoid | 64:a667cfd83492 | 1665 | #warning "Not Tested Yet: MAX11043::Write_AGain..." |
whismanoid | 64:a667cfd83492 | 1666 | |
whismanoid | 64:a667cfd83492 | 1667 | //---------------------------------------- |
whismanoid | 64:a667cfd83492 | 1668 | // write register |
whismanoid | 64:a667cfd83492 | 1669 | RegWrite(CMD_0100_0100_d16_Wr11_AGain, gain); |
whismanoid | 64:a667cfd83492 | 1670 | |
whismanoid | 64:a667cfd83492 | 1671 | //---------------------------------------- |
whismanoid | 64:a667cfd83492 | 1672 | // success |
whismanoid | 64:a667cfd83492 | 1673 | return 1; |
whismanoid | 64:a667cfd83492 | 1674 | } |
whismanoid | 64:a667cfd83492 | 1675 | |
whismanoid | 64:a667cfd83492 | 1676 | //---------------------------------------- |
whismanoid | 89:20fd6ce5e4dd | 1677 | // Menu item 'XD' |
whismanoid | 89:20fd6ce5e4dd | 1678 | // Example configuration. |
whismanoid | 89:20fd6ce5e4dd | 1679 | // Slowest conversion rate 1:6 = 9us, |
whismanoid | 89:20fd6ce5e4dd | 1680 | // Bypass PGA and filters, Gain=1V/V, |
whismanoid | 89:20fd6ce5e4dd | 1681 | // AOUT = 2.0V |
whismanoid | 89:20fd6ce5e4dd | 1682 | // |
whismanoid | 89:20fd6ce5e4dd | 1683 | void MAX11043::Configure_Demo(void) |
whismanoid | 89:20fd6ce5e4dd | 1684 | { |
whismanoid | 89:20fd6ce5e4dd | 1685 | |
whismanoid | 89:20fd6ce5e4dd | 1686 | //---------------------------------------- |
whismanoid | 89:20fd6ce5e4dd | 1687 | // warning -- WIP work in progress |
whismanoid | 89:20fd6ce5e4dd | 1688 | #warning "Not Tested Yet: MAX11043::Configure_Demo..." |
whismanoid | 89:20fd6ce5e4dd | 1689 | |
whismanoid | 89:20fd6ce5e4dd | 1690 | //---------------------------------------- |
whismanoid | 89:20fd6ce5e4dd | 1691 | // *Config=0x6000 (POR default, slowest conversion rate 1:6 = 9us) |
whismanoid | 89:20fd6ce5e4dd | 1692 | RegWrite(CMD_0010_0000_d16_Wr08_Configuration, 0x6000); |
whismanoid | 89:20fd6ce5e4dd | 1693 | |
whismanoid | 89:20fd6ce5e4dd | 1694 | //---------------------------------------- |
whismanoid | 89:20fd6ce5e4dd | 1695 | // *ConfigA=0x0018 (Bypass PGA and filters, Gain=1V/V) |
whismanoid | 89:20fd6ce5e4dd | 1696 | RegWrite(CMD_0011_0000_d16_Wr0C_ConfigA, 0x0018); |
whismanoid | 89:20fd6ce5e4dd | 1697 | |
whismanoid | 89:20fd6ce5e4dd | 1698 | //---------------------------------------- |
whismanoid | 89:20fd6ce5e4dd | 1699 | // *AGain=0x1000 (0.5) (default is 0x2000=1.0) |
whismanoid | 89:20fd6ce5e4dd | 1700 | RegWrite(CMD_0100_0100_d16_Wr11_AGain, 0x1000); |
whismanoid | 89:20fd6ce5e4dd | 1701 | |
whismanoid | 89:20fd6ce5e4dd | 1702 | //---------------------------------------- |
whismanoid | 89:20fd6ce5e4dd | 1703 | // *ConfigB=0x0018 (Bypass PGA and filters, Gain=1V/V) |
whismanoid | 89:20fd6ce5e4dd | 1704 | RegWrite(CMD_0011_0100_d16_Wr0D_ConfigB, 0x0018); |
whismanoid | 89:20fd6ce5e4dd | 1705 | |
whismanoid | 89:20fd6ce5e4dd | 1706 | //---------------------------------------- |
whismanoid | 89:20fd6ce5e4dd | 1707 | // *BGain=0x1000 (0.5) (default is 0x2000=1.0) |
whismanoid | 89:20fd6ce5e4dd | 1708 | RegWrite(CMD_0100_1000_d16_Wr12_BGain, 0x1000); |
whismanoid | 89:20fd6ce5e4dd | 1709 | |
whismanoid | 89:20fd6ce5e4dd | 1710 | //---------------------------------------- |
whismanoid | 89:20fd6ce5e4dd | 1711 | // *ConfigC=0x0018 (Bypass PGA and filters, Gain=1V/V) |
whismanoid | 89:20fd6ce5e4dd | 1712 | RegWrite(CMD_0011_1000_d16_Wr0E_ConfigC, 0x0018); |
whismanoid | 89:20fd6ce5e4dd | 1713 | |
whismanoid | 89:20fd6ce5e4dd | 1714 | //---------------------------------------- |
whismanoid | 89:20fd6ce5e4dd | 1715 | // *CGain=0x1000 (0.5) (default is 0x2000=1.0) |
whismanoid | 89:20fd6ce5e4dd | 1716 | RegWrite(CMD_0100_1100_d16_Wr13_CGain, 0x1000); |
whismanoid | 89:20fd6ce5e4dd | 1717 | |
whismanoid | 89:20fd6ce5e4dd | 1718 | //---------------------------------------- |
whismanoid | 89:20fd6ce5e4dd | 1719 | // *ConfigD=0x0018 (Bypass PGA and filters, Gain=1V/V) |
whismanoid | 89:20fd6ce5e4dd | 1720 | RegWrite(CMD_0011_1100_d16_Wr0F_ConfigD, 0x0018); |
whismanoid | 89:20fd6ce5e4dd | 1721 | |
whismanoid | 89:20fd6ce5e4dd | 1722 | //---------------------------------------- |
whismanoid | 89:20fd6ce5e4dd | 1723 | // *DGain=0x1000 (0.5) (default is 0x2000=1.0) |
whismanoid | 89:20fd6ce5e4dd | 1724 | RegWrite(CMD_0101_0000_d16_Wr14_DGain, 0x1000); |
whismanoid | 89:20fd6ce5e4dd | 1725 | |
whismanoid | 89:20fd6ce5e4dd | 1726 | //---------------------------------------- |
whismanoid | 89:20fd6ce5e4dd | 1727 | // *DacHDacL=0xFF00 (DAC code 0xFFF fullscale 2.5V, DAC code 0x000 lowest 0V) |
whismanoid | 89:20fd6ce5e4dd | 1728 | RegWrite(CMD_0010_1100_d16_Wr0B_DACHDACL, 0xFF00); |
whismanoid | 89:20fd6ce5e4dd | 1729 | |
whismanoid | 89:20fd6ce5e4dd | 1730 | //---------------------------------------- |
whismanoid | 89:20fd6ce5e4dd | 1731 | // *DacStep=0x0001 (DAC increment value triggered by DACSTEP pin) |
whismanoid | 89:20fd6ce5e4dd | 1732 | RegWrite(CMD_0010_1000_d16_Wr0A_DACStep, 0x0001); |
whismanoid | 89:20fd6ce5e4dd | 1733 | |
whismanoid | 89:20fd6ce5e4dd | 1734 | //---------------------------------------- |
whismanoid | 89:20fd6ce5e4dd | 1735 | // *Dac=0x0ccc (AOUT=2V) |
whismanoid | 89:20fd6ce5e4dd | 1736 | RegWrite(CMD_0010_0100_d16_Wr09_DAC, 0x0ccc); |
whismanoid | 89:20fd6ce5e4dd | 1737 | } |
whismanoid | 89:20fd6ce5e4dd | 1738 | |
whismanoid | 89:20fd6ce5e4dd | 1739 | //---------------------------------------- |
whismanoid | 59:47538bcf6cda | 1740 | // Menu item 'XX' |
whismanoid | 59:47538bcf6cda | 1741 | // |
whismanoid | 59:47538bcf6cda | 1742 | // @return 1 on success; 0 on failure |
whismanoid | 59:47538bcf6cda | 1743 | uint8_t MAX11043::Configure_XXXXX(uint8_t linef, uint8_t rate) |
whismanoid | 59:47538bcf6cda | 1744 | { |
whismanoid | 59:47538bcf6cda | 1745 | |
whismanoid | 59:47538bcf6cda | 1746 | //---------------------------------------- |
whismanoid | 59:47538bcf6cda | 1747 | // warning -- WIP work in progress |
whismanoid | 59:47538bcf6cda | 1748 | #warning "Not Tested Yet: MAX11043::Configure_XXXXX..." |
whismanoid | 59:47538bcf6cda | 1749 | |
whismanoid | 59:47538bcf6cda | 1750 | //---------------------------------------- |
whismanoid | 59:47538bcf6cda | 1751 | // read register |
whismanoid | 90:d6ed8a8c5f26 | 1752 | RegRead(CMD_0000_0010_d16o8_Rd00_ADCa, 0); // updates &adca |
whismanoid | 59:47538bcf6cda | 1753 | |
whismanoid | 59:47538bcf6cda | 1754 | //---------------------------------------- |
whismanoid | 59:47538bcf6cda | 1755 | // success |
whismanoid | 59:47538bcf6cda | 1756 | return 1; |
whismanoid | 59:47538bcf6cda | 1757 | } |
whismanoid | 59:47538bcf6cda | 1758 | |
whismanoid | 59:47538bcf6cda | 1759 | //---------------------------------------- |
whismanoid | 59:47538bcf6cda | 1760 | // Menu item 'XY' |
whismanoid | 59:47538bcf6cda | 1761 | // |
whismanoid | 59:47538bcf6cda | 1762 | // @return 1 on success; 0 on failure |
whismanoid | 59:47538bcf6cda | 1763 | uint8_t MAX11043::Configure_XXXXY(uint8_t linef, uint8_t rate) |
whismanoid | 59:47538bcf6cda | 1764 | { |
whismanoid | 59:47538bcf6cda | 1765 | |
whismanoid | 59:47538bcf6cda | 1766 | //---------------------------------------- |
whismanoid | 59:47538bcf6cda | 1767 | // warning -- WIP work in progress |
whismanoid | 59:47538bcf6cda | 1768 | #warning "Not Tested Yet: MAX11043::Configure_XXXXY..." |
whismanoid | 59:47538bcf6cda | 1769 | |
whismanoid | 59:47538bcf6cda | 1770 | //---------------------------------------- |
whismanoid | 59:47538bcf6cda | 1771 | // read register |
whismanoid | 90:d6ed8a8c5f26 | 1772 | RegRead(CMD_0001_1110_d8_Rd07_Status, 0); // udpates &status |
whismanoid | 59:47538bcf6cda | 1773 | |
whismanoid | 59:47538bcf6cda | 1774 | //---------------------------------------- |
whismanoid | 59:47538bcf6cda | 1775 | // success |
whismanoid | 59:47538bcf6cda | 1776 | return 1; |
whismanoid | 59:47538bcf6cda | 1777 | } |
whismanoid | 59:47538bcf6cda | 1778 | |
whismanoid | 53:3d5a3d241a5e | 1779 | |
whismanoid | 53:3d5a3d241a5e | 1780 | // End of file |