Skip to content

Commit 8884c9c

Browse files
authored
Merge pull request #2 from SandeepanSengupta/master
Patch release v1.0.1
2 parents 001157e + dc64aef commit 8884c9c

File tree

10 files changed

+661
-220
lines changed

10 files changed

+661
-220
lines changed

LICENSE

Lines changed: 381 additions & 0 deletions
Large diffs are not rendered by default.

MAX6626.cpp

Lines changed: 54 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
/*
2-
* @file MAX6266.cpp
3-
* @author Tamojit Saha
4-
* @website www.tamojitsaha.info
5-
*
6-
* @license CC-BY-SA 4.0(See license.txt)
7-
*
8-
* I2C Driver for Maxim's MAX6626 12Bit Temperature Sensor
9-
* v1.0 - First Release
10-
*/
11-
2+
@file MAX6266.cpp
3+
@author Sandeepan Sengupta, Tamojit Saha
4+
@website https://www.sandeepan.info,
5+
https://www.tamojitsaha.info
6+
7+
@Library https://github.com/TamojitSaha/MAX6626
8+
@license CC-BY-SA 4.0
9+
10+
I2C Driver for Maxim's MAX6626 12Bit Temperature Sensor
11+
Version 1.0.1 -First Patch for v1.0
12+
*/
13+
1214
#if ARDUINO >= 100
1315
#include "Arduino.h"
1416
#else
@@ -26,12 +28,12 @@
2628
MAX6626::MAX6626() {
2729
}
2830

29-
boolean MAX6626::begin(uint8_t addr)
31+
boolean MAX6626::begin(address addr)
3032
{
3133
Wire.begin();
3234
i2caddr = addr;
3335
conf_register = readConfig();
34-
36+
3537
Wire.beginTransmission(i2caddr);
3638
uint8_t err = Wire.endTransmission();
3739
if (err != 0)
@@ -61,8 +63,12 @@ void MAX6626::sleep() {
6163
}
6264

6365
void MAX6626::wake() {
64-
shutdown_wake(0);
65-
_delay_ms(250);
66+
shutdown_wake(false);
67+
delay(wakeDelay);
68+
}
69+
70+
void MAX6626::setWakeDelay(uint32_t wkDelay) {
71+
wakeDelay = wkDelay;
6672
}
6773

6874
void MAX6626::setInterruptMode(bool sw)
@@ -99,57 +105,52 @@ void MAX6626::setOTpolarity(bool sw)
99105
}
100106
}
101107

102-
void MAX6626::setFaultQueueDepth(uint8_t depth)
108+
void MAX6626::setFaultQueueDepth(depth _depth)
103109
{
104110
volatile uint8_t reg = (uint8_t)readConfig();
105-
if (depth < 0) depth = 0;
106-
if (depth > 3) depth = 3;
107-
if (depth >= 0 && depth <= 3)
111+
switch (_depth)
108112
{
109-
switch (depth)
110-
{
111-
case 0:
112-
reg &= FQ_BITS_CLEAR_MASK;
113-
conf_register = reg;
114-
115-
write8(CONF_REG, conf_register);
116-
break;
117-
118-
case 1:
119-
reg &= FQ_BITS_CLEAR_MASK;
120-
reg |= FAULT_DEPTH_1;
121-
conf_register = reg;
122-
write8(CONF_REG, conf_register);
123-
break;
124-
125-
case 2:
126-
reg &= FQ_BITS_CLEAR_MASK;
127-
reg |= FAULT_DEPTH_2;
128-
conf_register = reg;
129-
write8(CONF_REG, conf_register);
130-
break;
131-
132-
case 3:
133-
reg &= FQ_BITS_CLEAR_MASK;
134-
reg |= FAULT_DEPTH_3;
135-
conf_register = reg;
136-
write8(CONF_REG, conf_register);
137-
break;
138-
}
113+
case 0:
114+
reg &= FQ_BITS_CLEAR_MASK;
115+
conf_register = reg;
116+
117+
write8(CONF_REG, conf_register);
118+
break;
119+
120+
case 1:
121+
reg &= FQ_BITS_CLEAR_MASK;
122+
reg |= FAULT_DEPTH_1;
123+
conf_register = reg;
124+
write8(CONF_REG, conf_register);
125+
break;
126+
127+
case 2:
128+
reg &= FQ_BITS_CLEAR_MASK;
129+
reg |= FAULT_DEPTH_2;
130+
conf_register = reg;
131+
write8(CONF_REG, conf_register);
132+
break;
133+
134+
case 3:
135+
reg &= FQ_BITS_CLEAR_MASK;
136+
reg |= FAULT_DEPTH_3;
137+
conf_register = reg;
138+
write8(CONF_REG, conf_register);
139+
break;
139140
}
140141
}
141142

