Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp
00001 /* 00002 Copyright 2019 (c) Analog Devices, Inc. 00003 00004 All rights reserved. 00005 00006 Redistribution and use in source and binary forms, with or without 00007 modification, are permitted provided that the following conditions are met: 00008 - Redistributions of source code must retain the above copyright 00009 notice, this list of conditions and the following disclaimer. 00010 - Redistributions in binary form must reproduce the above copyright 00011 notice, this list of conditions and the following disclaimer in 00012 the documentation and/or other materials provided with the 00013 distribution. 00014 - Neither the name of Analog Devices, Inc. nor the names of its 00015 contributors may be used to endorse or promote products derived 00016 from this software without specific prior written permission. 00017 - The use of this software may or may not infringe the patent rights 00018 of one or more patent holders. This license does not release you 00019 from the requirement that you obtain separate licenses from these 00020 patent holders to use this software. 00021 - Use of the software either in source or binary form, must be run 00022 on or directly connected to an Analog Devices Inc. component. 00023 00024 THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR 00025 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT, 00026 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 00027 IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT, 00028 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 00029 LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR 00030 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00031 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00032 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00033 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00034 00035 *****************************************************************************/ 00036 /*! 00037 ****************************************************************************** 00038 * @file: 00039 *----------------------------------------------------------------------------- 00040 * 00041 */ 00042 #include "mbed.h" 00043 #include "admw_api.h" 00044 #include "admw1001/admw1001_api.h" 00045 #include "admw_log.h" 00046 #include "common/utils.h" 00047 #include "common/platform.h" 00048 #include "admw1001/ADMW1001_REGISTERS.h" 00049 00050 extern ADMW_CONFIG thermocouple_typeK_cjc0_config; 00051 extern ADMW_CONFIG thermocouple_typeT_cjc0_config; 00052 extern ADMW_CONFIG thermocouple_typeJ_cjc0_config; 00053 extern ADMW_CONFIG rtd_3w_pt100_config; 00054 extern ADMW_CONFIG rtd_4w_config; 00055 extern ADMW_CONFIG bridge_4w_load_cell_config; 00056 extern ADMW_CONFIG multichannel_continuous_config; 00057 extern ADMW_CONFIG multichannel_singlecycle_config; 00058 extern ADMW_CONFIG i2c0_sensirionSHT3X_config; 00059 /* Use the following config if adding a configuration file from measureware designer*/ 00060 extern ADMW_CONFIG measureware_config; 00061 00062 /* Change the following pointer to load or change the configurations */ 00063 static ADMW_CONFIG *pSelectedConfig = &thermocouple_typeK_cjc0_config; 00064 00065 static ADMW_CONNECTION connectionInfo = PLATFORM_CONNECTION_INFO; 00066 00067 00068 int main() 00069 { 00070 00071 ADMW_RESULT res; 00072 ADMW_STATUS status; 00073 ADMW_DEVICE_HANDLE hDevice; 00074 ADMW_MEASUREMENT_MODE eMeasurementMode = ADMW_MEASUREMENT_MODE_NORMAL ; 00075 bool bDeviceReady; 00076 00077 /* 00078 * Open an ADMW1001 device instance. 00079 */ 00080 res = admw_Open(0, &connectionInfo, &hDevice); 00081 if (res != ADMW_SUCCESS ) { 00082 ADMW_LOG_ERROR("Failed to open device instance"); 00083 return res; 00084 } 00085 00086 /* 00087 * Reset the given ADMW1001 device.... 00088 */ 00089 ADMW_LOG_INFO("Resetting ADMW1001 device, please wait..."); 00090 res = admw_Reset(hDevice); 00091 if (res != ADMW_SUCCESS ) { 00092 ADMW_LOG_ERROR("Failed to reset device"); 00093 return res; 00094 } 00095 /* 00096 * ...and wait until the device is ready. 00097 */ 00098 do { 00099 wait_ms(100); 00100 res = admw_GetDeviceReadyState(hDevice, &bDeviceReady); 00101 if (res != ADMW_SUCCESS ) { 00102 ADMW_LOG_ERROR("Failed to get device ready-state"); 00103 return res; 00104 } 00105 } while (! bDeviceReady); 00106 ADMW_LOG_INFO("ADMW1001 device ready"); 00107 /* 00108 * Write configuration settings to the device registers. 00109 * Settings are not applied until admw_ApplyConfigUpdates() is called. 00110 */ 00111 ADMW_LOG_INFO("Setting device configuration"); 00112 res = admw_SetConfig(hDevice, pSelectedConfig); 00113 if (res != ADMW_SUCCESS ) { 00114 ADMW_LOG_ERROR("Failed to set device configuration"); 00115 return res; 00116 } 00117 res = admw_ApplyConfigUpdates(hDevice); 00118 if (res != ADMW_SUCCESS ) { 00119 ADMW_LOG_ERROR("Failed to apply device configuration"); 00120 return res; 00121 } 00122 /* 00123 * Check device status after updating the configuration 00124 */ 00125 res = admw_GetStatus(hDevice, &status); 00126 admw_deviceInformation(hDevice); 00127 if (res != ADMW_SUCCESS ) { 00128 ADMW_LOG_ERROR("Failed to retrieve device status"); 00129 return res; 00130 } 00131 if (status.deviceStatus & 00132 (ADMW_DEVICE_STATUS_ERROR | ADMW_DEVICE_STATUS_ALERT )) { 00133 utils_printStatus(&status); 00134 } 00135 00136 /* 00137 * Kick off the measurement cycle here 00138 */ 00139 ADMW_LOG_INFO("Configuration completed, starting measurement cycles"); 00140 utils_runMeasurement(hDevice, eMeasurementMode); 00141 00142 /* 00143 * Clean up and exit 00144 */ 00145 res = admw_Close(hDevice); 00146 if (res != ADMW_SUCCESS ) { 00147 ADMW_LOG_ERROR("Failed to close device instance"); 00148 return res; 00149 } 00150 00151 return 0; 00152 } 00153
Generated on Tue Jul 12 2022 23:10:09 by
