Simple demo for exercising the board

Dependencies:   MAX11300 MAX4822 OneWire Terminal ds3231 mbed

Committer:
j3
Date:
Mon Mar 06 23:17:57 2017 +0000
Revision:
10:5c9242143a30
Parent:
9:a5fd406b24a6
Child:
11:fe03fb61fb08
Updated ow library and made appropriate changes

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 9:a5fd406b24a6 130 Timer t;
j3 9:a5fd406b24a6 131 t.start();
j3 9:a5fd406b24a6 132
j3 0:24b8a6f0a563 133 while(user_entry != QUIT)
j3 0:24b8a6f0a563 134 {
j3 2:0c0994f70fd2 135 term.printf("1. Set RTC\n");
j3 2:0c0994f70fd2 136 term.printf("2. Get Time/Date\n");
j3 2:0c0994f70fd2 137 term.printf("3. Search OneWire bus\n");
j3 2:0c0994f70fd2 138 term.printf("4. Set non-latching relay\n");
j3 2:0c0994f70fd2 139 term.printf("5. Reset non-latching relay\n");
j3 2:0c0994f70fd2 140 term.printf("6. Set all non-latching relays\n");
j3 2:0c0994f70fd2 141 term.printf("7. Reset all non-latching relays\n");
j3 2:0c0994f70fd2 142 term.printf("8. Set latching relay\n");
j3 2:0c0994f70fd2 143 term.printf("9. Reset latching relay\n");
j3 0:24b8a6f0a563 144 term.printf("10. Set 0-10 analog out\n");
j3 0:24b8a6f0a563 145 term.printf("11. Set 4-20 out\n");
j3 0:24b8a6f0a563 146 term.printf("12. Get 4-20 in\n");
j3 2:0c0994f70fd2 147 term.printf("13. Calibrate 4-20 io\n");
j3 0:24b8a6f0a563 148 term.printf("%d. Clear Screen\n", (QUIT - 1));
j3 0:24b8a6f0a563 149 term.printf("%d. Quit\n\n", QUIT);
j3 0:24b8a6f0a563 150
j3 0:24b8a6f0a563 151 user_entry = term.get_int32("Please select an option above: ", 1, QUIT);
j3 0:24b8a6f0a563 152
j3 0:24b8a6f0a563 153 //get non-latching relay
j3 0:24b8a6f0a563 154 if((user_entry == 4) || (user_entry == 5))
j3 0:24b8a6f0a563 155 {
j3 0:24b8a6f0a563 156 relay = term.get_int32("Select a relay from 1 to 8: ", 1, 8);
j3 0:24b8a6f0a563 157 }
j3 0:24b8a6f0a563 158
j3 0:24b8a6f0a563 159 //get latching relay
j3 0:24b8a6f0a563 160 if((user_entry == 8) || (user_entry == 9))
j3 0:24b8a6f0a563 161 {
j3 0:24b8a6f0a563 162 relay = (8 + term.get_int32("Select a relay from 1 to 3: ", 1, 3));
j3 0:24b8a6f0a563 163 }
j3 0:24b8a6f0a563 164
j3 0:24b8a6f0a563 165 switch(user_entry)
j3 0:24b8a6f0a563 166 {
j3 0:24b8a6f0a563 167 case 1:
j3 0:24b8a6f0a563 168 set_rtc(term, rtc);
j3 0:24b8a6f0a563 169 break;
j3 0:24b8a6f0a563 170
j3 0:24b8a6f0a563 171 case 2:
j3 0:24b8a6f0a563 172 get_time_date(term, rtc);
j3 0:24b8a6f0a563 173 break;
j3 0:24b8a6f0a563 174
j3 0:24b8a6f0a563 175 case 3:
j3 0:24b8a6f0a563 176 search_ow_bus(term, owm);
j3 0:24b8a6f0a563 177 break;
j3 0:24b8a6f0a563 178
j3 0:24b8a6f0a563 179 case 4:
j3 1:03c04017a728 180 rly_drvr_result = rly_drvr.set_relay(static_cast<MAX4822::RelayChannel>(relay));
j3 9:a5fd406b24a6 181 t.reset();
j3 1:03c04017a728 182 if(rly_drvr_result != MAX4822::Success)
j3 1:03c04017a728 183 {
j3 1:03c04017a728 184 term.printf("Failed to set relay\n");
j3 1:03c04017a728 185 }
j3 9:a5fd406b24a6 186 else
j3 9:a5fd406b24a6 187 {
j3 9:a5fd406b24a6 188 while(t.read_ms() < 2400);
j3 9:a5fd406b24a6 189
j3 9:a5fd406b24a6 190 rly_drvr_result = rly_drvr.reset_relay(static_cast<MAX4822::RelayChannel>(relay));
j3 9:a5fd406b24a6 191 if(rly_drvr_result != MAX4822::Success)
j3 9:a5fd406b24a6 192 {
j3 9:a5fd406b24a6 193 term.printf("Failed to reset relay\n");
j3 9:a5fd406b24a6 194 }
j3 9:a5fd406b24a6 195 }
j3 0:24b8a6f0a563 196 break;
j3 0:24b8a6f0a563 197
j3 0:24b8a6f0a563 198 case 5:
j3 1:03c04017a728 199 rly_drvr_result = rly_drvr.reset_relay(static_cast<MAX4822::RelayChannel>(relay));
j3 1:03c04017a728 200 if(rly_drvr_result != MAX4822::Success)
j3 1:03c04017a728 201 {
j3 1:03c04017a728 202 term.printf("Failed to reset relay\n");
j3 1:03c04017a728 203 }
j3 0:24b8a6f0a563 204 break;
j3 0:24b8a6f0a563 205
j3 0:24b8a6f0a563 206 case 6:
j3 0:24b8a6f0a563 207 rly_drvr.set_all_relays(rly_drvr_set);
j3 0:24b8a6f0a563 208 term.printf("\n");
j3 0:24b8a6f0a563 209 break;
j3 0:24b8a6f0a563 210
j3 0:24b8a6f0a563 211 case 7:
j3 0:24b8a6f0a563 212 rly_drvr.reset_all_relays(rly_drvr_reset);
j3 0:24b8a6f0a563 213 term.printf("\n");
j3 0:24b8a6f0a563 214 break;
j3 0:24b8a6f0a563 215
j3 0:24b8a6f0a563 216 case 8:
j3 1:03c04017a728 217 pixi_result = pixi.gpio_write(static_cast<MAX11300::MAX11300_Ports>(relay), 1);
j3 1:03c04017a728 218 if(pixi_result != MAX11300::Success)
j3 1:03c04017a728 219 {
j3 1:03c04017a728 220 term.printf("Failed to set relay\n");
j3 1:03c04017a728 221 }
j3 0:24b8a6f0a563 222 break;
j3 0:24b8a6f0a563 223
j3 0:24b8a6f0a563 224 case 9:
j3 1:03c04017a728 225 pixi_result = pixi.gpio_write(static_cast<MAX11300::MAX11300_Ports>(relay), 0);
j3 1:03c04017a728 226 if(pixi_result != MAX11300::Success)
j3 1:03c04017a728 227 {
j3 1:03c04017a728 228 term.printf("Failed to reset relay\n");
j3 1:03c04017a728 229 }
j3 0:24b8a6f0a563 230 break;
j3 0:24b8a6f0a563 231
j3 0:24b8a6f0a563 232 case 10:
j3 2:0c0994f70fd2 233 analog_out_ch = (term.get_int32("Please select a 0-10V output; 1-8: ", 1, 8) - 1);
j3 2:0c0994f70fd2 234 avo_volts = term.get_float("Please enter a voltage from 0.0 to 10.0 volts: ", -0.1, 10.1);
j3 2:0c0994f70fd2 235 analog_val = static_cast<uint16_t>((avo_volts/10.0) * 4095);
j3 1:03c04017a728 236
j3 5:2fe6dd435618 237 term.printf("DAC Code = %d\n", analog_val);
j3 5:2fe6dd435618 238
j3 2:0c0994f70fd2 239 pixi_result = pixi.single_ended_dac_write(static_cast<MAX11300::MAX11300_Ports>(analog_out_ch), analog_val);
j3 1:03c04017a728 240 if(pixi_result != MAX11300::Success)
j3 1:03c04017a728 241 {
j3 1:03c04017a728 242 term.printf("Failed to set 0-10 out\n");
j3 1:03c04017a728 243 }
j3 0:24b8a6f0a563 244 break;
j3 0:24b8a6f0a563 245
j3 0:24b8a6f0a563 246 case 11:
j3 8:8e36fe48b351 247 if(currentLoopCal)
j3 1:03c04017a728 248 {
j3 8:8e36fe48b351 249 aio_mA = term.get_float("Please enter a current from 4.0 to 20.0 mA: ", 3.9, 20.1);
j3 8:8e36fe48b351 250 analog_val = static_cast<uint16_t>((aio_slope * aio_mA) + aio_offset);
j3 8:8e36fe48b351 251
j3 8:8e36fe48b351 252 pixi_result = pixi.single_ended_dac_write(MAX11300::PORT8, analog_val);
j3 8:8e36fe48b351 253 if(pixi_result != MAX11300::Success)
j3 8:8e36fe48b351 254 {
j3 8:8e36fe48b351 255 term.printf("Failed to set 4-20 out\n");
j3 8:8e36fe48b351 256 }
j3 8:8e36fe48b351 257 }
j3 8:8e36fe48b351 258 else
j3 8:8e36fe48b351 259 {
j3 8:8e36fe48b351 260 term.printf("Please calibrate 4-20mA loop first, option 13.\n");
j3 1:03c04017a728 261 }
j3 0:24b8a6f0a563 262 break;
j3 0:24b8a6f0a563 263
j3 0:24b8a6f0a563 264 case 12:
j3 8:8e36fe48b351 265 if(currentLoopCal)
j3 1:03c04017a728 266 {
j3 8:8e36fe48b351 267 pixi_result = pixi.single_ended_adc_read(MAX11300::PORT12, analog_val);
j3 8:8e36fe48b351 268 aii_mA = ((aii_slope*analog_val) + aii_offset);
j3 8:8e36fe48b351 269 if(pixi_result == MAX11300::Success)
j3 8:8e36fe48b351 270 {
j3 8:8e36fe48b351 271 term.printf("4-20 in = %.2fmA\n", aii_mA);
j3 8:8e36fe48b351 272 }
j3 8:8e36fe48b351 273 else
j3 8:8e36fe48b351 274 {
j3 8:8e36fe48b351 275 term.printf("Failed to read 4-20 in\n");
j3 8:8e36fe48b351 276 }
j3 1:03c04017a728 277 }
j3 1:03c04017a728 278 else
j3 1:03c04017a728 279 {
j3 8:8e36fe48b351 280 term.printf("Please calibrate 4-20mA loop first, option 13.\n");
j3 1:03c04017a728 281 }
j3 0:24b8a6f0a563 282 break;
j3 0:24b8a6f0a563 283
j3 2:0c0994f70fd2 284 case 13:
j3 8:8e36fe48b351 285 if(calibrate_420_io(term, pixi, owm, calData, currentLoopCal))
j3 8:8e36fe48b351 286 {
j3 8:8e36fe48b351 287 aio_slope = (((calData[1]*1.0) - (calData[0]*1.0))/16.0);
j3 8:8e36fe48b351 288 aio_offset = ((-1.0*aio_slope*4.0) + calData[0]);
j3 8:8e36fe48b351 289
j3 8:8e36fe48b351 290 aii_slope = (16.0/((calData[3]*1.0) - (calData[2]*1.0)));
j3 8:8e36fe48b351 291 aii_offset = ((-1.0*aii_slope*calData[2]) + 4.0);
j3 8:8e36fe48b351 292
j3 8:8e36fe48b351 293 currentLoopCal = true;
j3 8:8e36fe48b351 294
j3 8:8e36fe48b351 295 term.printf("Calibration data saved to 1-Wire EEPROM\n");
j3 8:8e36fe48b351 296 }
j3 2:0c0994f70fd2 297 break;
j3 2:0c0994f70fd2 298
j3 0:24b8a6f0a563 299 case (QUIT - 1):
j3 0:24b8a6f0a563 300 term.cls();
j3 0:24b8a6f0a563 301 term.home();
j3 0:24b8a6f0a563 302 break;
j3 0:24b8a6f0a563 303
j3 0:24b8a6f0a563 304 case QUIT:
j3 0:24b8a6f0a563 305 term.printf("\nEnding Program\n");
j3 0:24b8a6f0a563 306 break;
j3 0:24b8a6f0a563 307
j3 0:24b8a6f0a563 308 default:
j3 0:24b8a6f0a563 309 mbed_die();
j3 0:24b8a6f0a563 310 break;
j3 0:24b8a6f0a563 311 }
j3 0:24b8a6f0a563 312 }
j3 0:24b8a6f0a563 313 }
j3 0:24b8a6f0a563 314
j3 0:24b8a6f0a563 315 //*********************************************************************
j3 0:24b8a6f0a563 316 void set_rtc(Terminal & term, Ds3231 & rtc)
j3 0:24b8a6f0a563 317 {
j3 0:24b8a6f0a563 318 //default, use bit masks in ds3231.h for desired operation
j3 0:24b8a6f0a563 319 ds3231_cntl_stat_t rtc_control_status = {0,0};
j3 0:24b8a6f0a563 320 ds3231_time_t rtc_time;
j3 0:24b8a6f0a563 321 ds3231_calendar_t rtc_calendar;
j3 0:24b8a6f0a563 322
j3 0:24b8a6f0a563 323 rtc.set_cntl_stat_reg(rtc_control_status);
j3 0:24b8a6f0a563 324
j3 0:24b8a6f0a563 325 //get day from user
j3 0:24b8a6f0a563 326 rtc_calendar.day = term.get_int32("\nPlease enter day of week, 1 for Sunday (1-7): ", 1, 7);
j3 0:24b8a6f0a563 327
j3 0:24b8a6f0a563 328 //get day of month from user
j3 0:24b8a6f0a563 329 rtc_calendar.date = term.get_int32("\nPlease enter day of month (1-31): ", 1, 31);
j3 0:24b8a6f0a563 330
j3 0:24b8a6f0a563 331 //get month from user
j3 0:24b8a6f0a563 332 rtc_calendar.month = term.get_int32("\nPlease enter the month, 1 for January (1-12): ", 1, 12);
j3 0:24b8a6f0a563 333
j3 0:24b8a6f0a563 334 //get year from user
j3 0:24b8a6f0a563 335 rtc_calendar.year = term.get_int32("\nPlease enter the year (0-99): ", 0, 99);
j3 0:24b8a6f0a563 336
j3 0:24b8a6f0a563 337 //Get time mode
j3 0:24b8a6f0a563 338 rtc_time.mode = term.get_int32("\nWhat time mode? 1 for 12hr 0 for 24hr: ", 0, 1);
j3 0:24b8a6f0a563 339
j3 0:24b8a6f0a563 340 if(rtc_time.mode)
j3 0:24b8a6f0a563 341 {
j3 0:24b8a6f0a563 342 //Get AM/PM status
j3 0:24b8a6f0a563 343 rtc_time.am_pm = term.get_int32("\nIs it AM or PM? 0 for AM 1 for PM: ", 0, 1);
j3 0:24b8a6f0a563 344 //Get hour from user
j3 0:24b8a6f0a563 345 rtc_time.hours = term.get_int32("\nPlease enter the hour (1-12): ", 1, 12);
j3 0:24b8a6f0a563 346 }
j3 0:24b8a6f0a563 347 else
j3 0:24b8a6f0a563 348 {
j3 0:24b8a6f0a563 349 //Get hour from user
j3 0:24b8a6f0a563 350 rtc_time.hours = term.get_int32("\nPlease enter the hour (0-23): ", 0, 23);
j3 0:24b8a6f0a563 351 }
j3 0:24b8a6f0a563 352
j3 0:24b8a6f0a563 353 //Get minutes from user
j3 0:24b8a6f0a563 354 rtc_time.minutes = term.get_int32("\nPlease enter the minute (0-59): ", 0, 59);
j3 0:24b8a6f0a563 355
j3 0:24b8a6f0a563 356
j3 0:24b8a6f0a563 357 //Get seconds from user
j3 0:24b8a6f0a563 358 rtc_time.seconds = term.get_int32("\nPlease enter the second (0-59): ", 0, 59);
j3 0:24b8a6f0a563 359
j3 0:24b8a6f0a563 360 term.printf("\n");
j3 0:24b8a6f0a563 361
j3 0:24b8a6f0a563 362 rtc.set_time(rtc_time);
j3 0:24b8a6f0a563 363 rtc.set_calendar(rtc_calendar);
j3 0:24b8a6f0a563 364 }
j3 0:24b8a6f0a563 365
j3 0:24b8a6f0a563 366 //*********************************************************************
j3 0:24b8a6f0a563 367 void get_time_date(Terminal & term, Ds3231 & rtc)
j3 0:24b8a6f0a563 368 {
j3 0:24b8a6f0a563 369 time_t epoch_time;
j3 0:24b8a6f0a563 370
j3 0:24b8a6f0a563 371 epoch_time = rtc.get_epoch();
j3 0:24b8a6f0a563 372 term.printf("\n%s\n", ctime(&epoch_time));
j3 0:24b8a6f0a563 373 }
j3 0:24b8a6f0a563 374
j3 0:24b8a6f0a563 375 //*********************************************************************
j3 0:24b8a6f0a563 376 void search_ow_bus(Terminal & term, DS2484 & owm)
j3 0:24b8a6f0a563 377 {
j3 0:24b8a6f0a563 378 OneWireMaster::CmdResult result = owm.OWReset();
j3 5:2fe6dd435618 379 MultidropRomIterator selector(owm);
j3 0:24b8a6f0a563 380 SearchState search_state;
j3 0:24b8a6f0a563 381
j3 0:24b8a6f0a563 382 if(result == OneWireMaster::Success)
j3 0:24b8a6f0a563 383 {
j3 0:24b8a6f0a563 384 term.printf("\nOWReset success, starting search\n");
j3 0:24b8a6f0a563 385
j3 0:24b8a6f0a563 386 result = OWFirst(owm, search_state);
j3 0:24b8a6f0a563 387 if(result == OneWireMaster::Success)
j3 0:24b8a6f0a563 388 {
j3 0:24b8a6f0a563 389 while(result == OneWireMaster::Success)
j3 0:24b8a6f0a563 390 {
j3 0:24b8a6f0a563 391 //print current devices rom id
j3 0:24b8a6f0a563 392 print_rom_id(term, search_state.romId);
j3 0:24b8a6f0a563 393
j3 5:2fe6dd435618 394 if(search_state.romId.familyCode() == 0x10)
j3 6:18a831a757b5 395 {
j3 6:18a831a757b5 396 DS1920Menu(term, search_state.romId, selector);
j3 6:18a831a757b5 397 }
j3 5:2fe6dd435618 398
j3 0:24b8a6f0a563 399 //find the next device if any
j3 0:24b8a6f0a563 400 result = OWNext(owm, search_state);
j3 0:24b8a6f0a563 401 }
j3 0:24b8a6f0a563 402 term.printf("\n");
j3 0:24b8a6f0a563 403 }
j3 0:24b8a6f0a563 404 else
j3 0:24b8a6f0a563 405 {
j3 0:24b8a6f0a563 406 term.printf("\nSearch failed\n");
j3 0:24b8a6f0a563 407 term.printf("\nError code = %d\n", result);
j3 0:24b8a6f0a563 408 }
j3 0:24b8a6f0a563 409 }
j3 0:24b8a6f0a563 410 else
j3 0:24b8a6f0a563 411 {
j3 0:24b8a6f0a563 412 term.printf("\nFailed to find any 1-wire devices on bus\n");
j3 0:24b8a6f0a563 413 term.printf("\nError code = %d\n", result);
j3 0:24b8a6f0a563 414 }
j3 0:24b8a6f0a563 415 }
j3 0:24b8a6f0a563 416
j3 0:24b8a6f0a563 417 //*********************************************************************
j3 0:24b8a6f0a563 418 void print_rom_id(Terminal & term, RomId & romId)
j3 0:24b8a6f0a563 419 {
j3 0:24b8a6f0a563 420 //print the rom number
j3 0:24b8a6f0a563 421 term.printf("\n");
j3 10:5c9242143a30 422 int8_t idx = 7;
j3 0:24b8a6f0a563 423 do
j3 0:24b8a6f0a563 424 {
j3 10:5c9242143a30 425 term.printf("0x%02x ", romId.buffer[idx--]);
j3 0:24b8a6f0a563 426 }
j3 0:24b8a6f0a563 427 while(idx >= 0);
j3 0:24b8a6f0a563 428 term.printf("\n");
j3 0:24b8a6f0a563 429 }
j3 2:0c0994f70fd2 430
j3 2:0c0994f70fd2 431 //*********************************************************************
j3 8:8e36fe48b351 432 bool calibrate_420_io(Terminal & term, MAX11300 & pixi, DS2484 & owm, uint16_t *calData, bool loopAlreadyCal)
j3 2:0c0994f70fd2 433 {
j3 2:0c0994f70fd2 434 char user_entry;
j3 2:0c0994f70fd2 435 //initial vals for aio determined imperically on one pcb
j3 2:0c0994f70fd2 436 static uint16_t aio_4mA = 518;
j3 2:0c0994f70fd2 437 static uint16_t aio_20mA = 2592;
j3 8:8e36fe48b351 438
j3 8:8e36fe48b351 439 if(loopAlreadyCal)
j3 8:8e36fe48b351 440 {
j3 8:8e36fe48b351 441 aio_4mA = calData[0];
j3 8:8e36fe48b351 442 aio_20mA = calData[1];
j3 8:8e36fe48b351 443 }
j3 2:0c0994f70fd2 444 uint16_t aii_4mA, aii_20mA;
j3 2:0c0994f70fd2 445
j3 4:2a25a4e00541 446 term.cls();
j3 4:2a25a4e00541 447 term.home();
j3 4:2a25a4e00541 448
j3 2:0c0994f70fd2 449 //cal aio
j3 2:0c0994f70fd2 450 term.printf("\nConnect DMM in series with AIO and AII.\n");
j3 4:2a25a4e00541 451 term.printf("AIO----(DMMM)----AII\n\n");
j3 4:2a25a4e00541 452 term.printf("Use 'i' and 'd' keys to increase/decrease measurement to calibration value.\n\n");
j3 4:2a25a4e00541 453 term.printf("Setting AIO calibration val to 4mA, enter 'q' when DMM measurement = 4mA.\n\n");
j3 2:0c0994f70fd2 454
j3 2:0c0994f70fd2 455 do
j3 2:0c0994f70fd2 456 {
j3 10:5c9242143a30 457 printf("aio_4mA = %d\n", aio_4mA);
j3 2:0c0994f70fd2 458 pixi.single_ended_dac_write(MAX11300::PORT8, aio_4mA);
j3 4:2a25a4e00541 459 user_entry = term.get_char("increase (i), decrease (d), quit (q) when DMM = 4mA: ", 'd', 'q');
j3 2:0c0994f70fd2 460
j3 2:0c0994f70fd2 461 if(user_entry == 'i')
j3 2:0c0994f70fd2 462 {
j3 2:0c0994f70fd2 463 aio_4mA++;
j3 2:0c0994f70fd2 464 }
j3 2:0c0994f70fd2 465 else if(user_entry == 'd')
j3 2:0c0994f70fd2 466 {
j3 2:0c0994f70fd2 467 aio_4mA--;
j3 2:0c0994f70fd2 468 }
j3 2:0c0994f70fd2 469 else if(user_entry == 'q')
j3 2:0c0994f70fd2 470 {
j3 4:2a25a4e00541 471 term.printf("\nSetting AIO calibration val to 20mA, enter 'q' when DMM measurement = 20mA.\n\n");
j3 2:0c0994f70fd2 472 }
j3 2:0c0994f70fd2 473 else
j3 2:0c0994f70fd2 474 {
j3 2:0c0994f70fd2 475 term.printf("Not an option, please read the instructions.\n");
j3 2:0c0994f70fd2 476 }
j3 2:0c0994f70fd2 477 }
j3 2:0c0994f70fd2 478 while(user_entry != 'q');
j3 2:0c0994f70fd2 479
j3 2:0c0994f70fd2 480 do
j3 2:0c0994f70fd2 481 {
j3 2:0c0994f70fd2 482 pixi.single_ended_dac_write(MAX11300::PORT8, aio_20mA);
j3 4:2a25a4e00541 483 user_entry = term.get_char("increase (i), decrease (d), quit (q) when DMM = 20mA: ", 'd', 'q');
j3 2:0c0994f70fd2 484
j3 2:0c0994f70fd2 485 if(user_entry == 'i')
j3 2:0c0994f70fd2 486 {
j3 2:0c0994f70fd2 487 aio_20mA++;
j3 2:0c0994f70fd2 488 }
j3 2:0c0994f70fd2 489 else if(user_entry == 'd')
j3 2:0c0994f70fd2 490 {
j3 2:0c0994f70fd2 491 aio_20mA--;
j3 2:0c0994f70fd2 492 }
j3 2:0c0994f70fd2 493 else if(user_entry == 'q')
j3 2:0c0994f70fd2 494 {
j3 4:2a25a4e00541 495 term.printf("\nExecuting AII Cal\n\n");
j3 2:0c0994f70fd2 496 }
j3 2:0c0994f70fd2 497 else
j3 2:0c0994f70fd2 498 {
j3 2:0c0994f70fd2 499 term.printf("Not an option, please read the instructions.\n");
j3 2:0c0994f70fd2 500 }
j3 2:0c0994f70fd2 501 }
j3 2:0c0994f70fd2 502 while(user_entry != 'q');
j3 2:0c0994f70fd2 503
j3 8:8e36fe48b351 504 calData[0] = aio_4mA;
j3 8:8e36fe48b351 505 calData[1] = aio_20mA;
j3 2:0c0994f70fd2 506
j3 4:2a25a4e00541 507 uint8_t idx;
j3 2:0c0994f70fd2 508 //cal aii
j3 2:0c0994f70fd2 509 pixi.single_ended_dac_write(MAX11300::PORT8, aio_4mA);
j3 4:2a25a4e00541 510 for(idx = 0; idx < 10; idx++)
j3 4:2a25a4e00541 511 {
j3 4:2a25a4e00541 512 term.printf("AII 4mA input cal...\n");
j3 4:2a25a4e00541 513 wait(1.0);
j3 4:2a25a4e00541 514 }
j3 2:0c0994f70fd2 515 pixi.single_ended_adc_read(MAX11300::PORT12, aii_4mA);
j3 4:2a25a4e00541 516
j3 8:8e36fe48b351 517 calData[2] = aii_4mA;
j3 8:8e36fe48b351 518
j3 2:0c0994f70fd2 519 pixi.single_ended_dac_write(MAX11300::PORT8, aio_20mA);
j3 4:2a25a4e00541 520 for(idx = 0; idx < 10; idx++)
j3 4:2a25a4e00541 521 {
j3 4:2a25a4e00541 522 term.printf("AII 20mA input cal...\n");
j3 4:2a25a4e00541 523 wait(1.0);
j3 4:2a25a4e00541 524 }
j3 2:0c0994f70fd2 525 pixi.single_ended_adc_read(MAX11300::PORT12, aii_20mA);
j3 2:0c0994f70fd2 526
j3 8:8e36fe48b351 527 calData[3] = aii_20mA;
j3 2:0c0994f70fd2 528
j3 8:8e36fe48b351 529
j3 8:8e36fe48b351 530 bool rtn_val = false;
j3 8:8e36fe48b351 531
j3 8:8e36fe48b351 532 //Write cal data to eeprom
j3 8:8e36fe48b351 533 OneWireMaster::CmdResult result = owm.OWReset();
j3 8:8e36fe48b351 534 MultidropRomIterator selector(owm);
j3 8:8e36fe48b351 535 SearchState search_state;
j3 8:8e36fe48b351 536
j3 8:8e36fe48b351 537 DS2431 eeprom(selector);
j3 4:2a25a4e00541 538
j3 8:8e36fe48b351 539 search_state.findFamily(0x2D);
j3 8:8e36fe48b351 540 result = OWNext(owm, search_state);
j3 8:8e36fe48b351 541 if(result == OneWireMaster::Success)
j3 8:8e36fe48b351 542 {
j3 8:8e36fe48b351 543 eeprom.setRomId(search_state.romId);
j3 10:5c9242143a30 544 DS2431::Scratchpad scratchPadBuf = {'C','a','l','T','r','u','e','!'};
j3 10:5c9242143a30 545 OneWireSlave::CmdResult slaveResult = eeprom.writeMemory(0, scratchPadBuf);
j3 8:8e36fe48b351 546 if(slaveResult == OneWireSlave::Success)
j3 8:8e36fe48b351 547 {
j3 8:8e36fe48b351 548 //cal data stored MSB first;
j3 10:5c9242143a30 549 scratchPadBuf[0] = ((aio_4mA >> 8) & 0xFF);
j3 10:5c9242143a30 550 scratchPadBuf[1] = (aio_4mA & 0xFF);
j3 10:5c9242143a30 551 scratchPadBuf[2] = ((aio_20mA >> 8) & 0xFF);
j3 10:5c9242143a30 552 scratchPadBuf[3] = (aio_20mA & 0xFF);
j3 10:5c9242143a30 553 scratchPadBuf[4] = ((aii_4mA >> 8) & 0xFF);
j3 10:5c9242143a30 554 scratchPadBuf[5] = (aii_4mA & 0xFF);
j3 10:5c9242143a30 555 scratchPadBuf[6] = ((aii_20mA >> 8) & 0xFF);
j3 10:5c9242143a30 556 scratchPadBuf[7] = (aii_20mA & 0xFF);
j3 8:8e36fe48b351 557
j3 10:5c9242143a30 558 slaveResult = eeprom.writeMemory(8, scratchPadBuf);
j3 8:8e36fe48b351 559 if(slaveResult == OneWireSlave::Success)
j3 8:8e36fe48b351 560 {
j3 8:8e36fe48b351 561 rtn_val = true;
j3 8:8e36fe48b351 562 term.printf("\nCal done.\n\n");
j3 8:8e36fe48b351 563 wait(1.0);
j3 8:8e36fe48b351 564 }
j3 8:8e36fe48b351 565 else
j3 8:8e36fe48b351 566 {
j3 8:8e36fe48b351 567 term.printf("Failed to write cal data.\n\n");
j3 8:8e36fe48b351 568 }
j3 8:8e36fe48b351 569 }
j3 8:8e36fe48b351 570 else
j3 8:8e36fe48b351 571 {
j3 8:8e36fe48b351 572 term.printf("Failed to write cal message.\n\n");
j3 8:8e36fe48b351 573 }
j3 8:8e36fe48b351 574 }
j3 8:8e36fe48b351 575
j3 8:8e36fe48b351 576 return rtn_val;
j3 2:0c0994f70fd2 577 }
j3 2:0c0994f70fd2 578
j3 5:2fe6dd435618 579 //*********************************************************************
j3 5:2fe6dd435618 580 void DS1920Menu(Terminal & term, const RomId & romId, MultidropRomIterator & selector)
j3 5:2fe6dd435618 581 {
j3 5:2fe6dd435618 582 char userEntry = '0';
j3 5:2fe6dd435618 583 uint8_t th, tl, idx;
j3 5:2fe6dd435618 584 uint8_t scratchPadBuff[8];
j3 5:2fe6dd435618 585 float temperature;
j3 5:2fe6dd435618 586
j3 5:2fe6dd435618 587 DS1920 tempIbutton(selector);
j3 5:2fe6dd435618 588 DS1920::CmdResult result = DS1920::OpFailure;
j3 5:2fe6dd435618 589 tempIbutton.setRomId(romId);
j3 5:2fe6dd435618 590
j3 5:2fe6dd435618 591 while(userEntry != '7')
j3 5:2fe6dd435618 592 {
j3 5:2fe6dd435618 593 term.printf("\nDS1920 Menu Options\n");
j3 5:2fe6dd435618 594 term.printf("\n%t1. Write ScratchPad");
j3 5:2fe6dd435618 595 term.printf("\n%t2. Read Scratchpad");
j3 5:2fe6dd435618 596 term.printf("\n%t3. Copy Scratchpad");
j3 5:2fe6dd435618 597 term.printf("\n%t4. Convert Temperature");
j3 5:2fe6dd435618 598 term.printf("\n%t5. Recall EEPROM");
j3 5:2fe6dd435618 599 term.printf("\n%t6. Clear Screen");
j3 5:2fe6dd435618 600 term.printf("\n%t7. Quit");
j3 5:2fe6dd435618 601
j3 5:2fe6dd435618 602 userEntry = term.get_char("\nPlease select an option above: ", '1', '7');
j3 5:2fe6dd435618 603
j3 5:2fe6dd435618 604 switch(userEntry)
j3 5:2fe6dd435618 605 {
j3 5:2fe6dd435618 606 case '1':
j3 5:2fe6dd435618 607 th = term.get_int32("\nPlease enter upper temperature threshold, integer values only: ", 0, 100);
j3 5:2fe6dd435618 608 tl = term.get_int32("\nPlease enter lower temperature threshold, integer values only: ", -55, 0);
j3 5:2fe6dd435618 609
j3 5:2fe6dd435618 610 result = tempIbutton.writeScratchPad(th, tl);
j3 5:2fe6dd435618 611 if(result == DS1920::Success)
j3 5:2fe6dd435618 612 {
j3 5:2fe6dd435618 613 term.printf("\nWrite Scratchpad Success\n");
j3 5:2fe6dd435618 614 }
j3 5:2fe6dd435618 615 else
j3 5:2fe6dd435618 616 {
j3 5:2fe6dd435618 617 term.printf("\nWrite Scratchpad Fail\n");
j3 5:2fe6dd435618 618 }
j3 5:2fe6dd435618 619
j3 5:2fe6dd435618 620 break;
j3 5:2fe6dd435618 621
j3 5:2fe6dd435618 622 case '2':
j3 5:2fe6dd435618 623
j3 5:2fe6dd435618 624 result = tempIbutton.readScratchPad(scratchPadBuff);
j3 5:2fe6dd435618 625 if(result == DS1920::Success)
j3 5:2fe6dd435618 626 {
j3 5:2fe6dd435618 627 term.printf("\nRead Scratchpad Success\n");
j3 5:2fe6dd435618 628 term.printf("\nScratchpad = ");
j3 5:2fe6dd435618 629 for(idx = 0; idx < 8; idx++)
j3 5:2fe6dd435618 630 {
j3 5:2fe6dd435618 631 if(scratchPadBuff[idx] < 16)
j3 5:2fe6dd435618 632 {
j3 5:2fe6dd435618 633 term.printf("0x0%x ", scratchPadBuff[idx]);
j3 5:2fe6dd435618 634 }
j3 5:2fe6dd435618 635 else
j3 5:2fe6dd435618 636 {
j3 5:2fe6dd435618 637 term.printf("0x%2x ", scratchPadBuff[idx]);
j3 5:2fe6dd435618 638 }
j3 5:2fe6dd435618 639 }
j3 5:2fe6dd435618 640 term.printf("\n");
j3 5:2fe6dd435618 641
j3 5:2fe6dd435618 642 }
j3 5:2fe6dd435618 643 else
j3 5:2fe6dd435618 644 {
j3 5:2fe6dd435618 645 term.printf("\nRead 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 '3':
j3 5:2fe6dd435618 651
j3 5:2fe6dd435618 652 result = tempIbutton.copyScratchPad();
j3 5:2fe6dd435618 653 if(result == DS1920::Success)
j3 5:2fe6dd435618 654 {
j3 5:2fe6dd435618 655 term.printf("\nCopy Scratchpad Success\n");
j3 5:2fe6dd435618 656 }
j3 5:2fe6dd435618 657 else
j3 5:2fe6dd435618 658 {
j3 5:2fe6dd435618 659 term.printf("\nCopy Scratchpad Fail\n");
j3 5:2fe6dd435618 660 }
j3 5:2fe6dd435618 661
j3 5:2fe6dd435618 662 break;
j3 5:2fe6dd435618 663
j3 5:2fe6dd435618 664 case '4':
j3 5:2fe6dd435618 665
j3 5:2fe6dd435618 666 result = tempIbutton.convertTemperature(temperature);
j3 5:2fe6dd435618 667 if(result == DS1920::Success)
j3 5:2fe6dd435618 668 {
j3 5:2fe6dd435618 669 term.printf("\nConvert Temperature Success\n");
j3 5:2fe6dd435618 670 term.printf("\nTemperature = %.1f", temperature);
j3 5:2fe6dd435618 671 }
j3 5:2fe6dd435618 672 else
j3 5:2fe6dd435618 673 {
j3 5:2fe6dd435618 674 term.printf("\nConvert Temperature Fail\n");
j3 5:2fe6dd435618 675 }
j3 5:2fe6dd435618 676
j3 5:2fe6dd435618 677 break;
j3 5:2fe6dd435618 678
j3 5:2fe6dd435618 679 case '5':
j3 5:2fe6dd435618 680
j3 5:2fe6dd435618 681 result = tempIbutton.recallEEPROM();
j3 5:2fe6dd435618 682 if(result == DS1920::Success)
j3 5:2fe6dd435618 683 {
j3 5:2fe6dd435618 684 term.printf("\nRecall EEPROM Success\n");
j3 5:2fe6dd435618 685 }
j3 5:2fe6dd435618 686 else
j3 5:2fe6dd435618 687 {
j3 5:2fe6dd435618 688 term.printf("\nRecall EEPROM Fail\n");
j3 5:2fe6dd435618 689 }
j3 5:2fe6dd435618 690
j3 5:2fe6dd435618 691 break;
j3 5:2fe6dd435618 692
j3 5:2fe6dd435618 693 case '6':
j3 5:2fe6dd435618 694 term.cls();
j3 5:2fe6dd435618 695 term.home();
j3 5:2fe6dd435618 696 break;
j3 5:2fe6dd435618 697
j3 5:2fe6dd435618 698 case '7':
j3 5:2fe6dd435618 699 term.printf("\nLeaving DS1920 Menu Options\n");
j3 5:2fe6dd435618 700 break;
j3 5:2fe6dd435618 701
j3 5:2fe6dd435618 702 default:
j3 5:2fe6dd435618 703 mbed_die();
j3 5:2fe6dd435618 704 break;
j3 5:2fe6dd435618 705 }
j3 5:2fe6dd435618 706 }
j3 5:2fe6dd435618 707 }
j3 8:8e36fe48b351 708
j3 8:8e36fe48b351 709 //*********************************************************************
j3 8:8e36fe48b351 710 bool check_420_cal(Terminal & term, DS2484 & owm, uint16_t *calData)
j3 8:8e36fe48b351 711 {
j3 8:8e36fe48b351 712 OneWireMaster::CmdResult result = owm.OWReset();
j3 8:8e36fe48b351 713 MultidropRomIterator selector(owm);
j3 8:8e36fe48b351 714 SearchState search_state;
j3 8:8e36fe48b351 715
j3 8:8e36fe48b351 716 DS2431 eeprom(selector);
j3 8:8e36fe48b351 717
j3 8:8e36fe48b351 718 bool rtn_val = false;
j3 8:8e36fe48b351 719
j3 8:8e36fe48b351 720 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 721 wait(2.5);
j3 8:8e36fe48b351 722
j3 8:8e36fe48b351 723 search_state.findFamily(0x2D);
j3 8:8e36fe48b351 724 result = OWNext(owm, search_state);
j3 8:8e36fe48b351 725 if(result == OneWireMaster::Success)
j3 8:8e36fe48b351 726 {
j3 8:8e36fe48b351 727 eeprom.setRomId(search_state.romId);
j3 8:8e36fe48b351 728 uint8_t temp_data[8];
j3 8:8e36fe48b351 729
j3 10:5c9242143a30 730 OneWireSlave::CmdResult slaveResult = eeprom.readMemory(0, 8, temp_data);
j3 8:8e36fe48b351 731
j3 8:8e36fe48b351 732 if((temp_data[0] == 'C') && (slaveResult == OneWireSlave::Success))
j3 8:8e36fe48b351 733 {
j3 10:5c9242143a30 734 slaveResult = eeprom.readMemory(8, 8, temp_data);
j3 8:8e36fe48b351 735 if(slaveResult == OneWireSlave::Success)
j3 8:8e36fe48b351 736 {
j3 8:8e36fe48b351 737 calData[0] = ((temp_data[0] << 8) | temp_data[1]);
j3 8:8e36fe48b351 738 calData[1] = ((temp_data[2] << 8) | temp_data[3]);
j3 8:8e36fe48b351 739 calData[2] = ((temp_data[4] << 8) | temp_data[5]);
j3 8:8e36fe48b351 740 calData[3] = ((temp_data[6] << 8) | temp_data[7]);
j3 8:8e36fe48b351 741
j3 8:8e36fe48b351 742 rtn_val = true;
j3 8:8e36fe48b351 743 }
j3 8:8e36fe48b351 744 else
j3 8:8e36fe48b351 745 {
j3 8:8e36fe48b351 746 term.printf("Failed to read row 1 of EEPROM\n\n");
j3 8:8e36fe48b351 747 }
j3 8:8e36fe48b351 748 }
j3 8:8e36fe48b351 749 else
j3 8:8e36fe48b351 750 {
j3 8:8e36fe48b351 751 if(slaveResult == OneWireSlave::Success)
j3 8:8e36fe48b351 752 {
j3 8:8e36fe48b351 753 term.printf("No cal data stored, please calibrate 4-20mA loop\n\n");
j3 8:8e36fe48b351 754 }
j3 8:8e36fe48b351 755 else
j3 8:8e36fe48b351 756 {
j3 8:8e36fe48b351 757 term.printf("Failed to read row 0 of EEPROM\n\n");
j3 8:8e36fe48b351 758 }
j3 8:8e36fe48b351 759 }
j3 8:8e36fe48b351 760 }
j3 8:8e36fe48b351 761
j3 8:8e36fe48b351 762 return rtn_val;
j3 8:8e36fe48b351 763 }