-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathDS2423.cpp
91 lines (68 loc) · 1.82 KB
/
DS2423.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include "OneWireHub.h"
#include "DS2423.h"
#define DEBUG_DS2423
DS2423::DS2423(byte ID1, byte ID2, byte ID3, byte ID4, byte ID5, byte ID6, byte ID7): OneWireItem(ID1, ID2, ID3, ID4, ID5, ID6, ID7){
}
bool DS2423::duty(OneWireHub * hub)
{
uint16_t memory_address;
uint16_t memory_address_start;
uint8_t b;
uint16_t crc;
ow_crc16_reset();
uint8_t done = hub->recv();
switch (done) {
// Read Memory + Counter
case 0xA5:
ow_crc16_update(0xA5);
// Adr1
b = hub->recv();
((uint8_t*)&memory_address)[0] = b;
ow_crc16_update(b);
// Adr2
b = hub->recv();
((uint8_t*)&memory_address)[1] = b;
ow_crc16_update(b);
memory_address_start = memory_address;
// data
for (int i=0;i<32;i++){
hub->send(0xff);
ow_crc16_update(0xff);
}
// cnt
hub->send(0x00);
ow_crc16_update(0x00);
hub->send(0x00);
ow_crc16_update(0x00);
hub->send(0x00);
ow_crc16_update(0x00);
hub->send(0x00);
ow_crc16_update(0x00);
// zero
hub->send(0x00);
ow_crc16_update(0x00);
hub->send(0x00);
ow_crc16_update(0x00);
hub->send(0x00);
ow_crc16_update(0x00);
hub->send(0x00);
ow_crc16_update(0x00);
// crc
crc = ow_crc16_get();
hub->send(((uint8_t*)&crc)[0]);
hub->send(((uint8_t*)&crc)[1]);
ow_crc16_reset();
#ifdef DEBUG_DS2423
Serial.print("DS2423 : Read Memory + Counter : ");
Serial.println(memory_address_start, HEX);
#endif
break;
default:
#ifdef DEBUG_hint
Serial.print("DS2423=");
Serial.println(done, HEX);
#endif
break;
}
return TRUE;
}