forked from nimaltd/ds18b20
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ds18b20.h
85 lines (69 loc) · 3.06 KB
/
ds18b20.h
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
#ifndef _DS18B20_H
#define _DS18B20_H
// 2018/09/08
#include "onewire.h"
#include "ds18b20Config.h"
#include <stdbool.h>
#if (_DS18B20_USE_FREERTOS==1)
#include "cmsis_os.h"
#define Ds18b20Delay(x) osDelay(x)
#else
#define Ds18b20Delay(x) HAL_Delay(x)
#endif
//###################################################################################
typedef struct
{
uint8_t Address[8];
float Temperature;
bool DataIsValid;
}Ds18b20Sensor_t;
//###################################################################################
extern Ds18b20Sensor_t ds18b20[_DS18B20_MAX_SENSORS];
//###################################################################################
/* Every onewire chip has different ROM code, but all the same chips has same family code */
/* in case of DS18B20 this is 0x28 and this is first byte of ROM address */
#define DS18B20_FAMILY_CODE 0x28
#define DS18B20_CMD_ALARMSEARCH 0xEC
/* DS18B20 read temperature command */
#define DS18B20_CMD_CONVERTTEMP 0x44 /* Convert temperature */
#define DS18B20_DECIMAL_STEPS_12BIT 0.0625
#define DS18B20_DECIMAL_STEPS_11BIT 0.125
#define DS18B20_DECIMAL_STEPS_10BIT 0.25
#define DS18B20_DECIMAL_STEPS_9BIT 0.5
/* Bits locations for resolution */
#define DS18B20_RESOLUTION_R1 6
#define DS18B20_RESOLUTION_R0 5
/* CRC enabled */
#ifdef DS18B20_USE_CRC
#define DS18B20_DATA_LEN 9
#else
#define DS18B20_DATA_LEN 2
#endif
//###################################################################################
typedef enum {
DS18B20_Resolution_9bits = 9, /*!< DS18B20 9 bits resolution */
DS18B20_Resolution_10bits = 10, /*!< DS18B20 10 bits resolution */
DS18B20_Resolution_11bits = 11, /*!< DS18B20 11 bits resolution */
DS18B20_Resolution_12bits = 12 /*!< DS18B20 12 bits resolution */
} DS18B20_Resolution_t;
//###################################################################################
#if (_DS18B20_USE_FREERTOS==1)
void Ds18b20_Init(osPriority Priority);
#else
bool Ds18b20_Init(void);
#endif
bool Ds18b20_ManualConvert(void);
//###################################################################################
uint8_t DS18B20_Start(OneWire_t* OneWireStruct, uint8_t* ROM);
void DS18B20_StartAll(OneWire_t* OneWireStruct);
bool DS18B20_Read(OneWire_t* OneWireStruct, uint8_t* ROM, float* destination);
uint8_t DS18B20_GetResolution(OneWire_t* OneWireStruct, uint8_t* ROM);
uint8_t DS18B20_SetResolution(OneWire_t* OneWireStruct, uint8_t* ROM, DS18B20_Resolution_t resolution);
uint8_t DS18B20_Is(uint8_t* ROM);
uint8_t DS18B20_SetAlarmHighTemperature(OneWire_t* OneWireStruct, uint8_t* ROM, int8_t temp);
uint8_t DS18B20_SetAlarmLowTemperature(OneWire_t* OneWireStruct, uint8_t* ROM, int8_t temp);
uint8_t DS18B20_DisableAlarmTemperature(OneWire_t* OneWireStruct, uint8_t* ROM);
uint8_t DS18B20_AlarmSearch(OneWire_t* OneWireStruct);
uint8_t DS18B20_AllDone(OneWire_t* OneWireStruct);
//###################################################################################
#endif