LibDriver DS18B20
Loading...
Searching...
No Matches
driver_ds18b20_basic.c
Go to the documentation of this file.
1
37
39
40static ds18b20_handle_t gs_handle;
41
49uint8_t ds18b20_basic_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 skip rom mode */
75 res = ds18b20_set_mode(&gs_handle, DS18B20_MODE_SKIP_ROM);
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 /* set default resolution */
86 if (res != 0)
87 {
88 ds18b20_interface_debug_print("ds18b20: scratchpad set resolution failed.\n");
89 (void)ds18b20_deinit(&gs_handle);
90
91 return 1;
92 }
93
94 return 0;
95}
96
105uint8_t ds18b20_basic_read(float *temperature)
106{
107 int16_t raw;
108
109 /* read temperature */
110 if (ds18b20_read(&gs_handle, (int16_t *)&raw, temperature) != 0)
111 {
112 return 1;
113 }
114 else
115 {
116 return 0;
117 }
118}
119
128{
129 /* close ds18b20 */
130 if (ds18b20_deinit(&gs_handle) != 0)
131 {
132 return 1;
133 }
134 else
135 {
136 return 0;
137 }
138}
driver ds18b20 basic header file
uint8_t ds18b20_init(ds18b20_handle_t *handle)
initialize the chip
uint8_t ds18b20_read(ds18b20_handle_t *handle, int16_t *raw, float *temp)
read data from the chip
uint8_t ds18b20_scratchpad_set_resolution(ds18b20_handle_t *handle, ds18b20_resolution_t resolution)
set the resolution in the scratchpad
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_SKIP_ROM
#define DS18B20_BASIC_DEFAULT_RESOLUTION
ds18b20 basic example default definition
uint8_t ds18b20_basic_read(float *temperature)
basic example read
uint8_t ds18b20_basic_init(void)
basic example init
uint8_t ds18b20_basic_deinit(void)
basic example deinit
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