Go to the source code of this file.
◆ DS18B20_CMD_ALARMSEARCH
| #define DS18B20_CMD_ALARMSEARCH 0xEC |
◆ DS18B20_CMD_CONVERTTEMP
| #define DS18B20_CMD_CONVERTTEMP 0x44 /* Convert temperature */ |
◆ DS18B20_DECIMAL_STEPS_10BIT
| #define DS18B20_DECIMAL_STEPS_10BIT 0.25 |
◆ DS18B20_DECIMAL_STEPS_11BIT
| #define DS18B20_DECIMAL_STEPS_11BIT 0.125 |
◆ DS18B20_DECIMAL_STEPS_12BIT
| #define DS18B20_DECIMAL_STEPS_12BIT 0.0625 |
◆ DS18B20_DECIMAL_STEPS_9BIT
| #define DS18B20_DECIMAL_STEPS_9BIT 0.5 |
◆ DS18B20_DQ
DS18B20 - Programmable Resolution 1-Wire Digital Thermometer
To-92 Pins: With the flat side facing you and with the leads pointing down, they are GND, DQ and Vdd
Definition at line 28 of file ds18b20.h.
◆ DS18B20_DQ_HIGH
◆ DS18B20_DQ_INPUT
◆ DS18B20_DQ_LOW
◆ DS18B20_DQ_OUTPUT
◆ DS18B20_DQ_PULLUP
◆ DS18B20_FAMILY_CODE
| #define DS18B20_FAMILY_CODE 0x28 |
◆ DS18B20_RESOLUTION_R0
| #define DS18B20_RESOLUTION_R0 5 |
◆ DS18B20_RESOLUTION_R1
| #define DS18B20_RESOLUTION_R1 6 |
◆ ONEWIRE_CMD_CPYSCRATCHPAD
| #define ONEWIRE_CMD_CPYSCRATCHPAD 0x48 |
◆ ONEWIRE_CMD_MATCHROM
| #define ONEWIRE_CMD_MATCHROM 0x55 |
◆ ONEWIRE_CMD_READROM
| #define ONEWIRE_CMD_READROM 0x33 |
◆ ONEWIRE_CMD_RECEEPROM
| #define ONEWIRE_CMD_RECEEPROM 0xB8 |
◆ ONEWIRE_CMD_RPWRSUPPLY
| #define ONEWIRE_CMD_RPWRSUPPLY 0xB4 |
◆ ONEWIRE_CMD_RSCRATCHPAD
| #define ONEWIRE_CMD_RSCRATCHPAD 0xBE |
◆ ONEWIRE_CMD_SEARCHROM
| #define ONEWIRE_CMD_SEARCHROM 0xF0 |
◆ ONEWIRE_CMD_SKIPROM
| #define ONEWIRE_CMD_SKIPROM 0xCC |
◆ ONEWIRE_CMD_WSCRATCHPAD
| #define ONEWIRE_CMD_WSCRATCHPAD 0x4E |
◆ DS18B20_Resolution_t
| Enumerator |
|---|
| DS18B20_Resolution_9bits | DS18B20 9 bits resolution
|
| DS18B20_Resolution_10bits | DS18B20 10 bits resolution
|
| DS18B20_Resolution_11bits | DS18B20 11 bits resolution
|
| DS18B20_Resolution_12bits | DS18B20 12 bits resolution
|
| DS18B20_Resolution_9bits | DS18B20 9 bits resolution
|
| DS18B20_Resolution_10bits | DS18B20 10 bits resolution
|
| DS18B20_Resolution_11bits | DS18B20 11 bits resolution
|
| DS18B20_Resolution_12bits | DS18B20 12 bits resolution
|
Definition at line 60 of file ds18b20.h.
60 {
@ DS18B20_Resolution_11bits
@ DS18B20_Resolution_9bits
@ DS18B20_Resolution_10bits
@ DS18B20_Resolution_12bits
◆ DS18B20_AllDone()
| __BIT DS18B20_AllDone |
( |
void |
| ) |
|
If read bit is low, then device is not finished yet with calculation temperature.
- Returns
- bit value
Definition at line 183 of file ds18b20.c.
184{
185
187}
__BIT DS18B20_ReadBit(void)
Read one bit from DS18B20.
◆ DS18B20_Crc()
8-bit CRC calculation
- Parameters
-
- Returns
- crc result
Definition at line 151 of file ds18b20.c.
152{
154
155 while (len--)
156 {
159 {
160 mix = (crc ^ inbyte) & 0x01;
161 crc >>= 1;
162 if (mix)
163 {
164 crc ^= 0x8C;
165 }
166 inbyte >>= 1;
167 }
168 }
169
170 return crc;
171}
◆ DS18B20_Init()
| void DS18B20_Init |
( |
void |
| ) |
|
Initialize DS18B20.
Definition at line 53 of file DS18B20_ATY.c.
54{
55
56 RCC->APB2ENR |= 1 << 3;
57 GPIOB->CRL &= 0x0FFFFFFF;
58 GPIOB->CRL |= 0x30000000;
59 GPIOB->ODR |= 1 << 7;
60
61
63 {
64 case 0:
printf(
"DS18B20_Init OK!\n");
break;
65 case 1:
printf(
"DS18B20设备响应复位信号失败!\n");
break;
66 case 2:
printf(
"DS18B20设备释放总线失败!\n");
break;
67 }
68}
u8 DS18B20_CheckDevice(void)
__WEAK_ATY void printf(uint8_t *,...)
◆ DS18B20_ReadBit()
| __BIT DS18B20_ReadBit |
( |
void |
| ) |
|
Read one bit from DS18B20.
- Returns
- bit value
Definition at line 49 of file ds18b20.c.
50{
52
53
57
58
61
62
64
66 }
67
68
70
71
72 return b;
73}
void SYS_DelayUs(uint16_t t)
#define DS18B20_DQ_INPUT()
#define DS18B20_DQ_OUTPUT()
◆ DS18B20_ReadByte()
Read one byte from DS18B20.
- Returns
- byte value
Definition at line 143 of file DS18B20_ATY.c.
144{
146 for(
i = 0;
i < 8;
i++)
147 {
154 data >>= 1;
158 }
159 return data;
160}
#define DS18B20_InPut_Mode()
#define DS18B20_OutPut_Mode()
void DelayUs(uint32_t us)
◆ DS18B20_ReadRom()
| void DS18B20_ReadRom |
( |
uint8_t * |
buf | ) |
|
Read 64-bit ROM: 8-bit family code "0x28", unique 48-bit serial number, 8-bit CRC.
- Note
- This command can only be used if there is a single DS18B20 on the bus. If multiple slaves are present, a data collision will occur(a wired AND result).
- Parameters
-
Definition at line 189 of file ds18b20.c.
190{
192
194
196
197 for (
i = 0;
i < 8;
i++)
198 {
199
201 }
202}
void DS18B20_WriteByte(uint8_t byte)
Write one byte to DS18B20.
uint8_t DS18B20_ReadByte(void)
Read one byte from DS18B20.
__BIT DS18B20_Reset(void)
Reset DS18B20.
#define ONEWIRE_CMD_READROM
◆ DS18B20_ReadScratchpad()
| void DS18B20_ReadScratchpad |
( |
uint8_t * |
buf | ) |
|
Read SRAM scratchpad.
- Parameters
-
| buf | a 9-byte buffer, Byte 8 contains the CRC code for bytes 0 through 7 |
Definition at line 133 of file ds18b20.c.
134{
136
138
140
142
143
144 for (
i = 0;
i < 9;
i++)
145 {
146
148 }
149}
#define ONEWIRE_CMD_SKIPROM
#define ONEWIRE_CMD_RSCRATCHPAD
◆ DS18B20_ReadScratchpadFromAddr()
| void DS18B20_ReadScratchpadFromAddr |
( |
const uint8_t * |
addr, |
|
|
uint8_t * |
buf |
|
) |
| |
Read SRAM scratchpad from selected slave.
- Parameters
-
| addr | 64-bit ROM code |
| buf | a 9-byte buffer, Byte 8 contains the CRC code for bytes 0 through 7 |
Definition at line 224 of file ds18b20.c.
225{
227
229
231
233
234
235 for (
i = 0;
i < 9;
i++)
236 {
237
239 }
240}
void DS18B20_Select(const uint8_t *addr)
Select a slave on the bus.
◆ DS18B20_Reset()
| __BIT DS18B20_Reset |
( |
void |
| ) |
|
Reset DS18B20.
- Returns
- bit value
Definition at line 30 of file ds18b20.c.
31{
32 __BIT b;
33
34
38
41
43
45
46 return b;
47}
◆ DS18B20_Search()
Perform one ROM search.
- Parameters
-
| buff | 8-byte array for ROM bytes |
| stack | 8-byte array for search stack |
| split_point | deepest split point of last search |
- Returns
- new split point
Definition at line 242 of file ds18b20.c.
243{
245
246 split_point = (split_point == 0x00)? 0xFF : split_point;
247
249
251
252 while (len--)
253 {
254
257 if (pb && cb)
258 {
259 return 0;
260 }
261 else if (pb)
262 {
265
266 *(stack +
pos / 8) |= 0x01 << (
pos % 8);
267 }
268 else if (cb)
269 {
272
273 *(stack +
pos / 8) |= 0x01 << (
pos % 8);
274 }
275 else
276 {
277 if (split_point == 0xFF ||
pos > split_point)
278 {
279
282
283 *(stack +
pos / 8) &= ~(0x01 << (
pos % 8));
284
286 }
287 else if (
pos == split_point)
288 {
289
292
293 *(stack +
pos / 8) |= 0x01 << (
pos % 8);
294 }
295 else
296 {
298 }
299 }
301 }
302
303 while (split_point > 0 && *(stack + split_point / 8) >> (split_point % 8) & 0x01 == 0x01) split_point--;
304 return split_point;
305}
void DS18B20_WriteBit(__BIT b)
Write one bit to DS18B20.
#define ONEWIRE_CMD_SEARCHROM
◆ DS18B20_Select()
| void DS18B20_Select |
( |
const uint8_t * |
addr | ) |
|
Select a slave on the bus.
- Note
- Only the slave that exactly matches the 64-bit ROM code sequence will respond to the function command issued by the master; all other slaves on the bus will wait for a reset pulse.
- Parameters
-
Definition at line 204 of file ds18b20.c.
205{
208 while (len--)
209 {
211 }
212}
#define ONEWIRE_CMD_MATCHROM
◆ DS18B20_Start()
| void DS18B20_Start |
( |
const uint8_t * |
addr | ) |
|
Start conversion on selected slave.
- Parameters
-
Definition at line 214 of file ds18b20.c.
215{
216
218
220
222}
#define DS18B20_CMD_CONVERTTEMP
◆ DS18B20_StartAll()
| void DS18B20_StartAll |
( |
void |
| ) |
|
Start conversion on all slaves.
Definition at line 173 of file ds18b20.c.
◆ DS18B20_WriteBit()
| void DS18B20_WriteBit |
( |
__BIT |
b | ) |
|
Write one bit to DS18B20.
- Parameters
-
Definition at line 89 of file ds18b20.c.
90{
91 if (b)
92 {
93
97
98
100
101
104 }
105 else
106 {
107
111
112
114
115
118 }
119}
◆ DS18B20_WriteByte()
| void DS18B20_WriteByte |
( |
uint8_t |
byte | ) |
|
Write one byte to DS18B20.
- Parameters
-
Definition at line 121 of file ds18b20.c.
122{
124
126 {
127
129 byte >>= 1;
130 }
131}