LibDriver DS18B20
Loading...
Searching...
No Matches
driver_ds18b20_match.c
Go to the documentation of this file.
1
37
39
40static ds18b20_handle_t gs_handle;
41
49uint8_t ds18b20_match_init(void)
50{
51 uint8_t res;
52
53 /* link interface function */
64
65 /* ds18b20 init */
66 res = ds18b20_init(&gs_handle);
67 if (res != 0)
68 {
69 ds18b20_interface_debug_print("ds18b20: init failed.\n");
70
71 return 1;
72 }
73
74 /* set match rom mode */
76 if (res != 0)
77 {
78 ds18b20_interface_debug_print("ds18b20: set mode failed.\n");
79 (void)ds18b20_deinit(&gs_handle);
80
81 return 1;
82 }
83
84 return 0;
85}
86
96uint8_t ds18b20_match_read(uint8_t rom[8], float *temperature)
97{
98 uint8_t res;
99 int16_t raw;
100
101 /* set rom */
102 res = ds18b20_set_rom(&gs_handle, (uint8_t *)rom);
103 if (res != 0)
104 {
105 return 1;
106 }
107
108 /* read temperature */
109 if (ds18b20_read(&gs_handle, (int16_t *)&raw, temperature) != 0)
110 {
111 return 1;
112 }
113 else
114 {
115 return 0;
116 }
117}
118
127{
128 /* ds18b20 close */
129 if (ds18b20_deinit(&gs_handle) != 0)
130 {
131 return 1;
132 }
133 else
134 {
135 return 0;
136 }
137}
driver ds18b20 match header file
uint8_t ds18b20_init(ds18b20_handle_t *handle)
initialize the chip
uint8_t ds18b20_set_rom(ds18b20_handle_t *handle, uint8_t rom[8])
set the handle rom
uint8_t ds18b20_read(ds18b20_handle_t *handle, int16_t *raw, float *temp)
read data from the chip
struct ds18b20_handle_s ds18b20_handle_t
ds18b20 handle structure definition
uint8_t ds18b20_deinit(ds18b20_handle_t *handle)
close the chip
uint8_t ds18b20_set_mode(ds18b20_handle_t *handle, ds18b20_mode_t mode)
set the chip mode
@ DS18B20_MODE_MATCH_ROM
uint8_t ds18b20_match_read(uint8_t rom[8], float *temperature)
match example read
uint8_t ds18b20_match_deinit(void)
match example deinit
uint8_t ds18b20_match_init(void)
match example init
uint8_t ds18b20_interface_deinit(void)
interface bus deinit
void ds18b20_interface_delay_ms(uint32_t ms)
interface delay ms
uint8_t ds18b20_interface_write(uint8_t value)
interface bus write
uint8_t ds18b20_interface_init(void)
interface bus init
uint8_t ds18b20_interface_read(uint8_t *value)
interface bus read
void ds18b20_interface_debug_print(const char *const fmt,...)
interface print format data
void ds18b20_interface_disable_irq(void)
interface disable the interrupt
void ds18b20_interface_enable_irq(void)
interface enable the interrupt
void ds18b20_interface_delay_us(uint32_t us)
interface delay us