(Working) Code to interface 3 LoadCells to ADISense1000 and display values using the Labview code.
Fork of 4Bridge_ADISense1000_Example_copy by
main.cpp
00001 /* 00002 ****************************************************************************** 00003 * file: main.cpp 00004 *----------------------------------------------------------------------------- 00005 * 00006 Copyright 2017 (c) Analog Devices, Inc. 00007 00008 All rights reserved. 00009 00010 Redistribution and use in source and binary forms, with or without 00011 modification, are permitted provided that the following conditions are met: 00012 - Redistributions of source code must retain the above copyright 00013 notice, this list of conditions and the following disclaimer. 00014 - Redistributions in binary form must reproduce the above copyright 00015 notice, this list of conditions and the following disclaimer in 00016 the documentation and/or other materials provided with the 00017 distribution. 00018 - Neither the name of Analog Devices, Inc. nor the names of its 00019 contributors may be used to endorse or promote products derived 00020 from this software without specific prior written permission. 00021 - The use of this software may or may not infringe the patent rights 00022 of one or more patent holders. This license does not release you 00023 from the requirement that you obtain separate licenses from these 00024 patent holders to use this software. 00025 - Use of the software either in source or binary form, must be run 00026 on or directly connected to an Analog Devices Inc. component. 00027 00028 THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR 00029 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT, 00030 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 00031 IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT, 00032 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 00033 LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR 00034 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00035 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00036 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00037 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00038 * 00039 *****************************************************************************/ 00040 #include "mbed.h" 00041 #include "inc/adi_sense_api.h" 00042 #include "inc/adi_sense_1000/adi_sense_1000_api.h" 00043 #include "inc/adi_sense_log.h" 00044 #include "common/utils.h" 00045 00046 extern ADI_SENSE_CONFIG sensor2_bridge_6w_pressure_config; 00047 00048 extern ADI_SENSE_1000_LUT_DESCRIPTOR *sample_lut_desc_list[]; 00049 extern ADI_SENSE_1000_LUT_TABLE_DATA *sample_lut_data_list[]; 00050 extern unsigned sample_lut_num_tables; 00051 00052 /* Change the following pointer to select any of the configurations above */ 00053 static ADI_SENSE_CONFIG *pSelectedConfig = &sensor2_bridge_6w_pressure_config; 00054 00055 static ADI_SENSE_CONNECTION connectionInfo = { 00056 .type = ADI_SENSE_CONNECTION_TYPE_SPI , 00057 .spi = { 00058 .mosiPin = SPI_MOSI, 00059 .misoPin = SPI_MISO, 00060 .sckPin = SPI_SCK, 00061 .csPin = D10, 00062 .maxSpeedHz = 2000000, 00063 }, 00064 .gpio = { 00065 .resetPin = D6, 00066 .errorPin = D3, 00067 .alertPin = D4, 00068 .datareadyPin = D5, 00069 }, 00070 }; 00071 00072 int main() 00073 { 00074 ADI_SENSE_RESULT res; 00075 ADI_SENSE_DEVICE_HANDLE hDevice; 00076 ADI_SENSE_MEASUREMENT_MODE eMeasurementMode = ADI_SENSE_MEASUREMENT_MODE_NORMAL ; 00077 bool_t bDeviceReady; 00078 00079 /* 00080 * Open an ADI Sense device instance. 00081 */ 00082 res = adi_sense_Open(0, &connectionInfo, &hDevice); 00083 if (res != ADI_SENSE_SUCCESS ) 00084 { 00085 ADI_SENSE_LOG_ERROR("Failed to open device instance"); 00086 return res; 00087 } 00088 00089 /* 00090 * Reset the given ADI Sense device.... 00091 */ 00092 ADI_SENSE_LOG_INFO("Resetting ADI Sense device, please wait..."); 00093 res = adi_sense_Reset(hDevice); 00094 if (res != ADI_SENSE_SUCCESS ) 00095 { 00096 ADI_SENSE_LOG_ERROR("Failed to reset device"); 00097 return res; 00098 } 00099 /* 00100 * ...and wait until the device is ready. 00101 */ 00102 do { 00103 wait_ms(100); 00104 res = adi_sense_GetDeviceReadyState(hDevice, &bDeviceReady); 00105 if (res != ADI_SENSE_SUCCESS ) 00106 { 00107 ADI_SENSE_LOG_ERROR("Failed to get device ready-state"); 00108 return res; 00109 } 00110 } while (! bDeviceReady); 00111 ADI_SENSE_LOG_INFO("ADI Sense device ready"); 00112 00113 /* 00114 * Write configuration settings to the device registers. 00115 * Settings are not applied until adi_sense_ApplyConfigUpdates() is called. 00116 */ 00117 ADI_SENSE_LOG_INFO("Setting device configuration"); 00118 res = adi_sense_SetConfig(hDevice, pSelectedConfig); 00119 if (res != ADI_SENSE_SUCCESS ) 00120 { 00121 ADI_SENSE_LOG_ERROR("Failed to set device configuration"); 00122 return res; 00123 } 00124 00125 00126 /* 00127 * Assemble the list of user-defined Look-Up Tables from sample_lut_data.c 00128 * into the single contiguous data format required by the device. 00129 */ 00130 unsigned lutBufferSize = ADI_SENSE_LUT_MAX_SIZE; 00131 ADI_SENSE_1000_LUT *pLutBuffer = (ADI_SENSE_1000_LUT *) ::operator new (lutBufferSize); 00132 if (pLutBuffer == NULL) 00133 { 00134 ADI_SENSE_LOG_ERROR("Failed to allocate memory for user-defined LUT data buffer"); 00135 return ADI_SENSE_NO_MEM ; 00136 } 00137 00138 ADI_SENSE_LOG_INFO("Assembling LUT data"); 00139 res = adi_sense_1000_AssembleLutData(pLutBuffer, lutBufferSize, 00140 sample_lut_num_tables, 00141 sample_lut_desc_list, 00142 sample_lut_data_list); 00143 if (res != ADI_SENSE_SUCCESS ) 00144 { 00145 ADI_SENSE_LOG_ERROR("Failed to assemble user-defined LUT data"); 00146 return res; 00147 } 00148 00149 /* 00150 * Write assembled user-defined Look-Up Table data structure to the device 00151 * User-defined LUT data is not applied until adi_sense_ApplyConfigUpdates() is called. 00152 */ 00153 ADI_SENSE_LOG_INFO("Setting LUT data"); 00154 res = adi_sense_1000_SetLutData(hDevice, pLutBuffer); 00155 if (res != ADI_SENSE_SUCCESS ) 00156 { 00157 ADI_SENSE_LOG_ERROR("Failed to set user-defined LUT data"); 00158 return res; 00159 } 00160 00161 delete pLutBuffer; 00162 00163 res = adi_sense_ApplyConfigUpdates(hDevice); 00164 if (res != ADI_SENSE_SUCCESS ) 00165 { 00166 ADI_SENSE_LOG_ERROR("Failed to apply device configuration"); 00167 return res; 00168 } 00169 /* 00170 * Kick off the measurement cycle here 00171 */ 00172 ADI_SENSE_LOG_INFO("Configuration completed, starting measurement cycles"); 00173 utils_runMeasurement(hDevice, eMeasurementMode); 00174 00175 /* 00176 * Clean up and exit 00177 */ 00178 res = adi_sense_Close(hDevice); 00179 if (res != ADI_SENSE_SUCCESS ) 00180 { 00181 ADI_SENSE_LOG_ERROR("Failed to close device instance"); 00182 return res; 00183 } 00184 00185 return 0; 00186 } 00187
Generated on Tue Jul 12 2022 21:13:17 by 1.7.2