LibDriver DS18B20
Loading...
Searching...
No Matches
driver_ds18b20_search_test.c
Go to the documentation of this file.
1
37
39
40static ds18b20_handle_t gs_handle;
41
50{
51 uint8_t res, i, num;
52 uint8_t rom[3][8];
53 ds18b20_info_t info;
54
55 /* link interface function */
66
67 /* get ds18b20 info */
68 res = ds18b20_info(&info);
69 if (res != 0)
70 {
71 ds18b20_interface_debug_print("ds18b20: get info failed.\n");
72
73 return 1;
74 }
75 else
76 {
77 /* print ds18b20 info */
78 ds18b20_interface_debug_print("ds18b20: chip is %s.\n", info.chip_name);
79 ds18b20_interface_debug_print("ds18b20: manufacturer is %s.\n", info.manufacturer_name);
80 ds18b20_interface_debug_print("ds18b20: interface is %s.\n", info.interface);
81 ds18b20_interface_debug_print("ds18b20: driver version is %d.%d.\n", info.driver_version / 1000, (info.driver_version % 1000) / 100);
82 ds18b20_interface_debug_print("ds18b20: min supply voltage is %0.1fV.\n", info.supply_voltage_min_v);
83 ds18b20_interface_debug_print("ds18b20: max supply voltage is %0.1fV.\n", info.supply_voltage_max_v);
84 ds18b20_interface_debug_print("ds18b20: max current is %0.2fmA.\n", info.max_current_ma);
85 ds18b20_interface_debug_print("ds18b20: max temperature is %0.1fC.\n", info.temperature_max);
86 ds18b20_interface_debug_print("ds18b20: min temperature is %0.1fC.\n", info.temperature_min);
87 }
88
89 /* start search test */
90 ds18b20_interface_debug_print("ds18b20: start search test.\n");
91
92 /* ds18b20 init */
93 res = ds18b20_init(&gs_handle);
94 if (res != 0)
95 {
96 ds18b20_interface_debug_print("ds18b20: init failed.\n");
97
98 return 1;
99 }
100
101 /* search rom */
102 ds18b20_interface_debug_print("ds18b20: search rom...\n");
103
104 /* max find 3 */
105 num = 3;
106
107 /* search rom */
108 res = ds18b20_search_rom(&gs_handle, (uint8_t (*)[8])rom, (uint8_t *)&num);
109 if (res != 0)
110 {
111 ds18b20_interface_debug_print("ds18b20: search rom failed.\n");
112 (void)ds18b20_deinit(&gs_handle);
113
114 return 1;
115 }
116 ds18b20_interface_debug_print("ds18b20: find %d rom.\n", num);
117
118 /* print found rom */
119 for (i = 0; i < num; i++)
120 {
121 char cmd_buf[128];
122
123 memset(cmd_buf, 0, 128);
124 strcat(cmd_buf, "ds18b20: rom ");
125 for (uint8_t j=0; j<8; j++)
126 {
127 char hex_buf[6];
128
129 memset((char *)hex_buf, 0 ,sizeof(char)*6);
130 (void)snprintf((char *)hex_buf, 6, "%02X", rom[i][j]);
131 strcat((char *)cmd_buf, (char *)hex_buf);
132 }
133 ds18b20_interface_debug_print("%s.\n",cmd_buf);
134 }
135
136 /* search alarm rom */
137 ds18b20_interface_debug_print("ds18b20: search alarm rom...\n");
138
139 /* max find 3 */
140 num = 3;
141
142 /* search alarm rom */
143 res = ds18b20_search_alarm(&gs_handle, (uint8_t (*)[8])rom, (uint8_t *)&num);
144 if (res != 0)
145 {
146 ds18b20_interface_debug_print("ds18b20: search alarm rom failed.\n");
147 (void)ds18b20_deinit(&gs_handle);
148
149 return 1;
150 }
151
152 /* print found rom */
153 ds18b20_interface_debug_print("ds18b20: find %d alarm rom.\n", num);
154 for (i = 0; i < num; i++)
155 {
156 char cmd_buf[128];
157
158 memset(cmd_buf, 0, 128);
159 strcat(cmd_buf, "ds18b20: alarm rom ");
160 for (uint8_t j=0; j<8; j++)
161 {
162 char hex_buf[6];
163
164 memset((char *)hex_buf, 0 ,sizeof(char)*6);
165 (void)snprintf((char *)hex_buf, 6, "%02X", rom[i][j]);
166 strcat((char *)cmd_buf, (char *)hex_buf);
167 }
168 ds18b20_interface_debug_print("%s.\n",cmd_buf);
169 }
170
171 /* finish search test */
172 ds18b20_interface_debug_print("ds18b20: finish search test.\n");
173 (void)ds18b20_deinit(&gs_handle);
174
175 return 0;
176}
driver ds18b20 search test header file
uint8_t ds18b20_search_alarm(ds18b20_handle_t *handle, uint8_t(*rom)[8], uint8_t *num)
search the ds18b20 alarm rom
uint8_t ds18b20_search_rom(ds18b20_handle_t *handle, uint8_t(*rom)[8], uint8_t *num)
search the ds18b20 rom
uint8_t ds18b20_init(ds18b20_handle_t *handle)
initialize the chip
uint8_t ds18b20_info(ds18b20_info_t *info)
get chip's information
struct ds18b20_handle_s ds18b20_handle_t
ds18b20 handle structure definition
uint8_t ds18b20_deinit(ds18b20_handle_t *handle)
close the chip
struct ds18b20_info_s ds18b20_info_t
ds18b20 info structure definition
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
uint8_t ds18b20_search_test(void)
search test
uint32_t driver_version
char manufacturer_name[32]