satnogs-rotator-firmware
Loading...
Searching...
No Matches
tc74.h
Go to the documentation of this file.
1
10#ifndef TC74_H_
11#define TC74_H_
12
13#include <Arduino.h>
14#include <Wire.h>
15
16#define TC74_TEMPERATURE_REGISTER 0x00
17#define TC74_CONFIGURATION_REGISTER 0x01
18#define TC74_STANDBY_COMMAND 0x80
19#define TC74_AWAKE_COMMAND 0x00
20#define TC74_DATA_READY_FLAG 0x40
21
22/**************************************************************************/
36/**************************************************************************/
37class tc74 {
38public:
39
40 tc74(uint8_t id) {
41 _id = id;
42 }
43
44 /**************************************************************************/
48 /**************************************************************************/
49 void init() {
50 Wire.begin();
51 Wire.setClock(I2C_FREQ);
52 }
53
54 /**************************************************************************/
59 /**************************************************************************/
60 int8_t get_temp() {
61 Wire.beginTransmission(_id);
62 Wire.write(TC74_TEMPERATURE_REGISTER);
63 Wire.endTransmission();
64 Wire.requestFrom(_id, 1);
65 while (Wire.available() == 0)
66 ;
67 return Wire.read();
68 }
69
70 /**************************************************************************/
75 /**************************************************************************/
76 int8_t get_status() {
77 Wire.beginTransmission(_id);
79 Wire.endTransmission();
80 Wire.beginTransmission(_id);
81 Wire.write(TC74_AWAKE_COMMAND);
82 Wire.endTransmission();
83 Wire.requestFrom(_id, 1);
84 while (Wire.available() == 0)
85 ;
86 return Wire.read();
87 }
88
89 /**************************************************************************/
94 /**************************************************************************/
95 int8_t wake_up() {
96 Wire.beginTransmission(_id);
98 Wire.endTransmission();
99 Wire.beginTransmission(_id);
100 Wire.write(TC74_AWAKE_COMMAND);
101 Wire.endTransmission();
102 return get_status();
103 }
104
105 /**************************************************************************/
110 /**************************************************************************/
111 int8_t sleep() {
112 Wire.beginTransmission(_id);
113 Wire.write(TC74_CONFIGURATION_REGISTER);
114 Wire.endTransmission();
115 Wire.beginTransmission(_id);
116 Wire.write(TC74_STANDBY_COMMAND);
117 Wire.endTransmission();
118 return get_status();
119 }
120
121private:
122 int _id;
123};
124
125#endif /* TC74_H_ */
#define I2C_FREQ
Definition as5601.h:18
Class that functions for interacting with a TC74 Temperature sensor.
Definition tc74.h:37
tc74(uint8_t id)
Definition tc74.h:40
int8_t sleep()
Sleep device request to the sensor on the specified address.
Definition tc74.h:111
int8_t get_temp()
Reads the int8_t in temperature measurement register.
Definition tc74.h:60
int8_t get_status()
Reads the int8_t in status register.
Definition tc74.h:76
int _id
Definition tc74.h:122
int8_t wake_up()
Wake up request to the sensor on the specified address.
Definition tc74.h:95
void init()
Initialize the I2C bus.
Definition tc74.h:49
#define TC74_STANDBY_COMMAND
Definition tc74.h:18
#define TC74_CONFIGURATION_REGISTER
Definition tc74.h:17
#define TC74_AWAKE_COMMAND
Definition tc74.h:19
#define TC74_TEMPERATURE_REGISTER
Definition tc74.h:16