Maxim DS1683 Total-Elapsed -Time and Event Recorder with Alarm

Dependents:   testDS1683

Committer:
Rhyme
Date:
Wed Jan 18 23:26:24 2017 +0000
Revision:
0:7c0469e71fa2
Child:
1:8fa5400054bd
First working version.; A lot of clean up required.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Rhyme 0:7c0469e71fa2 1 #include "mbed.h"
Rhyme 0:7c0469e71fa2 2 #include "DS1683.h"
Rhyme 0:7c0469e71fa2 3
Rhyme 0:7c0469e71fa2 4 /* ETC stands for Elapsed Time Counter */
Rhyme 0:7c0469e71fa2 5
Rhyme 0:7c0469e71fa2 6 /* Command Register */
Rhyme 0:7c0469e71fa2 7 #define REG_COMMAND 0x00
Rhyme 0:7c0469e71fa2 8 /* Status Register */
Rhyme 0:7c0469e71fa2 9 #define REG_STATUS 0x01
Rhyme 0:7c0469e71fa2 10 /* Password Entry Register 0x02 - 0x05 */
Rhyme 0:7c0469e71fa2 11 #define REG_PWE 0x02
Rhyme 0:7c0469e71fa2 12 /* Event Counter Register 0x08 - 0x09 */
Rhyme 0:7c0469e71fa2 13 #define REG_EVENT 0x08
Rhyme 0:7c0469e71fa2 14 /* ETC Register */
Rhyme 0:7c0469e71fa2 15 #define REG_ETC 0x0A
Rhyme 0:7c0469e71fa2 16 /* Event Counter Alarm Limit Register 0x10 - 0x11 */
Rhyme 0:7c0469e71fa2 17 #define REG_ECAL 0x10
Rhyme 0:7c0469e71fa2 18 /* ETC Alarm Limit Register 0x12 - 0x15 */
Rhyme 0:7c0469e71fa2 19 #define REG_ETCAL 0x12
Rhyme 0:7c0469e71fa2 20 /* Configuration Register */
Rhyme 0:7c0469e71fa2 21 #define REG_CONFIG 0x16
Rhyme 0:7c0469e71fa2 22 /* Password Value 0x1A - 0x1D */
Rhyme 0:7c0469e71fa2 23 #define REG_PWV 0x1A
Rhyme 0:7c0469e71fa2 24 /* User EEPROM 0x20 - 0x2F */
Rhyme 0:7c0469e71fa2 25 #define REG_USR 0x20
Rhyme 0:7c0469e71fa2 26
Rhyme 0:7c0469e71fa2 27 /* Command Register Bits */
Rhyme 0:7c0469e71fa2 28 /* bit[7:1] Reserved */
Rhyme 0:7c0469e71fa2 29 /* bit[0] CLR_ALM write 1 to unlatch the acvie ALARM output */
Rhyme 0:7c0469e71fa2 30 // Clear Alarm Bit. This bit reads as a 0. Writing this bit to a 1
Rhyme 0:7c0469e71fa2 31 // unlatches the active ALARM output, setting the ALARM pin to
Rhyme 0:7c0469e71fa2 32 // its inactive state if the alarm condition is no longer present.
Rhyme 0:7c0469e71fa2 33 // If the alarm condition persists, the ALARM pin once again
Rhyme 0:7c0469e71fa2 34 // asserts to its active state.
Rhyme 0:7c0469e71fa2 35 #define CLR_ALM_BIT 0x01
Rhyme 0:7c0469e71fa2 36
Rhyme 0:7c0469e71fa2 37 /* Status Register Bits */
Rhyme 0:7c0469e71fa2 38 /* bit[7:3] Reserved */
Rhyme 0:7c0469e71fa2 39 /* bit[2] EVENT */
Rhyme 0:7c0469e71fa2 40 // This bit indicates the status of the EVENT pin's logic level,
Rhyme 0:7c0469e71fa2 41 // detected after the tG glitch filter time.
Rhyme 0:7c0469e71fa2 42 #define EVENT_BIT 0x04
Rhyme 0:7c0469e71fa2 43
Rhyme 0:7c0469e71fa2 44 /* bit[1] EVENT AF */
Rhyme 0:7c0469e71fa2 45 // Default value = 0. If the value in the Event Counter SRAM value is
Rhyme 0:7c0469e71fa2 46 // greater than or equal to the Event Counter Alarm Limit value,
Rhyme 0:7c0469e71fa2 47 // then this bit is automatically set to a value of 1 to indecate
Rhyme 0:7c0469e71fa2 48 // the ALARM event. When the EVENT SRAM Counter value is less than
Rhyme 0:7c0469e71fa2 49 // the Event Counter Alarm Limit, this bit automatically set to a value of 0,
Rhyme 0:7c0469e71fa2 50 // indicating that there is no EVENT alarm.
Rhyme 0:7c0469e71fa2 51 #define EVENT_AF_BIT 0x02
Rhyme 0:7c0469e71fa2 52
Rhyme 0:7c0469e71fa2 53 /* bit[0] ETC AF */
Rhyme 0:7c0469e71fa2 54 // Default value = 0. If the value in the ETC SRAM value is greater than
Rhyme 0:7c0469e71fa2 55 // or equal to the ETC Alarm Limit value, then this bit is automatically
Rhyme 0:7c0469e71fa2 56 // set to a value of 1 to indicate an ALARM event. When the ETC SRAM value
Rhyme 0:7c0469e71fa2 57 // is less than the ETC Alarm Limit, this bit automatically set to a value of 0,
Rhyme 0:7c0469e71fa2 58 // indicating that there is no ETC alarm.
Rhyme 0:7c0469e71fa2 59 #define ETC_AF_BIT 0x01
Rhyme 0:7c0469e71fa2 60
Rhyme 0:7c0469e71fa2 61 /* Configuration Register */
Rhyme 0:7c0469e71fa2 62 /* bit[7:3] Reserved */
Rhyme 0:7c0469e71fa2 63 /* bit[2] ETC ALARM EN */
Rhyme 0:7c0469e71fa2 64 // Default value = 0, which is disabled. When set to a 1,
Rhyme 0:7c0469e71fa2 65 // and if the ETC register is equal to or greater than the ETC Alarm limit,
Rhyme 0:7c0469e71fa2 66 // then this device triggers the ETC Alarm Flag (ETC AF),
Rhyme 0:7c0469e71fa2 67 // and the ALARM pin goes to its active state.
Rhyme 0:7c0469e71fa2 68 #define ETC_ALARM_EN_BIT 0x04
Rhyme 0:7c0469e71fa2 69
Rhyme 0:7c0469e71fa2 70 /* bit[1] EVENT ALARM EN */
Rhyme 0:7c0469e71fa2 71 // Default value = 0, which is disabled. When set to a 1, and if the Event
Rhyme 0:7c0469e71fa2 72 // Counter register is equal to or greater than the Event Counter Alarm limit,
Rhyme 0:7c0469e71fa2 73 // then this device triggers the Event Count Alarm Flag (EVENT AF),
Rhyme 0:7c0469e71fa2 74 // and the ALARM pin goes to its active state.
Rhyme 0:7c0469e71fa2 75 #define EVENT_ALARM_EN_BIT 0x02
Rhyme 0:7c0469e71fa2 76
Rhyme 0:7c0469e71fa2 77 /* bit[0] ALARM POL */
Rhyme 0:7c0469e71fa2 78 // Default value = 0, which sets the ALARM output active low.
Rhyme 0:7c0469e71fa2 79 // When set to a 1, the ALARM output is active high.
Rhyme 0:7c0469e71fa2 80 #define ALRM_POL_BIT 0x01
Rhyme 0:7c0469e71fa2 81
Rhyme 0:7c0469e71fa2 82 /* Member Functions */
Rhyme 0:7c0469e71fa2 83
Rhyme 0:7c0469e71fa2 84 DS1683::DS1683(PinName sda, PinName scl, PinName eventpin, PinName alarmpin, int addr) :
Rhyme 0:7c0469e71fa2 85 event(eventpin), alarm(alarmpin), m_i2c(sda, scl), m_addr(addr<<1)
Rhyme 0:7c0469e71fa2 86 {
Rhyme 0:7c0469e71fa2 87 m_i2c.frequency(100000) ;
Rhyme 0:7c0469e71fa2 88 setConfig(0x00) ; /* disable ETC_ALRM_EN and EVENT_ALRM_EN */
Rhyme 0:7c0469e71fa2 89 alarmPol(0) ; /* Low Active */
Rhyme 0:7c0469e71fa2 90 // alarmPol(1) ; /* Active High */
Rhyme 0:7c0469e71fa2 91 }
Rhyme 0:7c0469e71fa2 92
Rhyme 0:7c0469e71fa2 93 DS1683::~DS1683()
Rhyme 0:7c0469e71fa2 94 {
Rhyme 0:7c0469e71fa2 95 }
Rhyme 0:7c0469e71fa2 96
Rhyme 0:7c0469e71fa2 97 int DS1683::read(int addr, uint8_t *data, int len)
Rhyme 0:7c0469e71fa2 98 {
Rhyme 0:7c0469e71fa2 99 int result ;
Rhyme 0:7c0469e71fa2 100 result = readRegs(addr, data, len) ;
Rhyme 0:7c0469e71fa2 101 wait(0.01) ;
Rhyme 0:7c0469e71fa2 102 return( result ) ;
Rhyme 0:7c0469e71fa2 103 }
Rhyme 0:7c0469e71fa2 104
Rhyme 0:7c0469e71fa2 105 int DS1683::write(int addr, uint8_t *data, int len)
Rhyme 0:7c0469e71fa2 106 {
Rhyme 0:7c0469e71fa2 107 uint8_t *buf ;
Rhyme 0:7c0469e71fa2 108 int ack ;
Rhyme 0:7c0469e71fa2 109 buf = new uint8_t[len+1] ;
Rhyme 0:7c0469e71fa2 110 buf[0] = addr ;
Rhyme 0:7c0469e71fa2 111 for (int i = 0 ; i < len ; i++ ) {
Rhyme 0:7c0469e71fa2 112 buf[i+1] = data[i] ;
Rhyme 0:7c0469e71fa2 113 }
Rhyme 0:7c0469e71fa2 114 ack = writeRegs(buf, len+1) ;
Rhyme 0:7c0469e71fa2 115 wait(0.01) ;
Rhyme 0:7c0469e71fa2 116 delete buf ;
Rhyme 0:7c0469e71fa2 117 return( ack ) ;
Rhyme 0:7c0469e71fa2 118 }
Rhyme 0:7c0469e71fa2 119
Rhyme 0:7c0469e71fa2 120 int DS1683::readRegs(int addr, uint8_t * data, int len) {
Rhyme 0:7c0469e71fa2 121 int result ;
Rhyme 0:7c0469e71fa2 122 char t[1] = {addr};
Rhyme 0:7c0469e71fa2 123 m_i2c.write(m_addr, t, 1, true);
Rhyme 0:7c0469e71fa2 124 result = m_i2c.read(m_addr, (char *)data, len);
Rhyme 0:7c0469e71fa2 125 return( result ) ;
Rhyme 0:7c0469e71fa2 126 }
Rhyme 0:7c0469e71fa2 127
Rhyme 0:7c0469e71fa2 128 int DS1683::writeRegs(uint8_t * data, int len) {
Rhyme 0:7c0469e71fa2 129 int ack ;
Rhyme 0:7c0469e71fa2 130 m_i2c.stop() ;
Rhyme 0:7c0469e71fa2 131 wait(0.01) ;
Rhyme 0:7c0469e71fa2 132 ack = m_i2c.write(m_addr, (char *)data, len);
Rhyme 0:7c0469e71fa2 133 m_i2c.stop() ;
Rhyme 0:7c0469e71fa2 134 return( ack ) ;
Rhyme 0:7c0469e71fa2 135 }
Rhyme 0:7c0469e71fa2 136
Rhyme 0:7c0469e71fa2 137 uint8_t DS1683::readReg8(int addr)
Rhyme 0:7c0469e71fa2 138 {
Rhyme 0:7c0469e71fa2 139 uint8_t data[1] ;
Rhyme 0:7c0469e71fa2 140 readRegs(addr, data, 1) ;
Rhyme 0:7c0469e71fa2 141 return( data[0] ) ;
Rhyme 0:7c0469e71fa2 142 }
Rhyme 0:7c0469e71fa2 143
Rhyme 0:7c0469e71fa2 144 void DS1683::writeReg8(int addr, uint8_t value)
Rhyme 0:7c0469e71fa2 145 {
Rhyme 0:7c0469e71fa2 146 uint8_t data[2] ;
Rhyme 0:7c0469e71fa2 147 data[0] = addr ;
Rhyme 0:7c0469e71fa2 148 data[1] = value ;
Rhyme 0:7c0469e71fa2 149 writeRegs(data, 2) ;
Rhyme 0:7c0469e71fa2 150 }
Rhyme 0:7c0469e71fa2 151
Rhyme 0:7c0469e71fa2 152 uint16_t DS1683::readReg16(int addr)
Rhyme 0:7c0469e71fa2 153 {
Rhyme 0:7c0469e71fa2 154 uint8_t data[2] ;
Rhyme 0:7c0469e71fa2 155 uint16_t value = 0 ;
Rhyme 0:7c0469e71fa2 156 readRegs(addr, data, 2) ;
Rhyme 0:7c0469e71fa2 157 value = data[1] ;
Rhyme 0:7c0469e71fa2 158 value = (value << 8) | data[1] ;
Rhyme 0:7c0469e71fa2 159 return(value) ;
Rhyme 0:7c0469e71fa2 160 }
Rhyme 0:7c0469e71fa2 161
Rhyme 0:7c0469e71fa2 162 void DS1683::writeReg16(int addr, uint16_t value)
Rhyme 0:7c0469e71fa2 163 {
Rhyme 0:7c0469e71fa2 164 #if 0
Rhyme 0:7c0469e71fa2 165 uint8_t data[3] ;
Rhyme 0:7c0469e71fa2 166 data[0] = addr ;
Rhyme 0:7c0469e71fa2 167 data[1] = value & 0xFF ;
Rhyme 0:7c0469e71fa2 168 data[2] = (value >> 8) & 0xFF ;
Rhyme 0:7c0469e71fa2 169 writeRegs(data, 3) ;
Rhyme 0:7c0469e71fa2 170 #endif
Rhyme 0:7c0469e71fa2 171 uint8_t data[2] ;
Rhyme 0:7c0469e71fa2 172 data[0] = addr ;
Rhyme 0:7c0469e71fa2 173 data[1] = value & 0xFF ;
Rhyme 0:7c0469e71fa2 174 writeRegs(data, 2) ;
Rhyme 0:7c0469e71fa2 175 data[0] = addr+1 ;
Rhyme 0:7c0469e71fa2 176 data[1] = (value >> 8) & 0xFF ;
Rhyme 0:7c0469e71fa2 177 writeRegs(data, 2) ;
Rhyme 0:7c0469e71fa2 178 }
Rhyme 0:7c0469e71fa2 179
Rhyme 0:7c0469e71fa2 180 uint32_t DS1683::readReg32(int addr)
Rhyme 0:7c0469e71fa2 181 {
Rhyme 0:7c0469e71fa2 182 uint8_t data[4] ;
Rhyme 0:7c0469e71fa2 183 uint32_t value = 0 ;
Rhyme 0:7c0469e71fa2 184 readRegs(addr, data, 4) ;
Rhyme 0:7c0469e71fa2 185 value = data[3] ;
Rhyme 0:7c0469e71fa2 186 value = (value << 8) | data[2] ;
Rhyme 0:7c0469e71fa2 187 value = (value << 8) | data[1] ;
Rhyme 0:7c0469e71fa2 188 value = (value << 8) | data[0] ;
Rhyme 0:7c0469e71fa2 189 return(value) ;
Rhyme 0:7c0469e71fa2 190 }
Rhyme 0:7c0469e71fa2 191
Rhyme 0:7c0469e71fa2 192 void DS1683::writeReg32(int addr, uint32_t value)
Rhyme 0:7c0469e71fa2 193 {
Rhyme 0:7c0469e71fa2 194 #if 0
Rhyme 0:7c0469e71fa2 195 uint8_t data[5] ;
Rhyme 0:7c0469e71fa2 196 data[0] = addr ;
Rhyme 0:7c0469e71fa2 197 data[1] = value & 0xFF ;
Rhyme 0:7c0469e71fa2 198 data[2] = (value >> 8) & 0xFF ;
Rhyme 0:7c0469e71fa2 199 data[3] = (value >> 16) & 0xFF ;
Rhyme 0:7c0469e71fa2 200 data[4] = (value >> 24) & 0xFF ;
Rhyme 0:7c0469e71fa2 201 writeRegs(data, 5) ;
Rhyme 0:7c0469e71fa2 202 #endif
Rhyme 0:7c0469e71fa2 203 uint8_t data[2] ;
Rhyme 0:7c0469e71fa2 204 data[0] = addr ;
Rhyme 0:7c0469e71fa2 205 data[1] = value & 0xFF ;
Rhyme 0:7c0469e71fa2 206 printf("mem[%02X] = %02x\n", data[0], data[1]) ;
Rhyme 0:7c0469e71fa2 207 // writeRegs(data, 2) ;
Rhyme 0:7c0469e71fa2 208 writeReg8(data[0], data[1]) ;
Rhyme 0:7c0469e71fa2 209 data[0] = addr + 1;
Rhyme 0:7c0469e71fa2 210 data[1] = (value >> 8) & 0xFF ;
Rhyme 0:7c0469e71fa2 211 printf("mem[%02X] = %02x\n", data[0], data[1]) ;
Rhyme 0:7c0469e71fa2 212 // writeRegs(data, 2) ;
Rhyme 0:7c0469e71fa2 213 writeReg8(data[0], data[1]) ;
Rhyme 0:7c0469e71fa2 214 data[0] = addr +2 ;
Rhyme 0:7c0469e71fa2 215 data[1] = (value >> 16) & 0xFF ;
Rhyme 0:7c0469e71fa2 216 printf("mem[%02X] = %02x\n", data[0], data[1]) ;
Rhyme 0:7c0469e71fa2 217 // writeRegs(data, 2) ;
Rhyme 0:7c0469e71fa2 218 writeReg8(data[0], data[1]) ;
Rhyme 0:7c0469e71fa2 219 data[0] = addr + 3;
Rhyme 0:7c0469e71fa2 220 data[1] = (value >> 24) & 0xFF ;
Rhyme 0:7c0469e71fa2 221 printf("mem[%02X] = %02x\n", data[0], data[1]) ;
Rhyme 0:7c0469e71fa2 222 // writeRegs(data, 2) ;
Rhyme 0:7c0469e71fa2 223 writeReg8(data[0], data[1]) ;
Rhyme 0:7c0469e71fa2 224 }
Rhyme 0:7c0469e71fa2 225
Rhyme 0:7c0469e71fa2 226 void DS1683::setConfig(uint8_t conf)
Rhyme 0:7c0469e71fa2 227 {
Rhyme 0:7c0469e71fa2 228 writeReg8(REG_CONFIG, conf) ;
Rhyme 0:7c0469e71fa2 229 }
Rhyme 0:7c0469e71fa2 230
Rhyme 0:7c0469e71fa2 231 uint8_t DS1683::getConfig(void)
Rhyme 0:7c0469e71fa2 232 {
Rhyme 0:7c0469e71fa2 233 return( readReg8(REG_CONFIG) ) ;
Rhyme 0:7c0469e71fa2 234 }
Rhyme 0:7c0469e71fa2 235
Rhyme 0:7c0469e71fa2 236 uint8_t DS1683::getStatus(void)
Rhyme 0:7c0469e71fa2 237 {
Rhyme 0:7c0469e71fa2 238 return(readReg8(REG_STATUS)) ;
Rhyme 0:7c0469e71fa2 239 }
Rhyme 0:7c0469e71fa2 240
Rhyme 0:7c0469e71fa2 241 void DS1683::setETC(uint32_t count)
Rhyme 0:7c0469e71fa2 242 {
Rhyme 0:7c0469e71fa2 243 writeReg32(REG_ETC, count) ;
Rhyme 0:7c0469e71fa2 244 }
Rhyme 0:7c0469e71fa2 245
Rhyme 0:7c0469e71fa2 246 uint32_t DS1683::getETC(void)
Rhyme 0:7c0469e71fa2 247 {
Rhyme 0:7c0469e71fa2 248 return(readReg32(REG_ETC)) ;
Rhyme 0:7c0469e71fa2 249 }
Rhyme 0:7c0469e71fa2 250
Rhyme 0:7c0469e71fa2 251 void DS1683::setEventCount(uint16_t count)
Rhyme 0:7c0469e71fa2 252 {
Rhyme 0:7c0469e71fa2 253 writeReg16(REG_EVENT, count) ;
Rhyme 0:7c0469e71fa2 254 }
Rhyme 0:7c0469e71fa2 255
Rhyme 0:7c0469e71fa2 256 uint16_t DS1683::getEventCount(void)
Rhyme 0:7c0469e71fa2 257 {
Rhyme 0:7c0469e71fa2 258 return(readReg16(REG_EVENT)) ;
Rhyme 0:7c0469e71fa2 259 }
Rhyme 0:7c0469e71fa2 260
Rhyme 0:7c0469e71fa2 261 void DS1683::dumpRegs(void)
Rhyme 0:7c0469e71fa2 262 {
Rhyme 0:7c0469e71fa2 263 uint8_t data[5] ;
Rhyme 0:7c0469e71fa2 264 // printf("m_addr = 0x%02X ", m_addr) ;
Rhyme 0:7c0469e71fa2 265 data[0] = 0 ;
Rhyme 0:7c0469e71fa2 266 readRegs(REG_COMMAND, data, 1) ;
Rhyme 0:7c0469e71fa2 267 printf("Command: 0x%02X ", data[0]) ;
Rhyme 0:7c0469e71fa2 268 printf("Status: 0x%02X ", getStatus()) ;
Rhyme 0:7c0469e71fa2 269 printf("Config: 0x%02X\n", getConfig()) ;
Rhyme 0:7c0469e71fa2 270 }
Rhyme 0:7c0469e71fa2 271
Rhyme 0:7c0469e71fa2 272 void DS1683::enterPW(uint32_t pass)
Rhyme 0:7c0469e71fa2 273 {
Rhyme 0:7c0469e71fa2 274 uint8_t data[5] ;
Rhyme 0:7c0469e71fa2 275 data[0] = REG_PWE ; /* Password Entry */
Rhyme 0:7c0469e71fa2 276 data[1] = pass & 0xFF ;
Rhyme 0:7c0469e71fa2 277 data[2] = (pass >> 8) & 0xFF ;
Rhyme 0:7c0469e71fa2 278 data[3] = (pass >> 16) & 0xFF ;
Rhyme 0:7c0469e71fa2 279 data[4] = (pass >> 24) & 0xFF ;
Rhyme 0:7c0469e71fa2 280 writeRegs(data, 5) ;
Rhyme 0:7c0469e71fa2 281 }
Rhyme 0:7c0469e71fa2 282
Rhyme 0:7c0469e71fa2 283 void DS1683::dumpETC(void)
Rhyme 0:7c0469e71fa2 284 {
Rhyme 0:7c0469e71fa2 285 uint32_t data[2] ;
Rhyme 0:7c0469e71fa2 286 data[0] = getETC() ;
Rhyme 0:7c0469e71fa2 287 data[1] = getETCAlarm() ;
Rhyme 0:7c0469e71fa2 288 printf("ETC count: 0x%08X / limit: 0x%08X flag: ", data[0], data[1]) ;
Rhyme 0:7c0469e71fa2 289 if (getStatus() & ETC_AF_BIT) {
Rhyme 0:7c0469e71fa2 290 printf("ON") ;
Rhyme 0:7c0469e71fa2 291 } else {
Rhyme 0:7c0469e71fa2 292 printf("OFF") ;
Rhyme 0:7c0469e71fa2 293 }
Rhyme 0:7c0469e71fa2 294 printf("\n") ;
Rhyme 0:7c0469e71fa2 295 }
Rhyme 0:7c0469e71fa2 296
Rhyme 0:7c0469e71fa2 297 void DS1683::dumpEvent(void)
Rhyme 0:7c0469e71fa2 298 {
Rhyme 0:7c0469e71fa2 299 uint16_t data[2] ;
Rhyme 0:7c0469e71fa2 300 data[0] = getEventCount() ;
Rhyme 0:7c0469e71fa2 301 data[1] = getEventAlarm() ;
Rhyme 0:7c0469e71fa2 302 printf("Event Counter count: %04X / limit: %04X flag: ", data[0], data[1]) ;
Rhyme 0:7c0469e71fa2 303 if (getStatus() & EVENT_AF_BIT) {
Rhyme 0:7c0469e71fa2 304 printf("ON") ;
Rhyme 0:7c0469e71fa2 305 } else {
Rhyme 0:7c0469e71fa2 306 printf("OFF") ;
Rhyme 0:7c0469e71fa2 307 }
Rhyme 0:7c0469e71fa2 308 printf("\n") ;
Rhyme 0:7c0469e71fa2 309 }
Rhyme 0:7c0469e71fa2 310
Rhyme 0:7c0469e71fa2 311 void DS1683::setETCAlarm(uint32_t count)
Rhyme 0:7c0469e71fa2 312 {
Rhyme 0:7c0469e71fa2 313 writeReg32(REG_ETCAL, count) ;
Rhyme 0:7c0469e71fa2 314 }
Rhyme 0:7c0469e71fa2 315
Rhyme 0:7c0469e71fa2 316 uint32_t DS1683::getETCAlarm(void)
Rhyme 0:7c0469e71fa2 317 {
Rhyme 0:7c0469e71fa2 318 return(readReg32(REG_ETCAL)) ;
Rhyme 0:7c0469e71fa2 319 }
Rhyme 0:7c0469e71fa2 320
Rhyme 0:7c0469e71fa2 321 void DS1683::clearAlarm(void)
Rhyme 0:7c0469e71fa2 322 {
Rhyme 0:7c0469e71fa2 323 uint8_t data[2] ;
Rhyme 0:7c0469e71fa2 324 data[0] = REG_COMMAND ;
Rhyme 0:7c0469e71fa2 325 data[1] = 0x01 ;
Rhyme 0:7c0469e71fa2 326 writeRegs(data, 2) ;
Rhyme 0:7c0469e71fa2 327 }
Rhyme 0:7c0469e71fa2 328
Rhyme 0:7c0469e71fa2 329 void DS1683::clearEvent(void)
Rhyme 0:7c0469e71fa2 330 {
Rhyme 0:7c0469e71fa2 331 writeReg16(REG_EVENT, 0x0000) ;
Rhyme 0:7c0469e71fa2 332 }
Rhyme 0:7c0469e71fa2 333
Rhyme 0:7c0469e71fa2 334 void DS1683::setEventAlarm(uint16_t count)
Rhyme 0:7c0469e71fa2 335 {
Rhyme 0:7c0469e71fa2 336 writeReg16(REG_ECAL, count) ;
Rhyme 0:7c0469e71fa2 337 }
Rhyme 0:7c0469e71fa2 338
Rhyme 0:7c0469e71fa2 339 uint16_t DS1683::getEventAlarm(void)
Rhyme 0:7c0469e71fa2 340 {
Rhyme 0:7c0469e71fa2 341 return(readReg16(REG_ECAL)) ;
Rhyme 0:7c0469e71fa2 342 }
Rhyme 0:7c0469e71fa2 343
Rhyme 0:7c0469e71fa2 344 void DS1683::clearETC(void)
Rhyme 0:7c0469e71fa2 345 {
Rhyme 0:7c0469e71fa2 346 writeReg32(REG_ETC, 0x00000000) ;
Rhyme 0:7c0469e71fa2 347 }
Rhyme 0:7c0469e71fa2 348
Rhyme 0:7c0469e71fa2 349 void DS1683::enableETCAlarm(void)
Rhyme 0:7c0469e71fa2 350 {
Rhyme 0:7c0469e71fa2 351 uint8_t config ;
Rhyme 0:7c0469e71fa2 352 config = getConfig() ;
Rhyme 0:7c0469e71fa2 353 config |= ETC_ALARM_EN_BIT ;
Rhyme 0:7c0469e71fa2 354 setConfig(config) ;
Rhyme 0:7c0469e71fa2 355 }
Rhyme 0:7c0469e71fa2 356
Rhyme 0:7c0469e71fa2 357 void DS1683::disableETCAlarm(void)
Rhyme 0:7c0469e71fa2 358 {
Rhyme 0:7c0469e71fa2 359 uint8_t config ;
Rhyme 0:7c0469e71fa2 360 config = getConfig() ;
Rhyme 0:7c0469e71fa2 361 config &= ~ETC_ALARM_EN_BIT ;
Rhyme 0:7c0469e71fa2 362 setConfig(config) ;
Rhyme 0:7c0469e71fa2 363 }
Rhyme 0:7c0469e71fa2 364
Rhyme 0:7c0469e71fa2 365 void DS1683::enableEventAlarm(void)
Rhyme 0:7c0469e71fa2 366 {
Rhyme 0:7c0469e71fa2 367 uint8_t config ;
Rhyme 0:7c0469e71fa2 368 config = getConfig() ;
Rhyme 0:7c0469e71fa2 369 config |= EVENT_ALARM_EN_BIT ;
Rhyme 0:7c0469e71fa2 370 setConfig(config) ;
Rhyme 0:7c0469e71fa2 371 }
Rhyme 0:7c0469e71fa2 372
Rhyme 0:7c0469e71fa2 373 void DS1683::disableEventAlarm(void)
Rhyme 0:7c0469e71fa2 374 {
Rhyme 0:7c0469e71fa2 375 uint8_t config ;
Rhyme 0:7c0469e71fa2 376 config = getConfig() ;
Rhyme 0:7c0469e71fa2 377 config &= ~EVENT_ALARM_EN_BIT ;
Rhyme 0:7c0469e71fa2 378 setConfig(config) ;
Rhyme 0:7c0469e71fa2 379 }
Rhyme 0:7c0469e71fa2 380
Rhyme 0:7c0469e71fa2 381 void DS1683::alarmPol(int pol)
Rhyme 0:7c0469e71fa2 382 {
Rhyme 0:7c0469e71fa2 383 uint8_t config ;
Rhyme 0:7c0469e71fa2 384 config = getConfig() ;
Rhyme 0:7c0469e71fa2 385 if (pol) {
Rhyme 0:7c0469e71fa2 386 config |= 0x01 ;
Rhyme 0:7c0469e71fa2 387 } else {
Rhyme 0:7c0469e71fa2 388 config &= ~0x01 ;
Rhyme 0:7c0469e71fa2 389 }
Rhyme 0:7c0469e71fa2 390 setConfig(config) ;
Rhyme 0:7c0469e71fa2 391 }