![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
added wait_us(31) in admw_spi.cpp to support hibernation mode
main.cpp@18:cbf514cce921, 2019-08-20 (annotated)
- Committer:
- Vkadaba
- Date:
- Tue Aug 20 12:19:31 2019 +0000
- Revision:
- 18:cbf514cce921
- Parent:
- 17:2f0028880874
- Child:
- 19:09d58952b65d
Added No excitation current config in host firmware
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ADIJake | 0:85855ecd3257 | 1 | /* |
Vkadaba | 15:b5d57daeb7c0 | 2 | Copyright 2019 (c) Analog Devices, Inc. |
ADIJake | 0:85855ecd3257 | 3 | |
ADIJake | 0:85855ecd3257 | 4 | All rights reserved. |
ADIJake | 0:85855ecd3257 | 5 | |
ADIJake | 0:85855ecd3257 | 6 | Redistribution and use in source and binary forms, with or without |
ADIJake | 0:85855ecd3257 | 7 | modification, are permitted provided that the following conditions are met: |
ADIJake | 0:85855ecd3257 | 8 | - Redistributions of source code must retain the above copyright |
ADIJake | 0:85855ecd3257 | 9 | notice, this list of conditions and the following disclaimer. |
ADIJake | 0:85855ecd3257 | 10 | - Redistributions in binary form must reproduce the above copyright |
ADIJake | 0:85855ecd3257 | 11 | notice, this list of conditions and the following disclaimer in |
ADIJake | 0:85855ecd3257 | 12 | the documentation and/or other materials provided with the |
ADIJake | 0:85855ecd3257 | 13 | distribution. |
ADIJake | 0:85855ecd3257 | 14 | - Neither the name of Analog Devices, Inc. nor the names of its |
ADIJake | 0:85855ecd3257 | 15 | contributors may be used to endorse or promote products derived |
ADIJake | 0:85855ecd3257 | 16 | from this software without specific prior written permission. |
ADIJake | 0:85855ecd3257 | 17 | - The use of this software may or may not infringe the patent rights |
ADIJake | 0:85855ecd3257 | 18 | of one or more patent holders. This license does not release you |
ADIJake | 0:85855ecd3257 | 19 | from the requirement that you obtain separate licenses from these |
ADIJake | 0:85855ecd3257 | 20 | patent holders to use this software. |
ADIJake | 0:85855ecd3257 | 21 | - Use of the software either in source or binary form, must be run |
ADIJake | 0:85855ecd3257 | 22 | on or directly connected to an Analog Devices Inc. component. |
ADIJake | 0:85855ecd3257 | 23 | |
ADIJake | 0:85855ecd3257 | 24 | THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR |
ADIJake | 0:85855ecd3257 | 25 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT, |
ADIJake | 0:85855ecd3257 | 26 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
ADIJake | 0:85855ecd3257 | 27 | IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT, |
ADIJake | 0:85855ecd3257 | 28 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
ADIJake | 0:85855ecd3257 | 29 | LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR |
ADIJake | 0:85855ecd3257 | 30 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
ADIJake | 0:85855ecd3257 | 31 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
ADIJake | 0:85855ecd3257 | 32 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
ADIJake | 0:85855ecd3257 | 33 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
ADIJake | 0:85855ecd3257 | 34 | * |
ADIJake | 0:85855ecd3257 | 35 | Copyright 2017 (c) Analog Devices, Inc. |
ADIJake | 0:85855ecd3257 | 36 | |
ADIJake | 0:85855ecd3257 | 37 | All rights reserved. |
ADIJake | 0:85855ecd3257 | 38 | |
ADIJake | 0:85855ecd3257 | 39 | Redistribution and use in source and binary forms, with or without |
ADIJake | 0:85855ecd3257 | 40 | modification, are permitted provided that the following conditions are met: |
ADIJake | 0:85855ecd3257 | 41 | - Redistributions of source code must retain the above copyright |
ADIJake | 0:85855ecd3257 | 42 | notice, this list of conditions and the following disclaimer. |
ADIJake | 0:85855ecd3257 | 43 | - Redistributions in binary form must reproduce the above copyright |
ADIJake | 0:85855ecd3257 | 44 | notice, this list of conditions and the following disclaimer in |
ADIJake | 0:85855ecd3257 | 45 | the documentation and/or other materials provided with the |
ADIJake | 0:85855ecd3257 | 46 | distribution. |
ADIJake | 0:85855ecd3257 | 47 | - Neither the name of Analog Devices, Inc. nor the names of its |
ADIJake | 0:85855ecd3257 | 48 | contributors may be used to endorse or promote products derived |
ADIJake | 0:85855ecd3257 | 49 | from this software without specific prior written permission. |
ADIJake | 0:85855ecd3257 | 50 | - The use of this software may or may not infringe the patent rights |
ADIJake | 0:85855ecd3257 | 51 | of one or more patent holders. This license does not release you |
ADIJake | 0:85855ecd3257 | 52 | from the requirement that you obtain separate licenses from these |
ADIJake | 0:85855ecd3257 | 53 | patent holders to use this software. |
ADIJake | 0:85855ecd3257 | 54 | - Use of the software either in source or binary form, must be run |
ADIJake | 0:85855ecd3257 | 55 | on or directly connected to an Analog Devices Inc. component. |
ADIJake | 0:85855ecd3257 | 56 | |
ADIJake | 0:85855ecd3257 | 57 | THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR |
ADIJake | 0:85855ecd3257 | 58 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT, |
ADIJake | 0:85855ecd3257 | 59 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
ADIJake | 0:85855ecd3257 | 60 | IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT, |
ADIJake | 0:85855ecd3257 | 61 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
ADIJake | 0:85855ecd3257 | 62 | LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR |
ADIJake | 0:85855ecd3257 | 63 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
ADIJake | 0:85855ecd3257 | 64 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
ADIJake | 0:85855ecd3257 | 65 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
ADIJake | 0:85855ecd3257 | 66 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
ADIJake | 0:85855ecd3257 | 67 | * |
ADIJake | 0:85855ecd3257 | 68 | *****************************************************************************/ |
ADIJake | 0:85855ecd3257 | 69 | /*! |
ADIJake | 0:85855ecd3257 | 70 | ****************************************************************************** |
ADIJake | 0:85855ecd3257 | 71 | * @file: |
ADIJake | 0:85855ecd3257 | 72 | *----------------------------------------------------------------------------- |
ADIJake | 0:85855ecd3257 | 73 | * |
ADIJake | 0:85855ecd3257 | 74 | */ |
ADIJake | 0:85855ecd3257 | 75 | #include "mbed.h" |
Vkadaba | 5:0728bde67bdb | 76 | #include "admw_api.h" |
Vkadaba | 5:0728bde67bdb | 77 | #include "admw1001/admw1001_api.h" |
Vkadaba | 5:0728bde67bdb | 78 | #include "admw_log.h" |
ADIJake | 0:85855ecd3257 | 79 | #include "common/utils.h" |
ADIJake | 0:85855ecd3257 | 80 | #include "common/platform.h" |
Vkadaba | 14:266ab283b086 | 81 | #include "admw1001/ADMW1001_REGISTERS.h" |
Vkadaba | 5:0728bde67bdb | 82 | |
Vkadaba | 5:0728bde67bdb | 83 | |
Vkadaba | 5:0728bde67bdb | 84 | |
Vkadaba | 5:0728bde67bdb | 85 | extern ADMW_CONFIG sensor0_typeK_cjc0_config; |
Vkadaba | 5:0728bde67bdb | 86 | extern ADMW_CONFIG sensor1_rtd_3w_pt100_config; |
Vkadaba | 5:0728bde67bdb | 87 | extern ADMW_CONFIG sensor2_typeT_cjc0_config; |
Vkadaba | 5:0728bde67bdb | 88 | extern ADMW_CONFIG sensor3_typeJ_cjc0_config; |
Vkadaba | 5:0728bde67bdb | 89 | extern ADMW_CONFIG i2c0_sensirionSHT3X_config; |
Vkadaba | 5:0728bde67bdb | 90 | extern ADMW_CONFIG spi0_adiAdxl362_config; |
Vkadaba | 5:0728bde67bdb | 91 | extern ADMW_CONFIG multichannel_continuous_config; |
Vkadaba | 5:0728bde67bdb | 92 | extern ADMW_CONFIG multichannel_multicycle_config; |
Vkadaba | 5:0728bde67bdb | 93 | extern ADMW_CONFIG multichannel_singlecycle_config; |
Vkadaba | 16:327cea5a86e9 | 94 | extern ADMW_CONFIG sensor2_bridge_4w_load_cell_config; |
Vkadaba | 17:2f0028880874 | 95 | extern ADMW_CONFIG config; |
ADIJake | 0:85855ecd3257 | 96 | /* Change the following pointer to select any of the configurations above */ |
Vkadaba | 18:cbf514cce921 | 97 | static ADMW_CONFIG *pSelectedConfig = &sensor2_bridge_4w_load_cell_config; |
ADIJake | 0:85855ecd3257 | 98 | |
Vkadaba | 5:0728bde67bdb | 99 | static ADMW_CONNECTION connectionInfo = PLATFORM_CONNECTION_INFO; |
ADIJake | 0:85855ecd3257 | 100 | |
Vkadaba | 14:266ab283b086 | 101 | |
ADIJake | 0:85855ecd3257 | 102 | int main() |
ADIJake | 0:85855ecd3257 | 103 | { |
Vkadaba | 5:0728bde67bdb | 104 | ADMW_RESULT res; |
Vkadaba | 5:0728bde67bdb | 105 | ADMW_STATUS status; |
Vkadaba | 5:0728bde67bdb | 106 | ADMW_DEVICE_HANDLE hDevice; |
Vkadaba | 5:0728bde67bdb | 107 | ADMW_MEASUREMENT_MODE eMeasurementMode = ADMW_MEASUREMENT_MODE_NORMAL; |
ADIJake | 0:85855ecd3257 | 108 | bool bDeviceReady; |
Vkadaba | 17:2f0028880874 | 109 | |
ADIJake | 0:85855ecd3257 | 110 | /* |
ADIJake | 0:85855ecd3257 | 111 | * Open an ADI Sense device instance. |
ADIJake | 0:85855ecd3257 | 112 | */ |
Vkadaba | 5:0728bde67bdb | 113 | res = admw_Open(0, &connectionInfo, &hDevice); |
Vkadaba | 5:0728bde67bdb | 114 | if (res != ADMW_SUCCESS) |
ADIJake | 0:85855ecd3257 | 115 | { |
Vkadaba | 5:0728bde67bdb | 116 | ADMW_LOG_ERROR("Failed to open device instance"); |
ADIJake | 0:85855ecd3257 | 117 | return res; |
ADIJake | 0:85855ecd3257 | 118 | } |
Vkadaba | 14:266ab283b086 | 119 | |
ADIJake | 0:85855ecd3257 | 120 | /* |
ADIJake | 0:85855ecd3257 | 121 | * Reset the given ADI Sense device.... |
ADIJake | 0:85855ecd3257 | 122 | */ |
Vkadaba | 5:0728bde67bdb | 123 | ADMW_LOG_INFO("Resetting ADI Sense device, please wait..."); |
Vkadaba | 5:0728bde67bdb | 124 | res = admw_Reset(hDevice); |
Vkadaba | 5:0728bde67bdb | 125 | if (res != ADMW_SUCCESS) |
ADIJake | 0:85855ecd3257 | 126 | { |
Vkadaba | 5:0728bde67bdb | 127 | ADMW_LOG_ERROR("Failed to reset device"); |
ADIJake | 0:85855ecd3257 | 128 | return res; |
ADIJake | 0:85855ecd3257 | 129 | } |
ADIJake | 0:85855ecd3257 | 130 | /* |
ADIJake | 0:85855ecd3257 | 131 | * ...and wait until the device is ready. |
ADIJake | 0:85855ecd3257 | 132 | */ |
ADIJake | 0:85855ecd3257 | 133 | do { |
ADIJake | 0:85855ecd3257 | 134 | wait_ms(100); |
Vkadaba | 5:0728bde67bdb | 135 | res = admw_GetDeviceReadyState(hDevice, &bDeviceReady); |
Vkadaba | 5:0728bde67bdb | 136 | if (res != ADMW_SUCCESS) |
ADIJake | 0:85855ecd3257 | 137 | { |
Vkadaba | 5:0728bde67bdb | 138 | ADMW_LOG_ERROR("Failed to get device ready-state"); |
ADIJake | 0:85855ecd3257 | 139 | return res; |
ADIJake | 0:85855ecd3257 | 140 | } |
ADIJake | 0:85855ecd3257 | 141 | } while (! bDeviceReady); |
Vkadaba | 5:0728bde67bdb | 142 | ADMW_LOG_INFO("ADI Sense device ready"); |
ADIJake | 0:85855ecd3257 | 143 | /* |
ADIJake | 0:85855ecd3257 | 144 | * Write configuration settings to the device registers. |
Vkadaba | 5:0728bde67bdb | 145 | * Settings are not applied until admw_ApplyConfigUpdates() is called. |
ADIJake | 0:85855ecd3257 | 146 | */ |
Vkadaba | 5:0728bde67bdb | 147 | ADMW_LOG_INFO("Setting device configuration"); |
Vkadaba | 5:0728bde67bdb | 148 | res = admw_SetConfig(hDevice, pSelectedConfig); |
Vkadaba | 5:0728bde67bdb | 149 | if (res != ADMW_SUCCESS) |
ADIJake | 0:85855ecd3257 | 150 | { |
Vkadaba | 5:0728bde67bdb | 151 | ADMW_LOG_ERROR("Failed to set device configuration"); |
ADIJake | 0:85855ecd3257 | 152 | return res; |
ADIJake | 0:85855ecd3257 | 153 | } |
Vkadaba | 5:0728bde67bdb | 154 | res = admw_ApplyConfigUpdates(hDevice); |
Vkadaba | 5:0728bde67bdb | 155 | if (res != ADMW_SUCCESS) |
ADIJake | 0:85855ecd3257 | 156 | { |
Vkadaba | 5:0728bde67bdb | 157 | ADMW_LOG_ERROR("Failed to apply device configuration"); |
ADIJake | 0:85855ecd3257 | 158 | return res; |
ADIJake | 0:85855ecd3257 | 159 | } |
ADIJake | 0:85855ecd3257 | 160 | /* |
ADIJake | 0:85855ecd3257 | 161 | * Check device status after updating the configuration |
ADIJake | 0:85855ecd3257 | 162 | */ |
Vkadaba | 5:0728bde67bdb | 163 | res = admw_GetStatus(hDevice, &status); |
Vkadaba | 14:266ab283b086 | 164 | deviceInformation(hDevice); |
Vkadaba | 5:0728bde67bdb | 165 | if (res != ADMW_SUCCESS) |
ADIJake | 0:85855ecd3257 | 166 | { |
Vkadaba | 5:0728bde67bdb | 167 | ADMW_LOG_ERROR("Failed to retrieve device status"); |
ADIJake | 0:85855ecd3257 | 168 | return res; |
ADIJake | 0:85855ecd3257 | 169 | } |
ADIJake | 0:85855ecd3257 | 170 | if (status.deviceStatus & |
Vkadaba | 5:0728bde67bdb | 171 | (ADMW_DEVICE_STATUS_ERROR | ADMW_DEVICE_STATUS_ALERT)) |
ADIJake | 0:85855ecd3257 | 172 | { |
ADIJake | 0:85855ecd3257 | 173 | utils_printStatus(&status); |
ADIJake | 0:85855ecd3257 | 174 | } |
ADIJake | 0:85855ecd3257 | 175 | |
ADIJake | 0:85855ecd3257 | 176 | /* |
ADIJake | 0:85855ecd3257 | 177 | * Kick off the measurement cycle here |
ADIJake | 0:85855ecd3257 | 178 | */ |
Vkadaba | 5:0728bde67bdb | 179 | ADMW_LOG_INFO("Configuration completed, starting measurement cycles"); |
ADIJake | 0:85855ecd3257 | 180 | utils_runMeasurement(hDevice, eMeasurementMode); |
ADIJake | 0:85855ecd3257 | 181 | |
ADIJake | 0:85855ecd3257 | 182 | /* |
ADIJake | 0:85855ecd3257 | 183 | * Clean up and exit |
ADIJake | 0:85855ecd3257 | 184 | */ |
Vkadaba | 5:0728bde67bdb | 185 | res = admw_Close(hDevice); |
Vkadaba | 5:0728bde67bdb | 186 | if (res != ADMW_SUCCESS) |
ADIJake | 0:85855ecd3257 | 187 | { |
Vkadaba | 5:0728bde67bdb | 188 | ADMW_LOG_ERROR("Failed to close device instance"); |
ADIJake | 0:85855ecd3257 | 189 | return res; |
ADIJake | 0:85855ecd3257 | 190 | } |
ADIJake | 0:85855ecd3257 | 191 | |
ADIJake | 0:85855ecd3257 | 192 | return 0; |
ADIJake | 0:85855ecd3257 | 193 | } |
ADIJake | 0:85855ecd3257 | 194 |