-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMCP9600.c
88 lines (63 loc) · 1.34 KB
/
MCP9600.c
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
#include <stdio.h>
#include <wiringPi.h>
#include <wiringPiI2C.h>
#include "MCP9600.h"
int MCP9600_Init(char address, char type, int filter)
{
int fd;
if((fd = wiringPiI2CSetup(adress)) < 0 ) {
printf("ERROR\n");
return -1;
}
else {
switch( type )
{
case 'K':
type = 0x00;
break;
case 'J':
type = 0x01;
break;
case 'T':
type = 0x02;
break;
case 'N':
type = 0x03;
break;
case 'S':
type = 0x04;
break;
case 'E':
type = 0x05;
break;
case 'B':
type = 0x06;
break;
case 'R':
type = 0x07;
break;
//default:
}
if((wiringPiI2CWriteReg8(fd, 0x05, ((type<<4) | (0x07 & filter))) ) < 0 )
printf("ERROR\n");
return fd;
}
}
float MCP9600_ReadAmbientTemperature(int fd) {
int result;
if((result = wiringPiI2CReadReg16 (fd, 0x02)) < 0 ) {
printf("MCP9600_ERROR\n");
return -1;
}
else
return (float)((0xff & (result>>8)) | (0xff00 &(result<<8))) * 0.0625;
}
float MCP9600_ReadProbeTemperature(int fd) {
int result;
if((result = wiringPiI2CReadReg16 (fd, 0x00)) < 0 ) {
printf("MCP9600_ERROR\n");
return -1;
}
else
return (float)((0xff & (result>>8)) | (0xff00 &(result<<8))) * 0.0625;
}