stm32-async-1wire 3.2.0
Non-blocking 1-Wire master for STM32 with DS18B20 temperature and DS2431 EEPROM drivers
Loading...
Searching...
No Matches
ds18b20.h
Go to the documentation of this file.
1
34
35#ifndef DS18B20_H
36#define DS18B20_H
37
38#include "ow_config.h"
39#include "ow_version.h"
40#include <stdint.h>
41
42#ifdef __cplusplus
43extern "C" {
44#endif
45
59
64
69#define DS18B20_TEMP_ERROR_GENERIC INT16_MIN
70#define DS18B20_TEMP_ERROR_NO_SENSOR (INT16_MIN + 1)
71#define DS18B20_TEMP_ERROR_CRC_FAIL (INT16_MIN + 2)
72
78#define DS18B20_FAMILY_CODE 0x28
79
83#define DS18B20_BITS_PER_BYTE 8
84
88#define DS18B20_ROM_BYTES 8
89
93#define DS18B20_SEARCH_ROM 0xF0
94
101#define DS18B20_ALARM_SEARCH 0xEC
102
106#define DS18B20_MATCH_ROM 0x55
107
111#define DS18B20_CONVERT_T 0x44
112
117#define DS18B20_READ_ROM 0x33
118
122#define DS18B20_READ_SCRATCHPAD 0xBE
123
128#define DS18B20_WRITE_SCRATCHPAD 0x4E
129
137#define DS18B20_COPY_SCRATCHPAD 0x48
138
143#define DS18B20_RECALL_EEPROM 0xB8
144
149#define DS18B20_READ_POWER_SUPPLY 0xB4
150
154#define DS18B20_RES_MIN 9
155
159#define DS18B20_RES_MAX 12
160
164#define DS18B20_RES_DEFAULT 12
165
172
176
187
194typedef uint8_t (*ds18b20_search_sink_t)(const uint8_t* rom);
195
201void ds18b20_search_start(ds18b20_search_sink_t sink, uint8_t max_devices);
202
208
214
218
234
242void ds18b20_alarm_search_start(ds18b20_search_sink_t sink, uint8_t max_devices);
243
249
255
259
274
284void ds18b20_set_resolution(uint8_t bits);
285
293
301
305
320
330void ds18b20_read_rom(uint8_t* rom);
331
337
350void ds18b20_set_alarm_thresholds(uint8_t th, uint8_t tl);
351
357
365void ds18b20_read_scratchpad(uint8_t* buf);
366
374
384
390
398
404
417void ds18b20_set_parasite(uint8_t parasite);
418
432
439
446
454
458
473
484
490
498const uint8_t* ds18b20_device_rom(uint8_t index);
499
504uint8_t ds18b20_scan_index(void);
505
509
514
521uint8_t ds18b20_crc8(const uint8_t* data, uint8_t len);
522
526void ds18b20_init(void);
527
538void ds18b20_poll(void);
539
554
572void ds18b20_select(const uint8_t* rom);
573
578void ds18b20_busy(unsigned action);
579
584void ds18b20_complete(int16_t temp);
585
589
590#ifdef __cplusplus
591}
592#endif
593
594#endif // DS18B20_H
ds18b20_state_t
DS18B20 driver state machine states.
Definition ds18b20.h:49
@ DS18B20_ST_START
Definition ds18b20.h:51
@ DS18B20_ST_READ
Definition ds18b20.h:56
@ DS18B20_ST_DECODE
Definition ds18b20.h:57
@ DS18B20_ST_CONVERT
Definition ds18b20.h:52
@ DS18B20_ST_REQUEST
Definition ds18b20.h:55
@ DS18B20_ST_WAIT
Definition ds18b20.h:53
@ DS18B20_ST_CONTINUE
Definition ds18b20.h:54
@ DS18B20_ST_IDLE
Definition ds18b20.h:50
void ds18b20_alarm_search_start(ds18b20_search_sink_t sink, uint8_t max_devices)
Start a non-blocking alarm search.
uint8_t ds18b20_alarm_search_count(void)
Number of DS18B20 devices found in alarm (valid once finished).
uint8_t ds18b20_alarm_search_poll(void)
Advance the non-blocking alarm search by one hardware operation.
uint8_t ds18b20_set_alarm_thresholds_poll(void)
Advance the non-blocking alarm threshold write.
uint8_t ds18b20_detect_parasite_poll(void)
Advance the non-blocking parasite-mode detection.
uint8_t ds18b20_read_rom_poll(void)
Advance the non-blocking Read ROM transaction.
uint8_t ds18b20_copy_scratchpad_poll(void)
Advance the non-blocking Copy Scratchpad transaction.
uint8_t ds18b20_recall_eeprom_poll(void)
Advance the non-blocking Recall EEPROM transaction.
void ds18b20_set_alarm_thresholds(uint8_t th, uint8_t tl)
Configure the alarm trigger thresholds TH and TL.
void ds18b20_read_rom(uint8_t *rom)
Read the 64-bit ROM of the (only) DS18B20 on the bus.
uint8_t ds18b20_parasite_mode(void)
Current parasite-power configuration of the driver.
void ds18b20_copy_scratchpad(void)
Copy the scratchpad into the EEPROM (non-volatile).
void ds18b20_detect_parasite(void)
Detect the bus wiring and configure parasite mode automatically.
void ds18b20_read_scratchpad(uint8_t *buf)
Read the 9-byte scratchpad (raw; includes TH, TL and the CRC).
void ds18b20_set_parasite(uint8_t parasite)
Declare the bus as parasite-powered.
uint8_t ds18b20_last_command_ok(void)
Result of the last completed command transaction.
uint8_t ds18b20_read_scratchpad_poll(void)
Advance the non-blocking raw scratchpad read.
void ds18b20_recall_eeprom(void)
Recall the EEPROM contents into the scratchpad.
void ds18b20_select(const uint8_t *rom)
Select which DS18B20 device to measure by its ROM address.
void ds18b20_busy(unsigned action)
Busy indicator callback (weak).
void ds18b20_poll(void)
Advance the state machine (non-blocking).
void ds18b20_init(void)
Initialize DS18B20 driver hardware and peripherals.
uint8_t ds18b20_crc8(const uint8_t *data, uint8_t len)
Calculate Dallas/Maxim CRC-8 over a byte buffer.
void ds18b20_complete(int16_t temp)
Measurement complete callback (weak).
void ds18b20_start_measure(void)
Start one measurement cycle (non-blocking).
uint8_t ds18b20_set_resolution_poll(void)
Advance the non-blocking resolution change by one hardware operation.
void ds18b20_set_resolution(uint8_t bits)
Start a non-blocking resolution change.
uint8_t ds18b20_get_resolution(void)
Current conversion resolution in bits.
const uint8_t * ds18b20_device_rom(uint8_t index)
ROM address of a discovered device.
void ds18b20_scan_start(void)
Arm simultaneous conversion of every discovered device.
uint8_t ds18b20_scan_index(void)
Index of the device whose result ds18b20_complete() just reported.
uint8_t ds18b20_device_count(void)
Number of DS18B20 devices stored by the driver.
uint8_t ds18b20_search_count(void)
Number of DS18B20 devices found (valid once the search finished).
uint8_t(* ds18b20_search_sink_t)(const uint8_t *rom)
Callback invoked for every DS18B20 found by the search.
Definition ds18b20.h:194
void ds18b20_search_start(ds18b20_search_sink_t sink, uint8_t max_devices)
Start a non-blocking device search.
uint8_t ds18b20_search_poll(void)
Advance the non-blocking device search by one hardware operation.
Central compile-time configuration for the 1-Wire stack.
Library version (semantic versioning).