142-
void MAX6626::setTHigh(int8_t t_high)
143+
void MAX6626::setTHigh(int8_t t_high)
143144
{
144145
write16(T_HIGH_REG, temperatureToRaw(t_high));
145146
}
146147

147-
void MAX6626::setTLow(int8_t t_low)
148+
void MAX6626::setTLow(int8_t t_low)
148149
{
149150
write16(T_LOW_REG, temperatureToRaw(t_low));
150151
}
151152

152-
uint8_t MAX6626::readConfig()
153+
uint8_t MAX6626::readConfig()
153154
{
154155
Wire.beginTransmission(i2caddr);
155156
Wire.write(CONF_REG);
@@ -161,7 +162,7 @@ uint8_t MAX6626::readConfig()
161162
return config_reg;
162163
}
163164

164-
float MAX6626::readTHigh()
165+
float MAX6626::readTHigh()
165166
{
166167
uint16_t _th = read16(T_HIGH_REG);
167168
float t_high = rawToTemperature(_th);
@@ -170,7 +171,7 @@ float MAX6626::readTHigh()
170171
}
171172

172173

173-
float MAX6626::readTLow()
174+
float MAX6626::readTLow()
174175
{
175176
uint16_t _tl = read16(T_LOW_REG);
176177
float t_low = rawToTemperature(_tl);
@@ -259,4 +260,3 @@ uint16_t MAX6626:: temperatureToRaw(int8_t temp)
259260
val <<= 8;
260261
return val;
261262
}
262-

MAX6626.h

Lines changed: 77 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,78 @@
1-
/*
2-
* @file MAX6266.h
3-
* @author Tamojit Saha
4-
* @website www.tamojitsaha.info
5-
*
6-
* @license CC-BY-SA 4.0(See license.txt)
7-
*
8-
* I2C Driver for Maxim's MAX6626 12Bit Temperature Sensor
9-
* v1.0 - First Release
10-
*/
11-
12-
#ifndef _MAX6626_H_
13-
#define _MAX6626_H_
14-
15-
#if ARDUINO >= 100
16-
#include "Arduino.h"
17-
#else
18-
#include "WProgram.h"
19-
#endif
20-
21-
#include "Wire.h"
22-
23-
#define ADDR_GND 0x48
24-
#define ADDR_VCC 0x49
25-
#define ADDR_SDA 0x4A
26-
#define ADDR_SCL 0x4B
27-
28-
#define TEMP_REG 0x00
29-
#define CONF_REG 0x01
30-
#define T_LOW_REG 0x02
31-
#define T_HIGH_REG 0x03
32-
33-
#define CONF_REG_SHUTDOWN 0x01
34-
#define CONF_REG_COMP_INT 0x02 //Compare Mode or Interrupt Mode
35-
#define CONF_REG_OT_POLARITY 0x04
36-
37-
#define FAULT_DEPTH_1 0x08
38-
#define FAULT_DEPTH_2 0x10
39-
#define FAULT_DEPTH_3 0x18
40-
#define FQ_BITS_CLEAR_MASK 0xE7
41-
42-
class MAX6626
43-
{
44-
public:
45-
MAX6626();
46-
boolean begin(uint8_t a= ADDR_GND);
47-
float readTemp(void);
48-
void sleep(void);
49-
void wake(void);
50-
void setInterruptMode(bool flag);
51-
void setOTpolarity(bool flag);
52-
void setFaultQueueDepth(uint8_t depth);
53-
void setTHigh(int8_t t_high);
54-
void setTLow(int8_t t_low);
55-
float readTHigh(void);
56-
float readTLow(void);
57-
uint8_t readConfig(void);
58-
59-
private:
60-
uint8_t i2caddr;
61-
uint8_t conf_register;
62-
void shutdown_wake(uint8_t sw);
63-
void write16(uint8_t reg,uint16_t val);
64-
uint16_t read16(uint8_t reg);
65-
void write8(uint8_t reg, uint8_t val);
66-
float rawToTemperature(uint16_t rawValue);
67-
uint16_t temperatureToRaw(int8_t temp);
68-
};
1+
/*
2+
@file MAX6266.h
3+
@author Sandeepan Sengupta, Tamojit Saha
4+
@website https://www.sandeepan.info,
5+
https://www.tamojitsaha.info
6+
7+
@Library https://github.com/TamojitSaha/MAX6626
8+
@license CC-BY-SA 4.0
9+
10+
11+
I2C Driver for Maxim's MAX6626 12Bit Temperature Sensor
12+
Version 1.0.1 -First Patch for v1.0
13+
*/
14+
15+
#ifndef _MAX6626_H_
16+
#define _MAX6626_H_
17+
#include "MAX6626CFG.h"
18+
19+
20+
#if ARDUINO >= 100
21+
#include "Arduino.h"
22+
#else
23+
#include "WProgram.h"
24+
#endif
25+
26+
#include "Wire.h"
27+
28+
/*
29+
#define ADDR_GND 0x48
30+
#define ADDR_VCC 0x49
31+
#define ADDR_SDA 0x4A
32+
#define ADDR_SCL 0x4B
33+
*/
34+
35+
#define TEMP_REG 0x00
36+
#define CONF_REG 0x01
37+
#define T_LOW_REG 0x02
38+
#define T_HIGH_REG 0x03
39+
40+
#define CONF_REG_SHUTDOWN 0x01
41+
#define CONF_REG_COMP_INT 0x02 //Compare Mode or Interrupt Mode
42+
#define CONF_REG_OT_POLARITY 0x04
43+
44+
#define FAULT_DEPTH_1 0x08
45+
#define FAULT_DEPTH_2 0x10
46+
#define FAULT_DEPTH_3 0x18
47+
#define FQ_BITS_CLEAR_MASK 0xE7
48+
49+
class MAX6626
50+
{
51+
public:
52+
MAX6626();
53+
boolean begin(address addr = ADDR_GND); //Default to ADDR_GND
54+
float readTemp(void);
55+
void sleep(void);
56+
void wake(void);
57+
void setWakeDelay(uint32_t);
58+
void setInterruptMode(bool flag);
59+
void setOTpolarity(bool flag);
60+
void setFaultQueueDepth(uint8_t depth);
61+
void setTHigh(int8_t t_high);
62+
void setTLow(int8_t t_low);
63+
float readTHigh(void);
64+
float readTLow(void);
65+
uint8_t readConfig(void);
66+
67+
private:
68+
uint32_t wakeDelay = 250; //Default
69+
uint8_t i2caddr;
70+
uint8_t conf_register;
71+
void shutdown_wake(uint8_t sw);
72+
void write8(uint8_t reg, uint8_t val);
73+
void write16(uint8_t reg, uint16_t val);
74+
uint16_t read16(uint8_t reg);
75+
float rawToTemperature(uint16_t rawValue);
76+
uint16_t temperatureToRaw(int8_t temp);
77+
};
6978
#endif

