This is a simple program to read temp reading using 2 wire RTD sensor with the measureware kit.
Fork of ADISense1000_Example_FW by
main.cpp@1:ae66eccef75f, 2018-07-18 (annotated)
- Committer:
- RGurav
- Date:
- Wed Jul 18 11:40:48 2018 +0000
- Revision:
- 1:ae66eccef75f
- Parent:
- 0:76fed7dd9235
connect 2 wire RTD to CJC_0 and read data using Tera
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
seanwilson10 | 0:76fed7dd9235 | 1 | /* |
seanwilson10 | 0:76fed7dd9235 | 2 | ****************************************************************************** |
seanwilson10 | 0:76fed7dd9235 | 3 | * file: main.cpp |
seanwilson10 | 0:76fed7dd9235 | 4 | *----------------------------------------------------------------------------- |
seanwilson10 | 0:76fed7dd9235 | 5 | * |
seanwilson10 | 0:76fed7dd9235 | 6 | Copyright 2017 (c) Analog Devices, Inc. |
seanwilson10 | 0:76fed7dd9235 | 7 | |
seanwilson10 | 0:76fed7dd9235 | 8 | All rights reserved. |
seanwilson10 | 0:76fed7dd9235 | 9 | |
seanwilson10 | 0:76fed7dd9235 | 10 | Redistribution and use in source and binary forms, with or without |
seanwilson10 | 0:76fed7dd9235 | 11 | modification, are permitted provided that the following conditions are met: |
seanwilson10 | 0:76fed7dd9235 | 12 | - Redistributions of source code must retain the above copyright |
seanwilson10 | 0:76fed7dd9235 | 13 | notice, this list of conditions and the following disclaimer. |
seanwilson10 | 0:76fed7dd9235 | 14 | - Redistributions in binary form must reproduce the above copyright |
seanwilson10 | 0:76fed7dd9235 | 15 | notice, this list of conditions and the following disclaimer in |
seanwilson10 | 0:76fed7dd9235 | 16 | the documentation and/or other materials provided with the |
seanwilson10 | 0:76fed7dd9235 | 17 | distribution. |
seanwilson10 | 0:76fed7dd9235 | 18 | - Neither the name of Analog Devices, Inc. nor the names of its |
seanwilson10 | 0:76fed7dd9235 | 19 | contributors may be used to endorse or promote products derived |
seanwilson10 | 0:76fed7dd9235 | 20 | from this software without specific prior written permission. |
seanwilson10 | 0:76fed7dd9235 | 21 | - The use of this software may or may not infringe the patent rights |
seanwilson10 | 0:76fed7dd9235 | 22 | of one or more patent holders. This license does not release you |
seanwilson10 | 0:76fed7dd9235 | 23 | from the requirement that you obtain separate licenses from these |
seanwilson10 | 0:76fed7dd9235 | 24 | patent holders to use this software. |
seanwilson10 | 0:76fed7dd9235 | 25 | - Use of the software either in source or binary form, must be run |
seanwilson10 | 0:76fed7dd9235 | 26 | on or directly connected to an Analog Devices Inc. component. |
seanwilson10 | 0:76fed7dd9235 | 27 | |
seanwilson10 | 0:76fed7dd9235 | 28 | THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR |
seanwilson10 | 0:76fed7dd9235 | 29 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT, |
seanwilson10 | 0:76fed7dd9235 | 30 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
seanwilson10 | 0:76fed7dd9235 | 31 | IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT, |
seanwilson10 | 0:76fed7dd9235 | 32 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
seanwilson10 | 0:76fed7dd9235 | 33 | LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR |
seanwilson10 | 0:76fed7dd9235 | 34 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
seanwilson10 | 0:76fed7dd9235 | 35 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
seanwilson10 | 0:76fed7dd9235 | 36 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
seanwilson10 | 0:76fed7dd9235 | 37 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
seanwilson10 | 0:76fed7dd9235 | 38 | * |
seanwilson10 | 0:76fed7dd9235 | 39 | *****************************************************************************/ |
seanwilson10 | 0:76fed7dd9235 | 40 | #include "mbed.h" |
seanwilson10 | 0:76fed7dd9235 | 41 | #include "inc/adi_sense_api.h" |
seanwilson10 | 0:76fed7dd9235 | 42 | #include "inc/adi_sense_1000/adi_sense_1000_api.h" |
seanwilson10 | 0:76fed7dd9235 | 43 | #include "inc/adi_sense_log.h" |
seanwilson10 | 0:76fed7dd9235 | 44 | #include "common/utils.h" |
seanwilson10 | 0:76fed7dd9235 | 45 | |
seanwilson10 | 0:76fed7dd9235 | 46 | extern ADI_SENSE_CONFIG config; |
seanwilson10 | 0:76fed7dd9235 | 47 | |
seanwilson10 | 0:76fed7dd9235 | 48 | /* Change the following pointer to select any of the configurations above */ |
seanwilson10 | 0:76fed7dd9235 | 49 | static ADI_SENSE_CONFIG *pSelectedConfig = &config; |
seanwilson10 | 0:76fed7dd9235 | 50 | |
seanwilson10 | 0:76fed7dd9235 | 51 | static ADI_SENSE_CONNECTION connectionInfo = { |
seanwilson10 | 0:76fed7dd9235 | 52 | .type = ADI_SENSE_CONNECTION_TYPE_SPI, |
seanwilson10 | 0:76fed7dd9235 | 53 | .spi = { |
seanwilson10 | 0:76fed7dd9235 | 54 | .mosiPin = SPI_MOSI, |
seanwilson10 | 0:76fed7dd9235 | 55 | .misoPin = SPI_MISO, |
seanwilson10 | 0:76fed7dd9235 | 56 | .sckPin = SPI_SCK, |
seanwilson10 | 0:76fed7dd9235 | 57 | .csPin = D10, |
seanwilson10 | 0:76fed7dd9235 | 58 | .maxSpeedHz = 2000000, |
seanwilson10 | 0:76fed7dd9235 | 59 | }, |
seanwilson10 | 0:76fed7dd9235 | 60 | .gpio = { |
seanwilson10 | 0:76fed7dd9235 | 61 | .resetPin = D6, |
seanwilson10 | 0:76fed7dd9235 | 62 | .errorPin = D3, |
seanwilson10 | 0:76fed7dd9235 | 63 | .alertPin = D4, |
seanwilson10 | 0:76fed7dd9235 | 64 | .datareadyPin = D5, |
seanwilson10 | 0:76fed7dd9235 | 65 | }, |
seanwilson10 | 0:76fed7dd9235 | 66 | }; |
seanwilson10 | 0:76fed7dd9235 | 67 | |
seanwilson10 | 0:76fed7dd9235 | 68 | int main() |
seanwilson10 | 0:76fed7dd9235 | 69 | { |
seanwilson10 | 0:76fed7dd9235 | 70 | ADI_SENSE_RESULT res; |
seanwilson10 | 0:76fed7dd9235 | 71 | ADI_SENSE_DEVICE_HANDLE hDevice; |
seanwilson10 | 0:76fed7dd9235 | 72 | ADI_SENSE_MEASUREMENT_MODE eMeasurementMode = ADI_SENSE_MEASUREMENT_MODE_NORMAL; |
seanwilson10 | 0:76fed7dd9235 | 73 | bool_t bDeviceReady; |
seanwilson10 | 0:76fed7dd9235 | 74 | |
seanwilson10 | 0:76fed7dd9235 | 75 | /* |
seanwilson10 | 0:76fed7dd9235 | 76 | * Open an ADI Sense device instance. |
seanwilson10 | 0:76fed7dd9235 | 77 | */ |
seanwilson10 | 0:76fed7dd9235 | 78 | res = adi_sense_Open(0, &connectionInfo, &hDevice); |
seanwilson10 | 0:76fed7dd9235 | 79 | if (res != ADI_SENSE_SUCCESS) |
seanwilson10 | 0:76fed7dd9235 | 80 | { |
seanwilson10 | 0:76fed7dd9235 | 81 | ADI_SENSE_LOG_ERROR("Failed to open device instance"); |
seanwilson10 | 0:76fed7dd9235 | 82 | return res; |
seanwilson10 | 0:76fed7dd9235 | 83 | } |
seanwilson10 | 0:76fed7dd9235 | 84 | |
seanwilson10 | 0:76fed7dd9235 | 85 | /* |
seanwilson10 | 0:76fed7dd9235 | 86 | * Reset the given ADI Sense device.... |
seanwilson10 | 0:76fed7dd9235 | 87 | */ |
seanwilson10 | 0:76fed7dd9235 | 88 | ADI_SENSE_LOG_INFO("Resetting ADI Sense device, please wait..."); |
seanwilson10 | 0:76fed7dd9235 | 89 | res = adi_sense_Reset(hDevice); |
seanwilson10 | 0:76fed7dd9235 | 90 | if (res != ADI_SENSE_SUCCESS) |
seanwilson10 | 0:76fed7dd9235 | 91 | { |
seanwilson10 | 0:76fed7dd9235 | 92 | ADI_SENSE_LOG_ERROR("Failed to reset device"); |
seanwilson10 | 0:76fed7dd9235 | 93 | return res; |
seanwilson10 | 0:76fed7dd9235 | 94 | } |
seanwilson10 | 0:76fed7dd9235 | 95 | /* |
seanwilson10 | 0:76fed7dd9235 | 96 | * ...and wait until the device is ready. |
seanwilson10 | 0:76fed7dd9235 | 97 | */ |
seanwilson10 | 0:76fed7dd9235 | 98 | do { |
seanwilson10 | 0:76fed7dd9235 | 99 | wait_ms(100); |
seanwilson10 | 0:76fed7dd9235 | 100 | res = adi_sense_GetDeviceReadyState(hDevice, &bDeviceReady); |
seanwilson10 | 0:76fed7dd9235 | 101 | if (res != ADI_SENSE_SUCCESS) |
seanwilson10 | 0:76fed7dd9235 | 102 | { |
seanwilson10 | 0:76fed7dd9235 | 103 | ADI_SENSE_LOG_ERROR("Failed to get device ready-state"); |
seanwilson10 | 0:76fed7dd9235 | 104 | return res; |
seanwilson10 | 0:76fed7dd9235 | 105 | } |
seanwilson10 | 0:76fed7dd9235 | 106 | } while (! bDeviceReady); |
seanwilson10 | 0:76fed7dd9235 | 107 | ADI_SENSE_LOG_INFO("ADI Sense device ready"); |
seanwilson10 | 0:76fed7dd9235 | 108 | |
seanwilson10 | 0:76fed7dd9235 | 109 | /* |
seanwilson10 | 0:76fed7dd9235 | 110 | * Write configuration settings to the device registers. |
seanwilson10 | 0:76fed7dd9235 | 111 | * Settings are not applied until adi_sense_ApplyConfigUpdates() is called. |
seanwilson10 | 0:76fed7dd9235 | 112 | */ |
seanwilson10 | 0:76fed7dd9235 | 113 | ADI_SENSE_LOG_INFO("Setting device configuration"); |
seanwilson10 | 0:76fed7dd9235 | 114 | res = adi_sense_SetConfig(hDevice, pSelectedConfig); |
seanwilson10 | 0:76fed7dd9235 | 115 | if (res != ADI_SENSE_SUCCESS) |
seanwilson10 | 0:76fed7dd9235 | 116 | { |
seanwilson10 | 0:76fed7dd9235 | 117 | ADI_SENSE_LOG_ERROR("Failed to set device configuration"); |
seanwilson10 | 0:76fed7dd9235 | 118 | return res; |
seanwilson10 | 0:76fed7dd9235 | 119 | } |
seanwilson10 | 0:76fed7dd9235 | 120 | res = adi_sense_ApplyConfigUpdates(hDevice); |
seanwilson10 | 0:76fed7dd9235 | 121 | if (res != ADI_SENSE_SUCCESS) |
seanwilson10 | 0:76fed7dd9235 | 122 | { |
seanwilson10 | 0:76fed7dd9235 | 123 | ADI_SENSE_LOG_ERROR("Failed to apply device configuration"); |
seanwilson10 | 0:76fed7dd9235 | 124 | return res; |
seanwilson10 | 0:76fed7dd9235 | 125 | } |
seanwilson10 | 0:76fed7dd9235 | 126 | |
seanwilson10 | 0:76fed7dd9235 | 127 | /* |
seanwilson10 | 0:76fed7dd9235 | 128 | * Kick off the measurement cycle here |
seanwilson10 | 0:76fed7dd9235 | 129 | */ |
seanwilson10 | 0:76fed7dd9235 | 130 | ADI_SENSE_LOG_INFO("Configuration completed, starting measurement cycles"); |
seanwilson10 | 0:76fed7dd9235 | 131 | utils_runMeasurement(hDevice, eMeasurementMode); |
seanwilson10 | 0:76fed7dd9235 | 132 | |
seanwilson10 | 0:76fed7dd9235 | 133 | /* |
seanwilson10 | 0:76fed7dd9235 | 134 | * Clean up and exit |
seanwilson10 | 0:76fed7dd9235 | 135 | */ |
seanwilson10 | 0:76fed7dd9235 | 136 | res = adi_sense_Close(hDevice); |
seanwilson10 | 0:76fed7dd9235 | 137 | if (res != ADI_SENSE_SUCCESS) |
seanwilson10 | 0:76fed7dd9235 | 138 | { |
seanwilson10 | 0:76fed7dd9235 | 139 | ADI_SENSE_LOG_ERROR("Failed to close device instance"); |
seanwilson10 | 0:76fed7dd9235 | 140 | return res; |
seanwilson10 | 0:76fed7dd9235 | 141 | } |
seanwilson10 | 0:76fed7dd9235 | 142 | |
seanwilson10 | 0:76fed7dd9235 | 143 | return 0; |
seanwilson10 | 0:76fed7dd9235 | 144 | } |
seanwilson10 | 0:76fed7dd9235 | 145 |