LibDriver HX711
Loading...
Searching...
No Matches
driver_hx711_read_test.c
Go to the documentation of this file.
1
37
39
40static hx711_handle_t gs_handle;
41
50uint8_t hx711_read_test(uint32_t times)
51{
52 uint8_t res;
53 uint32_t i;
54 int32_t raw;
55 double voltage_v;
56 hx711_info_t info;
57
58 /* link interface function */
70
71 /* get hx711 info */
72 res = hx711_info(&info);
73 if (res != 0)
74 {
75 hx711_interface_debug_print("hx711: get info failed.\n");
76
77 return 1;
78 }
79 else
80 {
81 /* print chip information */
82 hx711_interface_debug_print("hx711: chip is %s.\n", info.chip_name);
83 hx711_interface_debug_print("hx711: manufacturer is %s.\n", info.manufacturer_name);
84 hx711_interface_debug_print("hx711: interface is %s.\n", info.interface);
85 hx711_interface_debug_print("hx711: driver version is %d.%d.\n", info.driver_version / 1000, (info.driver_version % 1000) / 100);
86 hx711_interface_debug_print("hx711: min supply voltage is %0.1fV.\n", info.supply_voltage_min_v);
87 hx711_interface_debug_print("hx711: max supply voltage is %0.1fV.\n", info.supply_voltage_max_v);
88 hx711_interface_debug_print("hx711: max current is %0.2fmA.\n", info.max_current_ma);
89 hx711_interface_debug_print("hx711: max temperature is %0.1fC.\n", info.temperature_max);
90 hx711_interface_debug_print("hx711: min temperature is %0.1fC.\n", info.temperature_min);
91 }
92
93 /* start read test */
94 hx711_interface_debug_print("hx711: start read test.\n");
95 res = hx711_init(&gs_handle);
96 if (res != 0)
97 {
98 hx711_interface_debug_print("hx711: init failed.\n");
99
100 return 1;
101 }
102
103 /* start channel A 128 gain mode test */
104 hx711_interface_debug_print("hx711: channel A 128 gain mode test.\n");
106 if (res != 0)
107 {
108 hx711_interface_debug_print("hx711: set mode failed.\n");
109 (void)hx711_deinit(&gs_handle);
110
111 return 1;
112 }
113 for (i = 0; i < times; i++)
114 {
115 res = hx711_read(&gs_handle, (int32_t *)&raw, (double *)&voltage_v);
116 if (res != 0)
117 {
118 hx711_interface_debug_print("hx711: read failed.\n");
119 (void)hx711_deinit(&gs_handle);
120
121 return 1;
122 }
123 hx711_interface_debug_print("hx711: voltage is %fmV.\n", voltage_v * 1000.0);
124 hx711_interface_delay_us(1000L * 2000L);
125 }
126
127 /* start channel B 32 gain mode test */
128 hx711_interface_debug_print("hx711: channel B 32 gain mode test.\n");
130 if (res != 0)
131 {
132 hx711_interface_debug_print("hx711: set mode failed.\n");
133 (void)hx711_deinit(&gs_handle);
134
135 return 1;
136 }
137 for (i = 0; i < times; i++)
138 {
139 res = hx711_read(&gs_handle, (int32_t *)&raw, (double *)&voltage_v);
140 if (res != 0)
141 {
142 hx711_interface_debug_print("hx711: read failed.\n");
143 (void)hx711_deinit(&gs_handle);
144
145 return 1;
146 }
147 hx711_interface_debug_print("hx711: voltage is %fmV.\n", voltage_v * 1000.0);
148 hx711_interface_delay_us(1000L * 2000L);
149 }
150
151 /* start channel A 64 gain mode test */
152 hx711_interface_debug_print("hx711: channel A 64 gain mode test.\n");
154 if (res != 0)
155 {
156 hx711_interface_debug_print("hx711: set mode failed.\n");
157 (void)hx711_deinit(&gs_handle);
158
159 return 1;
160 }
161 for (i = 0; i < times; i++)
162 {
163 res = hx711_read(&gs_handle, (int32_t *)&raw, (double *)&voltage_v);
164 if (res != 0)
165 {
166 hx711_interface_debug_print("hx711: read failed.\n");
167 (void)hx711_deinit(&gs_handle);
168
169 return 1;
170 }
171 hx711_interface_debug_print("hx711: voltage is %fmV.\n", voltage_v * 1000.0);
172 hx711_interface_delay_us(1000L * 2000L);
173 }
174
175 /* finish read test */
176 hx711_interface_debug_print("hx711: finish read test.\n");
177 (void)hx711_deinit(&gs_handle);
178
179 return 0;
180}
driver hx711 read test header file
uint8_t hx711_deinit(hx711_handle_t *handle)
close the chip
struct hx711_handle_s hx711_handle_t
hx711 handle structure definition
uint8_t hx711_init(hx711_handle_t *handle)
initialize the chip
uint8_t hx711_set_mode(hx711_handle_t *handle, hx711_mode_t mode)
set the chip mode
struct hx711_info_s hx711_info_t
hx711 info structure definition
uint8_t hx711_info(hx711_info_t *info)
get chip's information
uint8_t hx711_read(hx711_handle_t *handle, int32_t *raw, double *voltage_v)
read the 24 bits raw ad from the chip
@ HX711_MODE_CHANNEL_A_GAIN_64
@ HX711_MODE_CHANNEL_A_GAIN_128
@ HX711_MODE_CHANNEL_B_GAIN_32
uint8_t hx711_interface_clock_write(uint8_t value)
interface clock write
uint8_t hx711_interface_bus_deinit(void)
interface bus deinit
uint8_t hx711_interface_bus_read(uint8_t *value)
interface bus read
uint8_t hx711_interface_clock_init(void)
interface clock init
uint8_t hx711_interface_bus_init(void)
interface bus init
void hx711_interface_enable_irq(void)
interface enable the interrupt
void hx711_interface_delay_us(uint32_t us)
interface delay us
void hx711_interface_debug_print(const char *const fmt,...)
interface print format data
uint8_t hx711_interface_clock_deinit(void)
interface clock deinit
void hx711_interface_disable_irq(void)
interface disable the interrupt
uint8_t hx711_read_test(uint32_t times)
read test
float temperature_max
float supply_voltage_max_v
uint32_t driver_version
float temperature_min
float max_current_ma
char manufacturer_name[32]
float supply_voltage_min_v
char interface[8]
char chip_name[32]