MAX6626CFG.h

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
@file MAX6266CFG.h
3+
@author Sandeepan Sengupta, Tamojit Saha
4+
@website https://www.sandeepan.info,
5+
https://www.tamojitsaha.info
6+
7+
@Library https://github.com/TamojitSaha/MAX6626
8+
@license CC-BY-SA 4.0
9+
10+
I2C Driver for Maxim's MAX6626 12Bit Temperature Sensor
11+
Version 1.0.1 -First Patch for v1.0
12+
*/
13+
#ifndef _MAX6626CFG_H_
14+
#define _MAX6626CFG_H_
15+
16+
typedef enum
17+
{
18+
ADDR_VCC = 0x48,
19+
ADDR_GND = 0x49,
20+
ADDR_SCL = 0x4A,
21+
ADDR_SDA = 0x4B
22+
} address;
23+
24+
typedef enum
25+
{
26+
f1 = 0, //0xE7
27+
f2 = 1, //0x08
28+
f3 = 2, //0x10
29+
f4 = 3, //0x18
30+
F1 = 0, //0xE7
31+
F2 = 1, //0x08
32+
F3 = 2, //0x10
33+
F4 = 3 //0x18
34+
} depth;
35+
36+
#endif

README.md

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
# MAX6626_library
2-
The MAX6626 combines a 12bit temperature sensor, a programmable overtemperature alarm, a dedicated alarm output, OT, activates if the conversion exceeds the value programmed in the high-temperature register. This library can be used to work with all the features the sensor provides.
3-
4-
Please refer to the datasheet [here](extras/MAX6625-MAX6626.pdf) for further information.
5-
6-
## Pinout and Application Circuit
7-
<p align="center">
8-
<img src = "extras/Application Circuit.png" height="150" width="450"/>
9-
</p>
10-
11-
## Test Breakout
12-
The DIP-8 component is for size reference.
13-
<p align="center">
14-
<img src = "extras/test_breakout.jpg" height="150" width="200"/>
15-
</p>
16-
<p align= "center">Test PCB of MAX6626</p>
1+
# MAX6626_library
2+
The MAX6626 combines a 12bit temperature sensor, a programmable overtemperature alarm, a dedicated alarm output, OT, activates if the conversion exceeds the value programmed in the high-temperature register. This library can be used to work with all the features the sensor provides.
3+
4+
Please refer to the datasheet [here](extras/MAX6625-MAX6626.pdf) for further information.
5+
6+
## Pinout and Application Circuit
7+
<p align="center">
8+
<img src = "extras/Application Circuit.png" height="150" width="450"/>
9+
</p>
10+
11+
## Test Breakout
12+
The DIP-8 component is for size reference.
13+
<p align="center">
14+
<img src = "extras/test_breakout.jpg" height="150" width="200"/>
15+
</p>
16+
<p align= "center">Test PCB of MAX6626</p>

0 commit comments

Comments
 (0)