Simple demo for exercising the board

Dependencies:   MAX11300 MAX4822 OneWire Terminal ds3231 mbed

Committer:
j3
Date:
Mon Mar 06 23:47:46 2017 +0000
Revision:
12:97bc95dbfc64
Parent:
11:fe03fb61fb08
Removed Timer object since not used

Who changed what in which revision?

UserRevisionLine numberNew contents of line
j3 0:24b8a6f0a563 1 /**********************************************************************
j3 0:24b8a6f0a563 2 * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
j3 0:24b8a6f0a563 3 *
j3 0:24b8a6f0a563 4 * Permission is hereby granted, free of charge, to any person obtaining a
j3 0:24b8a6f0a563 5 * copy of this software and associated documentation files (the "Software"),
j3 0:24b8a6f0a563 6 * to deal in the Software without restriction, including without limitation
j3 0:24b8a6f0a563 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
j3 0:24b8a6f0a563 8 * and/or sell copies of the Software, and to permit persons to whom the
j3 0:24b8a6f0a563 9 * Software is furnished to do so, subject to the following conditions:
j3 0:24b8a6f0a563 10 *
j3 0:24b8a6f0a563 11 * The above copyright notice and this permission notice shall be included
j3 0:24b8a6f0a563 12 * in all copies or substantial portions of the Software.
j3 0:24b8a6f0a563 13 *
j3 0:24b8a6f0a563 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
j3 0:24b8a6f0a563 15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
j3 0:24b8a6f0a563 16 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
j3 0:24b8a6f0a563 17 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
j3 0:24b8a6f0a563 18 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
j3 0:24b8a6f0a563 19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
j3 0:24b8a6f0a563 20 * OTHER DEALINGS IN THE SOFTWARE.
j3 0:24b8a6f0a563 21 *
j3 0:24b8a6f0a563 22 * Except as contained in this notice, the name of Maxim Integrated
j3 0:24b8a6f0a563 23 * Products, Inc. shall not be used except as stated in the Maxim Integrated
j3 0:24b8a6f0a563 24 * Products, Inc. Branding Policy.
j3 0:24b8a6f0a563 25 *
j3 0:24b8a6f0a563 26 * The mere transfer of this software does not imply any licenses
j3 0:24b8a6f0a563 27 * of trade secrets, proprietary technology, copyrights, patents,
j3 0:24b8a6f0a563 28 * trademarks, maskwork rights, or any other form of intellectual
j3 0:24b8a6f0a563 29 * property whatsoever. Maxim Integrated Products, Inc. retains all
j3 0:24b8a6f0a563 30 * ownership rights.
j3 0:24b8a6f0a563 31 **********************************************************************/
j3 0:24b8a6f0a563 32
j3 0:24b8a6f0a563 33 #include "mbed.h"
j3 0:24b8a6f0a563 34 #include "ds3231.h"
j3 0:24b8a6f0a563 35 #include "MAX4822.h"
j3 0:24b8a6f0a563 36 #include "MAX11300.h"
j3 0:24b8a6f0a563 37 #include "Terminal.h"
j3 0:24b8a6f0a563 38 #include "OneWire.h"
j3 0:24b8a6f0a563 39
j3 0:24b8a6f0a563 40 using namespace OneWire;
j3 0:24b8a6f0a563 41 using namespace RomCommands;
j3 0:24b8a6f0a563 42
j3 0:24b8a6f0a563 43 void set_rtc(Terminal & term, Ds3231 & rtc);
j3 0:24b8a6f0a563 44 void get_time_date(Terminal & term, Ds3231 & rtc);
j3 0:24b8a6f0a563 45 void search_ow_bus(Terminal & term, DS2484 & owm);
j3 0:24b8a6f0a563 46 void print_rom_id(Terminal & term, RomId & romId);
j3 8:8e36fe48b351 47 bool calibrate_420_io(Terminal & term, MAX11300 & pixi, DS2484 & owm, uint16_t *calData, bool loopAlreadyCal);
j3 5:2fe6dd435618 48 void DS1920Menu(Terminal & term, const RomId & romId, MultidropRomIterator & selector);
j3 8:8e36fe48b351 49 bool check_420_cal(Terminal & term, DS2484 & owm, uint16_t *calData);
j3 0:24b8a6f0a563 50
j3 0:24b8a6f0a563 51 int main(void)
j3 0:24b8a6f0a563 52 {
j3 0:24b8a6f0a563 53 Terminal term(USBTX, USBRX);
j3 0:24b8a6f0a563 54 term.baud(57600);
j3 0:24b8a6f0a563 55 term.cls();
j3 0:24b8a6f0a563 56 term.home();
j3 0:24b8a6f0a563 57 term.printf("Starting Demo\n");
j3 0:24b8a6f0a563 58
j3 0:24b8a6f0a563 59 SPI spi_bus(D11, D12, D13);
j3 0:24b8a6f0a563 60 MAX4822 rly_drvr(spi_bus, D10);
j3 0:24b8a6f0a563 61 DigitalOut rly_drvr_set(D7, 1);
j3 0:24b8a6f0a563 62 DigitalOut rly_drvr_reset(D6, 1);
j3 0:24b8a6f0a563 63
j3 0:24b8a6f0a563 64 rly_drvr.reset_all_relays(rly_drvr_reset);
j3 0:24b8a6f0a563 65
j3 1:03c04017a728 66 MAX11300 pixi(spi_bus, D8, NC, D9);
j3 0:24b8a6f0a563 67
j3 0:24b8a6f0a563 68 //set all analog outs to 0
j3 0:24b8a6f0a563 69 for(uint8_t idx = 0; idx < 9; idx++)
j3 0:24b8a6f0a563 70 {
j3 0:24b8a6f0a563 71 pixi.single_ended_dac_write(static_cast<MAX11300::MAX11300_Ports>(idx), 0);
j3 0:24b8a6f0a563 72 }
j3 0:24b8a6f0a563 73
j3 0:24b8a6f0a563 74 //ensure latching relays are reset
j3 0:24b8a6f0a563 75 for(uint8_t idx = 0; idx < 3; idx++)
j3 0:24b8a6f0a563 76 {
j3 0:24b8a6f0a563 77 pixi.gpio_write(static_cast<MAX11300::MAX11300_Ports>(idx + 9), 1);
j3 10:5c9242143a30 78 wait_ms(200);
j3 0:24b8a6f0a563 79 pixi.gpio_write(static_cast<MAX11300::MAX11300_Ports>(idx + 9), 0);
j3 0:24b8a6f0a563 80 }
j3 0:24b8a6f0a563 81
j3 0:24b8a6f0a563 82 I2C i2c_bus(D14, D15);
j3 0:24b8a6f0a563 83 i2c_bus.frequency(400000);
j3 0:24b8a6f0a563 84
j3 0:24b8a6f0a563 85 Ds3231 rtc(i2c_bus);
j3 0:24b8a6f0a563 86
j3 0:24b8a6f0a563 87 DS2484 owm(i2c_bus);
j3 0:24b8a6f0a563 88 OneWireMaster::CmdResult owm_result = owm.OWInitMaster();
j3 10:5c9242143a30 89 if(owm_result != OneWireMaster::Success)
j3 0:24b8a6f0a563 90 {
j3 10:5c9242143a30 91 //wait_ms(100);
j3 0:24b8a6f0a563 92 term.printf("Failed to initialize OneWire master\n");
j3 10:5c9242143a30 93 //owm_result = owm.OWInitMaster();
j3 0:24b8a6f0a563 94 }
j3 10:5c9242143a30 95 else
j3 10:5c9242143a30 96 {
j3 10:5c9242143a30 97 term.printf("OneWire master initialized\n\n");
j3 10:5c9242143a30 98 }
j3 10:5c9242143a30 99
j3 0:24b8a6f0a563 100
j3 8:8e36fe48b351 101 float aio_slope = 0;
j3 8:8e36fe48b351 102 float aio_offset = 0;
j3 8:8e36fe48b351 103 float aii_slope = 0;
j3 8:8e36fe48b351 104 float aii_offset = 0;
j3 8:8e36fe48b351 105 uint16_t calData[4];
j3 8:8e36fe48b351 106
j3 8:8e36fe48b351 107 bool currentLoopCal = false;
j3 8:8e36fe48b351 108 if(check_420_cal(term, owm, calData))
j3 8:8e36fe48b351 109 {
j3 8:8e36fe48b351 110 aio_slope = (((calData[1]*1.0) - (calData[0]*1.0))/16.0);
j3 8:8e36fe48b351 111 aio_offset = ((-1.0*aio_slope*4.0) + calData[0]);
j3 8:8e36fe48b351 112
j3 8:8e36fe48b351 113 aii_slope = (16.0/((calData[3]*1.0) - (calData[2]*1.0)));
j3 8:8e36fe48b351 114 aii_offset = ((-1.0*aii_slope*calData[2]) + 4.0);
j3 8:8e36fe48b351 115
j3 8:8e36fe48b351 116 currentLoopCal = true;
j3 8:8e36fe48b351 117 }
j3 8:8e36fe48b351 118
j3 0:24b8a6f0a563 119 int32_t user_entry = 0;
j3 0:24b8a6f0a563 120 int32_t relay = 0;
j3 0:24b8a6f0a563 121
j3 2:0c0994f70fd2 122 uint16_t analog_out_ch, analog_val;
j3 2:0c0994f70fd2 123 float avo_volts, aio_mA, aii_mA;
j3 0:24b8a6f0a563 124
j3 2:0c0994f70fd2 125 const int32_t QUIT = 15;
j3 0:24b8a6f0a563 126
j3 1:03c04017a728 127 MAX11300::CmdResult pixi_result;
j3 1:03c04017a728 128 MAX4822::CmdResult rly_drvr_result;
j3 1:03c04017a728 129
j3 0:24b8a6f0a563 130 while(user_entry != QUIT)
j3 0:24b8a6f0a563 131 {
j3 2:0c0994f70fd2 132 term.printf("1. Set RTC\n");
j3 2:0c0994f70fd2 133 term.printf("2. Get Time/Date\n");
j3 2:0c0994f70fd2 134 term.printf("3. Search OneWire bus\n");
j3 2:0c0994f70fd2 135 term.printf("4. Set non-latching relay\n");
j3 2:0c0994f70fd2 136 term.printf("5. Reset non-latching relay\n");
j3 2:0c0994f70fd2 137 term.printf("6. Set all non-latching relays\n");
j3 2:0c0994f70fd2 138 term.printf("7. Reset all non-latching relays\n");
j3 2:0c0994f70fd2 139 term.printf("8. Set latching relay\n");
j3 2:0c0994f70fd2 140 term.printf("9. Reset latching relay\n");
j3 0:24b8a6f0a563 141 term.printf("10. Set 0-10 analog out\n");
j3 0:24b8a6f0a563 142 term.printf("11. Set 4-20 out\n");
j3 0:24b8a6f0a563 143 term.printf("12. Get 4-20 in\n");
j3 2:0c0994f70fd2 144 term.printf("13. Calibrate 4-20 io\n");
j3 0:24b8a6f0a563 145 term.printf("%d. Clear Screen\n", (QUIT - 1));
j3 0:24b8a6f0a563 146 term.printf("%d. Quit\n\n", QUIT);
j3 0:24b8a6f0a563 147
j3 0:24b8a6f0a563 148 user_entry = term.get_int32("Please select an option above: ", 1, QUIT);
j3 0:24b8a6f0a563 149
j3 0:24b8a6f0a563 150 //get non-latching relay
j3 0:24b8a6f0a563 151 if((user_entry == 4) || (user_entry == 5))
j3 0:24b8a6f0a563 152 {
j3 0:24b8a6f0a563 153 relay = term.get_int32("Select a relay from 1 to 8: ", 1, 8);
j3 0:24b8a6f0a563 154 }
j3 0:24b8a6f0a563 155
j3 0:24b8a6f0a563 156 //get latching relay
j3 0:24b8a6f0a563 157 if((user_entry == 8) || (user_entry == 9))
j3 0:24b8a6f0a563 158 {
j3 0:24b8a6f0a563 159 relay = (8 + term.get_int32("Select a relay from 1 to 3: ", 1, 3));
j3 0:24b8a6f0a563 160 }
j3 0:24b8a6f0a563 161
j3 0:24b8a6f0a563 162 switch(user_entry)
j3 0:24b8a6f0a563 163 {
j3 0:24b8a6f0a563 164 case 1:
j3 0:24b8a6f0a563 165 set_rtc(term, rtc);
j3 0:24b8a6f0a563 166 break;
j3 0:24b8a6f0a563 167
j3 0:24b8a6f0a563 168 case 2:
j3 0:24b8a6f0a563 169 get_time_date(term, rtc);
j3 0:24b8a6f0a563 170 break;
j3 0:24b8a6f0a563 171
j3 0:24b8a6f0a563 172 case 3:
j3 0:24b8a6f0a563 173 search_ow_bus(term, owm);
j3 0:24b8a6f0a563 174 break;
j3 0:24b8a6f0a563 175
j3 0:24b8a6f0a563 176 case 4:
j3 1:03c04017a728 177 rly_drvr_result = rly_drvr.set_relay(static_cast<MAX4822::RelayChannel>(relay));
j3 1:03c04017a728 178 if(rly_drvr_result != MAX4822::Success)
j3 1:03c04017a728 179 {
j3 1:03c04017a728 180 term.printf("Failed to set relay\n");
j3 1:03c04017a728 181 }
j3 0:24b8a6f0a563 182 break;
j3 0:24b8a6f0a563 183
j3 0:24b8a6f0a563 184 case 5:
j3 1:03c04017a728 185 rly_drvr_result = rly_drvr.reset_relay(static_cast<MAX4822::RelayChannel>(relay));
j3 1:03c04017a728 186 if(rly_drvr_result != MAX4822::Success)
j3 1:03c04017a728 187 {
j3 1:03c04017a728 188 term.printf("Failed to reset relay\n");
j3 1:03c04017a728 189 }
j3 0:24b8a6f0a563 190 break;
j3 0:24b8a6f0a563 191
j3 0:24b8a6f0a563 192 case 6:
j3 0:24b8a6f0a563 193 rly_drvr.set_all_relays(rly_drvr_set);
j3 0:24b8a6f0a563 194 term.printf("\n");
j3 0:24b8a6f0a563 195 break;
j3 0:24b8a6f0a563 196
j3 0:24b8a6f0a563 197 case 7:
j3 0:24b8a6f0a563 198 rly_drvr.reset_all_relays(rly_drvr_reset);
j3 0:24b8a6f0a563 199 term.printf("\n");
j3 0:24b8a6f0a563 200 break;
j3 0:24b8a6f0a563 201
j3 0:24b8a6f0a563 202 case 8:
j3 1:03c04017a728 203 pixi_result = pixi.gpio_write(static_cast<MAX11300::MAX11300_Ports>(relay), 1);
j3 1:03c04017a728 204 if(pixi_result != MAX11300::Success)
j3 1:03c04017a728 205 {
j3 1:03c04017a728 206 term.printf("Failed to set relay\n");
j3 1:03c04017a728 207 }
j3 0:24b8a6f0a563 208 break;
j3 0:24b8a6f0a563 209
j3 0:24b8a6f0a563 210 case 9:
j3 1:03c04017a728 211 pixi_result = pixi.gpio_write(static_cast<MAX11300::MAX11300_Ports>(relay), 0);
j3 1:03c04017a728 212 if(pixi_result != MAX11300::Success)
j3 1:03c04017a728 213 {
j3 1:03c04017a728 214 term.printf("Failed to reset relay\n");
j3 1:03c04017a728 215 }
j3 0:24b8a6f0a563 216 break;
j3 0:24b8a6f0a563 217
j3 0:24b8a6f0a563 218 case 10:
j3 2:0c0994f70fd2 219 analog_out_ch = (term.get_int32("Please select a 0-10V output; 1-8: ", 1, 8) - 1);
j3 2:0c0994f70fd2 220 avo_volts = term.get_float("Please enter a voltage from 0.0 to 10.0 volts: ", -0.1, 10.1);
j3 2:0c0994f70fd2 221 analog_val = static_cast<uint16_t>((avo_volts/10.0) * 4095);
j3 1:03c04017a728 222
j3 5:2fe6dd435618 223 term.printf("DAC Code = %d\n", analog_val);
j3 5:2fe6dd435618 224
j3 2:0c0994f70fd2 225 pixi_result = pixi.single_ended_dac_write(static_cast<MAX11300::MAX11300_Ports>(analog_out_ch), analog_val);
j3 1:03c04017a728 226 if(pixi_result != MAX11300::Success)
j3 1:03c04017a728 227 {
j3 1:03c04017a728 228 term.printf("Failed to set 0-10 out\n");
j3 1:03c04017a728 229 }
j3 0:24b8a6f0a563 230 break;
j3 0:24b8a6f0a563 231
j3 0:24b8a6f0a563 232 case 11:
j3 8:8e36fe48b351 233 if(currentLoopCal)
j3 1:03c04017a728 234 {
j3 8:8e36fe48b351 235 aio_mA = term.get_float("Please enter a current from 4.0 to 20.0 mA: ", 3.9, 20.1);
j3 8:8e36fe48b351 236 analog_val = static_cast<uint16_t>((aio_slope * aio_mA) + aio_offset);
j3 8:8e36fe48b351 237
j3 8:8e36fe48b351 238 pixi_result = pixi.single_ended_dac_write(MAX11300::PORT8, analog_val);
j3 8:8e36fe48b351 239 if(pixi_result != MAX11300::Success)
j3 8:8e36fe48b351 240 {
j3 8:8e36fe48b351 241 term.printf("Failed to set 4-20 out\n");
j3 8:8e36fe48b351 242 }
j3 8:8e36fe48b351 243 }
j3 8:8e36fe48b351 244 else
j3 8:8e36fe48b351 245 {
j3 8:8e36fe48b351 246 term.printf("Please calibrate 4-20mA loop first, option 13.\n");
j3 1:03c04017a728 247 }
j3 0:24b8a6f0a563 248 break;
j3 0:24b8a6f0a563 249
j3 0:24b8a6f0a563 250 case 12:
j3 8:8e36fe48b351 251 if(currentLoopCal)
j3 1:03c04017a728 252 {
j3 8:8e36fe48b351 253 pixi_result = pixi.single_ended_adc_read(MAX11300::PORT12, analog_val);
j3 8:8e36fe48b351 254 aii_mA = ((aii_slope*analog_val) + aii_offset);
j3 8:8e36fe48b351 255 if(pixi_result == MAX11300::Success)
j3 8:8e36fe48b351 256 {
j3 8:8e36fe48b351 257 term.printf("4-20 in = %.2fmA\n", aii_mA);
j3 8:8e36fe48b351 258 }
j3 8:8e36fe48b351 259 else
j3 8:8e36fe48b351 260 {
j3 8:8e36fe48b351 261 term.printf("Failed to read 4-20 in\n");
j3 8:8e36fe48b351 262 }
j3 1:03c04017a728 263 }
j3 1:03c04017a728 264 else
j3 1:03c04017a728 265 {
j3 8:8e36fe48b351 266 term.printf("Please calibrate 4-20mA loop first, option 13.\n");
j3 1:03c04017a728 267 }
j3 0:24b8a6f0a563 268 break;
j3 0:24b8a6f0a563 269
j3 2:0c0994f70fd2 270 case 13:
j3 8:8e36fe48b351 271 if(calibrate_420_io(term, pixi, owm, calData, currentLoopCal))
j3 8:8e36fe48b351 272 {
j3 8:8e36fe48b351 273 aio_slope = (((calData[1]*1.0) - (calData[0]*1.0))/16.0);
j3 8:8e36fe48b351 274 aio_offset = ((-1.0*aio_slope*4.0) + calData[0]);
j3 8:8e36fe48b351 275
j3 8:8e36fe48b351 276 aii_slope = (16.0/((calData[3]*1.0) - (calData[2]*1.0)));
j3 8:8e36fe48b351 277 aii_offset = ((-1.0*aii_slope*calData[2]) + 4.0);
j3 8:8e36fe48b351 278
j3 8:8e36fe48b351 279 currentLoopCal = true;
j3 8:8e36fe48b351 280
j3 8:8e36fe48b351 281 term.printf("Calibration data saved to 1-Wire EEPROM\n");
j3 8:8e36fe48b351 282 }
j3 2:0c0994f70fd2 283 break;
j3 2:0c0994f70fd2 284
j3 0:24b8a6f0a563 285 case (QUIT - 1):
j3 0:24b8a6f0a563 286 term.cls();
j3 0:24b8a6f0a563 287 term.home();
j3 0:24b8a6f0a563 288 break;
j3 0:24b8a6f0a563 289
j3 0:24b8a6f0a563 290 case QUIT:
j3 0:24b8a6f0a563 291 term.printf("\nEnding Program\n");
j3 0:24b8a6f0a563 292 break;
j3 0:24b8a6f0a563 293
j3 0:24b8a6f0a563 294 default:
j3 0:24b8a6f0a563 295 mbed_die();
j3 0:24b8a6f0a563 296 break;
j3 0:24b8a6f0a563 297 }
j3 0:24b8a6f0a563 298 }
j3 0:24b8a6f0a563 299 }
j3 0:24b8a6f0a563 300
j3 0:24b8a6f0a563 301 //*********************************************************************
j3 0:24b8a6f0a563 302 void set_rtc(Terminal & term, Ds3231 & rtc)
j3 0:24b8a6f0a563 303 {
j3 0:24b8a6f0a563 304 //default, use bit masks in ds3231.h for desired operation
j3 0:24b8a6f0a563 305 ds3231_cntl_stat_t rtc_control_status = {0,0};
j3 0:24b8a6f0a563 306 ds3231_time_t rtc_time;
j3 0:24b8a6f0a563 307 ds3231_calendar_t rtc_calendar;
j3 0:24b8a6f0a563 308
j3 0:24b8a6f0a563 309 rtc.set_cntl_stat_reg(rtc_control_status);
j3 0:24b8a6f0a563 310
j3 0:24b8a6f0a563 311 //get day from user
j3 0:24b8a6f0a563 312 rtc_calendar.day = term.get_int32("\nPlease enter day of week, 1 for Sunday (1-7): ", 1, 7);
j3 0:24b8a6f0a563 313
j3 0:24b8a6f0a563 314 //get day of month from user
j3 0:24b8a6f0a563 315 rtc_calendar.date = term.get_int32("\nPlease enter day of month (1-31): ", 1, 31);
j3 0:24b8a6f0a563 316
j3 0:24b8a6f0a563 317 //get month from user
j3 0:24b8a6f0a563 318 rtc_calendar.month = term.get_int32("\nPlease enter the month, 1 for January (1-12): ", 1, 12);
j3 0:24b8a6f0a563 319
j3 0:24b8a6f0a563 320 //get year from user
j3 0:24b8a6f0a563 321 rtc_calendar.year = term.get_int32("\nPlease enter the year (0-99): ", 0, 99);
j3 0:24b8a6f0a563 322
j3 0:24b8a6f0a563 323 //Get time mode
j3 0:24b8a6f0a563 324 rtc_time.mode = term.get_int32("\nWhat time mode? 1 for 12hr 0 for 24hr: ", 0, 1);
j3 0:24b8a6f0a563 325
j3 0:24b8a6f0a563 326 if(rtc_time.mode)
j3 0:24b8a6f0a563 327 {
j3 0:24b8a6f0a563 328 //Get AM/PM status
j3 0:24b8a6f0a563 329 rtc_time.am_pm = term.get_int32("\nIs it AM or PM? 0 for AM 1 for PM: ", 0, 1);
j3 0:24b8a6f0a563 330 //Get hour from user
j3 0:24b8a6f0a563 331 rtc_time.hours = term.get_int32("\nPlease enter the hour (1-12): ", 1, 12);
j3 0:24b8a6f0a563 332 }
j3 0:24b8a6f0a563 333 else
j3 0:24b8a6f0a563 334 {
j3 0:24b8a6f0a563 335 //Get hour from user
j3 0:24b8a6f0a563 336 rtc_time.hours = term.get_int32("\nPlease enter the hour (0-23): ", 0, 23);
j3 0:24b8a6f0a563 337 }
j3 0:24b8a6f0a563 338
j3 0:24b8a6f0a563 339 //Get minutes from user
j3 0:24b8a6f0a563 340 rtc_time.minutes = term.get_int32("\nPlease enter the minute (0-59): ", 0, 59);
j3 0:24b8a6f0a563 341
j3 0:24b8a6f0a563 342
j3 0:24b8a6f0a563 343 //Get seconds from user
j3 0:24b8a6f0a563 344 rtc_time.seconds = term.get_int32("\nPlease enter the second (0-59): ", 0, 59);
j3 0:24b8a6f0a563 345
j3 0:24b8a6f0a563 346 term.printf("\n");
j3 0:24b8a6f0a563 347
j3 0:24b8a6f0a563 348 rtc.set_time(rtc_time);
j3 0:24b8a6f0a563 349 rtc.set_calendar(rtc_calendar);
j3 0:24b8a6f0a563 350 }
j3 0:24b8a6f0a563 351
j3 0:24b8a6f0a563 352 //*********************************************************************
j3 0:24b8a6f0a563 353 void get_time_date(Terminal & term, Ds3231 & rtc)
j3 0:24b8a6f0a563 354 {
j3 0:24b8a6f0a563 355 time_t epoch_time;
j3 0:24b8a6f0a563 356
j3 0:24b8a6f0a563 357 epoch_time = rtc.get_epoch();
j3 0:24b8a6f0a563 358 term.printf("\n%s\n", ctime(&epoch_time));
j3 0:24b8a6f0a563 359 }
j3 0:24b8a6f0a563 360
j3 0:24b8a6f0a563 361 //*********************************************************************
j3 0:24b8a6f0a563 362 void search_ow_bus(Terminal & term, DS2484 & owm)
j3 0:24b8a6f0a563 363 {
j3 0:24b8a6f0a563 364 OneWireMaster::CmdResult result = owm.OWReset();
j3 5:2fe6dd435618 365 MultidropRomIterator selector(owm);
j3 0:24b8a6f0a563 366 SearchState search_state;
j3 0:24b8a6f0a563 367
j3 0:24b8a6f0a563 368 if(result == OneWireMaster::Success)
j3 0:24b8a6f0a563 369 {
j3 0:24b8a6f0a563 370 term.printf("\nOWReset success, starting search\n");
j3 0:24b8a6f0a563 371
j3 0:24b8a6f0a563 372 result = OWFirst(owm, search_state);
j3 0:24b8a6f0a563 373 if(result == OneWireMaster::Success)
j3 0:24b8a6f0a563 374 {
j3 0:24b8a6f0a563 375 while(result == OneWireMaster::Success)
j3 0:24b8a6f0a563 376 {
j3 0:24b8a6f0a563 377 //print current devices rom id
j3 0:24b8a6f0a563 378 print_rom_id(term, search_state.romId);
j3 0:24b8a6f0a563 379
j3 5:2fe6dd435618 380 if(search_state.romId.familyCode() == 0x10)
j3 6:18a831a757b5 381 {
j3 6:18a831a757b5 382 DS1920Menu(term, search_state.romId, selector);
j3 6:18a831a757b5 383 }
j3 5:2fe6dd435618 384
j3 0:24b8a6f0a563 385 //find the next device if any
j3 0:24b8a6f0a563 386 result = OWNext(owm, search_state);
j3 0:24b8a6f0a563 387 }
j3 0:24b8a6f0a563 388 term.printf("\n");
j3 0:24b8a6f0a563 389 }
j3 0:24b8a6f0a563 390 else
j3 0:24b8a6f0a563 391 {
j3 0:24b8a6f0a563 392 term.printf("\nSearch failed\n");
j3 0:24b8a6f0a563 393 term.printf("\nError code = %d\n", result);
j3 0:24b8a6f0a563 394 }
j3 0:24b8a6f0a563 395 }
j3 0:24b8a6f0a563 396 else
j3 0:24b8a6f0a563 397 {
j3 0:24b8a6f0a563 398 term.printf("\nFailed to find any 1-wire devices on bus\n");
j3 0:24b8a6f0a563 399 term.printf("\nError code = %d\n", result);
j3 0:24b8a6f0a563 400 }
j3 0:24b8a6f0a563 401 }
j3 0:24b8a6f0a563 402
j3 0:24b8a6f0a563 403 //*********************************************************************
j3 0:24b8a6f0a563 404 void print_rom_id(Terminal & term, RomId & romId)
j3 0:24b8a6f0a563 405 {
j3 0:24b8a6f0a563 406 //print the rom number
j3 0:24b8a6f0a563 407 term.printf("\n");
j3 10:5c9242143a30 408 int8_t idx = 7;
j3 0:24b8a6f0a563 409 do
j3 0:24b8a6f0a563 410 {
j3 10:5c9242143a30 411 term.printf("0x%02x ", romId.buffer[idx--]);
j3 0:24b8a6f0a563 412 }
j3 0:24b8a6f0a563 413 while(idx >= 0);
j3 0:24b8a6f0a563 414 term.printf("\n");
j3 0:24b8a6f0a563 415 }
j3 2:0c0994f70fd2 416
j3 2:0c0994f70fd2 417 //*********************************************************************
j3 8:8e36fe48b351 418 bool calibrate_420_io(Terminal & term, MAX11300 & pixi, DS2484 & owm, uint16_t *calData, bool loopAlreadyCal)
j3 2:0c0994f70fd2 419 {
j3 2:0c0994f70fd2 420 char user_entry;
j3 2:0c0994f70fd2 421 //initial vals for aio determined imperically on one pcb
j3 2:0c0994f70fd2 422 static uint16_t aio_4mA = 518;
j3 2:0c0994f70fd2 423 static uint16_t aio_20mA = 2592;
j3 8:8e36fe48b351 424
j3 8:8e36fe48b351 425 if(loopAlreadyCal)
j3 8:8e36fe48b351 426 {
j3 8:8e36fe48b351 427 aio_4mA = calData[0];
j3 8:8e36fe48b351 428 aio_20mA = calData[1];
j3 8:8e36fe48b351 429 }
j3 2:0c0994f70fd2 430 uint16_t aii_4mA, aii_20mA;
j3 2:0c0994f70fd2 431
j3 4:2a25a4e00541 432 term.cls();
j3 4:2a25a4e00541 433 term.home();
j3 4:2a25a4e00541 434
j3 2:0c0994f70fd2 435 //cal aio
j3 2:0c0994f70fd2 436 term.printf("\nConnect DMM in series with AIO and AII.\n");
j3 4:2a25a4e00541 437 term.printf("AIO----(DMMM)----AII\n\n");
j3 4:2a25a4e00541 438 term.printf("Use 'i' and 'd' keys to increase/decrease measurement to calibration value.\n\n");
j3 4:2a25a4e00541 439 term.printf("Setting AIO calibration val to 4mA, enter 'q' when DMM measurement = 4mA.\n\n");
j3 2:0c0994f70fd2 440
j3 2:0c0994f70fd2 441 do
j3 2:0c0994f70fd2 442 {
j3 10:5c9242143a30 443 printf("aio_4mA = %d\n", aio_4mA);
j3 2:0c0994f70fd2 444 pixi.single_ended_dac_write(MAX11300::PORT8, aio_4mA);
j3 4:2a25a4e00541 445 user_entry = term.get_char("increase (i), decrease (d), quit (q) when DMM = 4mA: ", 'd', 'q');
j3 2:0c0994f70fd2 446
j3 2:0c0994f70fd2 447 if(user_entry == 'i')
j3 2:0c0994f70fd2 448 {
j3 2:0c0994f70fd2 449 aio_4mA++;
j3 2:0c0994f70fd2 450 }
j3 2:0c0994f70fd2 451 else if(user_entry == 'd')
j3 2:0c0994f70fd2 452 {
j3 2:0c0994f70fd2 453 aio_4mA--;
j3 2:0c0994f70fd2 454 }
j3 2:0c0994f70fd2 455 else if(user_entry == 'q')
j3 2:0c0994f70fd2 456 {
j3 4:2a25a4e00541 457 term.printf("\nSetting AIO calibration val to 20mA, enter 'q' when DMM measurement = 20mA.\n\n");
j3 2:0c0994f70fd2 458 }
j3 2:0c0994f70fd2 459 else
j3 2:0c0994f70fd2 460 {
j3 2:0c0994f70fd2 461 term.printf("Not an option, please read the instructions.\n");
j3 2:0c0994f70fd2 462 }
j3 2:0c0994f70fd2 463 }
j3 2:0c0994f70fd2 464 while(user_entry != 'q');
j3 2:0c0994f70fd2 465
j3 2:0c0994f70fd2 466 do
j3 2:0c0994f70fd2 467 {
j3 2:0c0994f70fd2 468 pixi.single_ended_dac_write(MAX11300::PORT8, aio_20mA);
j3 4:2a25a4e00541 469 user_entry = term.get_char("increase (i), decrease (d), quit (q) when DMM = 20mA: ", 'd', 'q');
j3 2:0c0994f70fd2 470
j3 2:0c0994f70fd2 471 if(user_entry == 'i')
j3 2:0c0994f70fd2 472 {
j3 2:0c0994f70fd2 473 aio_20mA++;
j3 2:0c0994f70fd2 474 }
j3 2:0c0994f70fd2 475 else if(user_entry == 'd')
j3 2:0c0994f70fd2 476 {
j3 2:0c0994f70fd2 477 aio_20mA--;
j3 2:0c0994f70fd2 478 }
j3 2:0c0994f70fd2 479 else if(user_entry == 'q')
j3 2:0c0994f70fd2 480 {
j3 4:2a25a4e00541 481 term.printf("\nExecuting AII Cal\n\n");
j3 2:0c0994f70fd2 482 }
j3 2:0c0994f70fd2 483 else
j3 2:0c0994f70fd2 484 {
j3 2:0c0994f70fd2 485 term.printf("Not an option, please read the instructions.\n");
j3 2:0c0994f70fd2 486 }
j3 2:0c0994f70fd2 487 }
j3 2:0c0994f70fd2 488 while(user_entry != 'q');
j3 2:0c0994f70fd2 489
j3 8:8e36fe48b351 490 calData[0] = aio_4mA;
j3 8:8e36fe48b351 491 calData[1] = aio_20mA;
j3 2:0c0994f70fd2 492
j3 4:2a25a4e00541 493 uint8_t idx;
j3 2:0c0994f70fd2 494 //cal aii
j3 2:0c0994f70fd2 495 pixi.single_ended_dac_write(MAX11300::PORT8, aio_4mA);
j3 4:2a25a4e00541 496 for(idx = 0; idx < 10; idx++)
j3 4:2a25a4e00541 497 {
j3 4:2a25a4e00541 498 term.printf("AII 4mA input cal...\n");
j3 4:2a25a4e00541 499 wait(1.0);
j3 4:2a25a4e00541 500 }
j3 2:0c0994f70fd2 501 pixi.single_ended_adc_read(MAX11300::PORT12, aii_4mA);
j3 4:2a25a4e00541 502
j3 8:8e36fe48b351 503 calData[2] = aii_4mA;
j3 8:8e36fe48b351 504
j3 2:0c0994f70fd2 505 pixi.single_ended_dac_write(MAX11300::PORT8, aio_20mA);
j3 4:2a25a4e00541 506 for(idx = 0; idx < 10; idx++)
j3 4:2a25a4e00541 507 {
j3 4:2a25a4e00541 508 term.printf("AII 20mA input cal...\n");
j3 4:2a25a4e00541 509 wait(1.0);
j3 4:2a25a4e00541 510 }
j3 2:0c0994f70fd2 511 pixi.single_ended_adc_read(MAX11300::PORT12, aii_20mA);
j3 2:0c0994f70fd2 512
j3 8:8e36fe48b351 513 calData[3] = aii_20mA;
j3 2:0c0994f70fd2 514
j3 8:8e36fe48b351 515
j3 8:8e36fe48b351 516 bool rtn_val = false;
j3 8:8e36fe48b351 517
j3 8:8e36fe48b351 518 //Write cal data to eeprom
j3 8:8e36fe48b351 519 OneWireMaster::CmdResult result = owm.OWReset();
j3 8:8e36fe48b351 520 MultidropRomIterator selector(owm);
j3 8:8e36fe48b351 521 SearchState search_state;
j3 8:8e36fe48b351 522
j3 8:8e36fe48b351 523 DS2431 eeprom(selector);
j3 4:2a25a4e00541 524
j3 8:8e36fe48b351 525 search_state.findFamily(0x2D);
j3 8:8e36fe48b351 526 result = OWNext(owm, search_state);
j3 8:8e36fe48b351 527 if(result == OneWireMaster::Success)
j3 8:8e36fe48b351 528 {
j3 8:8e36fe48b351 529 eeprom.setRomId(search_state.romId);
j3 10:5c9242143a30 530 DS2431::Scratchpad scratchPadBuf = {'C','a','l','T','r','u','e','!'};
j3 10:5c9242143a30 531 OneWireSlave::CmdResult slaveResult = eeprom.writeMemory(0, scratchPadBuf);
j3 8:8e36fe48b351 532 if(slaveResult == OneWireSlave::Success)
j3 8:8e36fe48b351 533 {
j3 8:8e36fe48b351 534 //cal data stored MSB first;
j3 10:5c9242143a30 535 scratchPadBuf[0] = ((aio_4mA >> 8) & 0xFF);
j3 10:5c9242143a30 536 scratchPadBuf[1] = (aio_4mA & 0xFF);
j3 10:5c9242143a30 537 scratchPadBuf[2] = ((aio_20mA >> 8) & 0xFF);
j3 10:5c9242143a30 538 scratchPadBuf[3] = (aio_20mA & 0xFF);
j3 10:5c9242143a30 539 scratchPadBuf[4] = ((aii_4mA >> 8) & 0xFF);
j3 10:5c9242143a30 540 scratchPadBuf[5] = (aii_4mA & 0xFF);
j3 10:5c9242143a30 541 scratchPadBuf[6] = ((aii_20mA >> 8) & 0xFF);
j3 10:5c9242143a30 542 scratchPadBuf[7] = (aii_20mA & 0xFF);
j3 8:8e36fe48b351 543
j3 10:5c9242143a30 544 slaveResult = eeprom.writeMemory(8, scratchPadBuf);
j3 8:8e36fe48b351 545 if(slaveResult == OneWireSlave::Success)
j3 8:8e36fe48b351 546 {
j3 8:8e36fe48b351 547 rtn_val = true;
j3 8:8e36fe48b351 548 term.printf("\nCal done.\n\n");
j3 8:8e36fe48b351 549 wait(1.0);
j3 8:8e36fe48b351 550 }
j3 8:8e36fe48b351 551 else
j3 8:8e36fe48b351 552 {
j3 8:8e36fe48b351 553 term.printf("Failed to write cal data.\n\n");
j3 8:8e36fe48b351 554 }
j3 8:8e36fe48b351 555 }
j3 8:8e36fe48b351 556 else
j3 8:8e36fe48b351 557 {
j3 8:8e36fe48b351 558 term.printf("Failed to write cal message.\n\n");
j3 8:8e36fe48b351 559 }
j3 8:8e36fe48b351 560 }
j3 8:8e36fe48b351 561
j3 8:8e36fe48b351 562 return rtn_val;
j3 2:0c0994f70fd2 563 }
j3 2:0c0994f70fd2 564
j3 5:2fe6dd435618 565 //*********************************************************************
j3 5:2fe6dd435618 566 void DS1920Menu(Terminal & term, const RomId & romId, MultidropRomIterator & selector)
j3 5:2fe6dd435618 567 {
j3 5:2fe6dd435618 568 char userEntry = '0';
j3 5:2fe6dd435618 569 uint8_t th, tl, idx;
j3 5:2fe6dd435618 570 uint8_t scratchPadBuff[8];
j3 5:2fe6dd435618 571 float temperature;
j3 5:2fe6dd435618 572
j3 5:2fe6dd435618 573 DS1920 tempIbutton(selector);
j3 5:2fe6dd435618 574 DS1920::CmdResult result = DS1920::OpFailure;
j3 5:2fe6dd435618 575 tempIbutton.setRomId(romId);
j3 5:2fe6dd435618 576
j3 5:2fe6dd435618 577 while(userEntry != '7')
j3 5:2fe6dd435618 578 {
j3 5:2fe6dd435618 579 term.printf("\nDS1920 Menu Options\n");
j3 5:2fe6dd435618 580 term.printf("\n%t1. Write ScratchPad");
j3 5:2fe6dd435618 581 term.printf("\n%t2. Read Scratchpad");
j3 5:2fe6dd435618 582 term.printf("\n%t3. Copy Scratchpad");
j3 5:2fe6dd435618 583 term.printf("\n%t4. Convert Temperature");
j3 5:2fe6dd435618 584 term.printf("\n%t5. Recall EEPROM");
j3 5:2fe6dd435618 585 term.printf("\n%t6. Clear Screen");
j3 5:2fe6dd435618 586 term.printf("\n%t7. Quit");
j3 5:2fe6dd435618 587
j3 5:2fe6dd435618 588 userEntry = term.get_char("\nPlease select an option above: ", '1', '7');
j3 5:2fe6dd435618 589
j3 5:2fe6dd435618 590 switch(userEntry)
j3 5:2fe6dd435618 591 {
j3 5:2fe6dd435618 592 case '1':
j3 5:2fe6dd435618 593 th = term.get_int32("\nPlease enter upper temperature threshold, integer values only: ", 0, 100);
j3 5:2fe6dd435618 594 tl = term.get_int32("\nPlease enter lower temperature threshold, integer values only: ", -55, 0);
j3 5:2fe6dd435618 595
j3 5:2fe6dd435618 596 result = tempIbutton.writeScratchPad(th, tl);
j3 5:2fe6dd435618 597 if(result == DS1920::Success)
j3 5:2fe6dd435618 598 {
j3 5:2fe6dd435618 599 term.printf("\nWrite Scratchpad Success\n");
j3 5:2fe6dd435618 600 }
j3 5:2fe6dd435618 601 else
j3 5:2fe6dd435618 602 {
j3 5:2fe6dd435618 603 term.printf("\nWrite Scratchpad Fail\n");
j3 5:2fe6dd435618 604 }
j3 5:2fe6dd435618 605
j3 5:2fe6dd435618 606 break;
j3 5:2fe6dd435618 607
j3 5:2fe6dd435618 608 case '2':
j3 5:2fe6dd435618 609
j3 5:2fe6dd435618 610 result = tempIbutton.readScratchPad(scratchPadBuff);
j3 5:2fe6dd435618 611 if(result == DS1920::Success)
j3 5:2fe6dd435618 612 {
j3 5:2fe6dd435618 613 term.printf("\nRead Scratchpad Success\n");
j3 5:2fe6dd435618 614 term.printf("\nScratchpad = ");
j3 5:2fe6dd435618 615 for(idx = 0; idx < 8; idx++)
j3 5:2fe6dd435618 616 {
j3 5:2fe6dd435618 617 if(scratchPadBuff[idx] < 16)
j3 5:2fe6dd435618 618 {
j3 5:2fe6dd435618 619 term.printf("0x0%x ", scratchPadBuff[idx]);
j3 5:2fe6dd435618 620 }
j3 5:2fe6dd435618 621 else
j3 5:2fe6dd435618 622 {
j3 5:2fe6dd435618 623 term.printf("0x%2x ", scratchPadBuff[idx]);
j3 5:2fe6dd435618 624 }
j3 5:2fe6dd435618 625 }
j3 5:2fe6dd435618 626 term.printf("\n");
j3 5:2fe6dd435618 627
j3 5:2fe6dd435618 628 }
j3 5:2fe6dd435618 629 else
j3 5:2fe6dd435618 630 {
j3 5:2fe6dd435618 631 term.printf("\nRead Scratchpad Fail\n");
j3 5:2fe6dd435618 632 }
j3 5:2fe6dd435618 633
j3 5:2fe6dd435618 634 break;
j3 5:2fe6dd435618 635
j3 5:2fe6dd435618 636 case '3':
j3 5:2fe6dd435618 637
j3 5:2fe6dd435618 638 result = tempIbutton.copyScratchPad();
j3 5:2fe6dd435618 639 if(result == DS1920::Success)
j3 5:2fe6dd435618 640 {
j3 5:2fe6dd435618 641 term.printf("\nCopy Scratchpad Success\n");
j3 5:2fe6dd435618 642 }
j3 5:2fe6dd435618 643 else
j3 5:2fe6dd435618 644 {
j3 5:2fe6dd435618 645 term.printf("\nCopy Scratchpad Fail\n");
j3 5:2fe6dd435618 646 }
j3 5:2fe6dd435618 647
j3 5:2fe6dd435618 648 break;
j3 5:2fe6dd435618 649
j3 5:2fe6dd435618 650 case '4':
j3 5:2fe6dd435618 651
j3 5:2fe6dd435618 652 result = tempIbutton.convertTemperature(temperature);
j3 5:2fe6dd435618 653 if(result == DS1920::Success)
j3 5:2fe6dd435618 654 {
j3 5:2fe6dd435618 655 term.printf("\nConvert Temperature Success\n");
j3 5:2fe6dd435618 656 term.printf("\nTemperature = %.1f", temperature);
j3 5:2fe6dd435618 657 }
j3 5:2fe6dd435618 658 else
j3 5:2fe6dd435618 659 {
j3 5:2fe6dd435618 660 term.printf("\nConvert Temperature Fail\n");
j3 5:2fe6dd435618 661 }
j3 5:2fe6dd435618 662
j3 5:2fe6dd435618 663 break;
j3 5:2fe6dd435618 664
j3 5:2fe6dd435618 665 case '5':
j3 5:2fe6dd435618 666
j3 5:2fe6dd435618 667 result = tempIbutton.recallEEPROM();
j3 5:2fe6dd435618 668 if(result == DS1920::Success)
j3 5:2fe6dd435618 669 {
j3 5:2fe6dd435618 670 term.printf("\nRecall EEPROM Success\n");
j3 5:2fe6dd435618 671 }
j3 5:2fe6dd435618 672 else
j3 5:2fe6dd435618 673 {
j3 5:2fe6dd435618 674 term.printf("\nRecall EEPROM Fail\n");
j3 5:2fe6dd435618 675 }
j3 5:2fe6dd435618 676
j3 5:2fe6dd435618 677 break;
j3 5:2fe6dd435618 678
j3 5:2fe6dd435618 679 case '6':
j3 5:2fe6dd435618 680 term.cls();
j3 5:2fe6dd435618 681 term.home();
j3 5:2fe6dd435618 682 break;
j3 5:2fe6dd435618 683
j3 5:2fe6dd435618 684 case '7':
j3 5:2fe6dd435618 685 term.printf("\nLeaving DS1920 Menu Options\n");
j3 5:2fe6dd435618 686 break;
j3 5:2fe6dd435618 687
j3 5:2fe6dd435618 688 default:
j3 5:2fe6dd435618 689 mbed_die();
j3 5:2fe6dd435618 690 break;
j3 5:2fe6dd435618 691 }
j3 5:2fe6dd435618 692 }
j3 5:2fe6dd435618 693 }
j3 8:8e36fe48b351 694
j3 8:8e36fe48b351 695 //*********************************************************************
j3 8:8e36fe48b351 696 bool check_420_cal(Terminal & term, DS2484 & owm, uint16_t *calData)
j3 8:8e36fe48b351 697 {
j3 8:8e36fe48b351 698 OneWireMaster::CmdResult result = owm.OWReset();
j3 8:8e36fe48b351 699 MultidropRomIterator selector(owm);
j3 8:8e36fe48b351 700 SearchState search_state;
j3 8:8e36fe48b351 701
j3 8:8e36fe48b351 702 DS2431 eeprom(selector);
j3 8:8e36fe48b351 703
j3 8:8e36fe48b351 704 bool rtn_val = false;
j3 8:8e36fe48b351 705
j3 8:8e36fe48b351 706 term.printf("\n\nPlease remove any 1-Wire devices connected to bus on start up and calibrartion of 4-20mA loop.\n\n");
j3 8:8e36fe48b351 707 wait(2.5);
j3 8:8e36fe48b351 708
j3 8:8e36fe48b351 709 search_state.findFamily(0x2D);
j3 8:8e36fe48b351 710 result = OWNext(owm, search_state);
j3 8:8e36fe48b351 711 if(result == OneWireMaster::Success)
j3 8:8e36fe48b351 712 {
j3 8:8e36fe48b351 713 eeprom.setRomId(search_state.romId);
j3 8:8e36fe48b351 714 uint8_t temp_data[8];
j3 8:8e36fe48b351 715
j3 10:5c9242143a30 716 OneWireSlave::CmdResult slaveResult = eeprom.readMemory(0, 8, temp_data);
j3 8:8e36fe48b351 717
j3 8:8e36fe48b351 718 if((temp_data[0] == 'C') && (slaveResult == OneWireSlave::Success))
j3 8:8e36fe48b351 719 {
j3 10:5c9242143a30 720 slaveResult = eeprom.readMemory(8, 8, temp_data);
j3 8:8e36fe48b351 721 if(slaveResult == OneWireSlave::Success)
j3 8:8e36fe48b351 722 {
j3 8:8e36fe48b351 723 calData[0] = ((temp_data[0] << 8) | temp_data[1]);
j3 8:8e36fe48b351 724 calData[1] = ((temp_data[2] << 8) | temp_data[3]);
j3 8:8e36fe48b351 725 calData[2] = ((temp_data[4] << 8) | temp_data[5]);
j3 8:8e36fe48b351 726 calData[3] = ((temp_data[6] << 8) | temp_data[7]);
j3 8:8e36fe48b351 727
j3 8:8e36fe48b351 728 rtn_val = true;
j3 8:8e36fe48b351 729 }
j3 8:8e36fe48b351 730 else
j3 8:8e36fe48b351 731 {
j3 8:8e36fe48b351 732 term.printf("Failed to read row 1 of EEPROM\n\n");
j3 8:8e36fe48b351 733 }
j3 8:8e36fe48b351 734 }
j3 8:8e36fe48b351 735 else
j3 8:8e36fe48b351 736 {
j3 8:8e36fe48b351 737 if(slaveResult == OneWireSlave::Success)
j3 8:8e36fe48b351 738 {
j3 8:8e36fe48b351 739 term.printf("No cal data stored, please calibrate 4-20mA loop\n\n");
j3 8:8e36fe48b351 740 }
j3 8:8e36fe48b351 741 else
j3 8:8e36fe48b351 742 {
j3 8:8e36fe48b351 743 term.printf("Failed to read row 0 of EEPROM\n\n");
j3 8:8e36fe48b351 744 }
j3 8:8e36fe48b351 745 }
j3 8:8e36fe48b351 746 }
j3 8:8e36fe48b351 747
j3 8:8e36fe48b351 748 return rtn_val;
j3 8:8e36fe48b351 749 }