LibDriver HX711
Loading...
Searching...
No Matches
driver_hx711_register_test.c
Go to the documentation of this file.
1
37
39
40static hx711_handle_t gs_handle;
41
50{
51 uint8_t res;
52 hx711_mode_t mode;
53 hx711_info_t info;
54
55 /* link interface function */
67
68 /* get chip information */
69 res = hx711_info(&info);
70 if (res != 0)
71 {
72 hx711_interface_debug_print("hx711: get info failed.\n");
73
74 return 1;
75 }
76 else
77 {
78 /* print chip information */
79 hx711_interface_debug_print("hx711: chip is %s.\n", info.chip_name);
80 hx711_interface_debug_print("hx711: manufacturer is %s.\n", info.manufacturer_name);
81 hx711_interface_debug_print("hx711: interface is %s.\n", info.interface);
82 hx711_interface_debug_print("hx711: driver version is %d.%d.\n", info.driver_version / 1000, (info.driver_version % 1000) / 100);
83 hx711_interface_debug_print("hx711: min supply voltage is %0.1fV.\n", info.supply_voltage_min_v);
84 hx711_interface_debug_print("hx711: max supply voltage is %0.1fV.\n", info.supply_voltage_max_v);
85 hx711_interface_debug_print("hx711: max current is %0.2fmA.\n", info.max_current_ma);
86 hx711_interface_debug_print("hx711: max temperature is %0.1fC.\n", info.temperature_max);
87 hx711_interface_debug_print("hx711: min temperature is %0.1fC.\n", info.temperature_min);
88 }
89
90 /* start register test */
91 hx711_interface_debug_print("hx711: start register test.\n");
92
93 /* hx711 init */
94 res = hx711_init(&gs_handle);
95 if (res != 0)
96 {
97 hx711_interface_debug_print("hx711: init failed.\n");
98
99 return 1;
100 }
101
102 /* hx711_set_mode/hx711_get_mode test */
103 hx711_interface_debug_print("hx711: hx711_set_mode/hx711_get_mode test.\n");
104
105 /* set CHANNEL_A_GAIN_128 */
107 if (res != 0)
108 {
109 hx711_interface_debug_print("hx711: set mode failed.\n");
110 (void)hx711_deinit(&gs_handle);
111
112 return 1;
113 }
114 hx711_interface_debug_print("hx711: set channel a gain 128 mode.\n");
115 res = hx711_get_mode(&gs_handle, &mode);
116 if (res != 0)
117 {
118 hx711_interface_debug_print("hx711: get mode failed.\n");
119 (void)hx711_deinit(&gs_handle);
120
121 return 1;
122 }
123 hx711_interface_debug_print("hx711: check mode %s.\n", mode==HX711_MODE_CHANNEL_A_GAIN_128?"ok":"error");
124
125 /* set CHANNEL_B_GAIN_32 */
127 if (res != 0)
128 {
129 hx711_interface_debug_print("hx711: set mode failed.\n");
130 (void)hx711_deinit(&gs_handle);
131
132 return 1;
133 }
134 hx711_interface_debug_print("hx711: set channel b gain 32 mode.\n");
135 res = hx711_get_mode(&gs_handle, &mode);
136 if (res != 0)
137 {
138 hx711_interface_debug_print("hx711: get mode failed.\n");
139 (void)hx711_deinit(&gs_handle);
140
141 return 1;
142 }
143 hx711_interface_debug_print("hx711: check mode %s.\n", mode==HX711_MODE_CHANNEL_B_GAIN_32?"ok":"error");
144
145 /* set CHANNEL_A_GAIN_64 */
147 if (res != 0)
148 {
149 hx711_interface_debug_print("hx711: set mode failed.\n");
150 (void)hx711_deinit(&gs_handle);
151
152 return 1;
153 }
154 hx711_interface_debug_print("hx711: set channel a gain 64 mode.\n");
155 res = hx711_get_mode(&gs_handle, &mode);
156 if (res != 0)
157 {
158 hx711_interface_debug_print("hx711: get mode failed.\n");
159 (void)hx711_deinit(&gs_handle);
160
161 return 1;
162 }
163 hx711_interface_debug_print("hx711: check mode %s.\n", mode==HX711_MODE_CHANNEL_A_GAIN_64?"ok":"error");
164
165 /* finish register test */
166 hx711_interface_debug_print("hx711: finish register test.\n");
167 (void)hx711_deinit(&gs_handle);
168
169 return 0;
170}
driver hx711 register test header file
uint8_t hx711_deinit(hx711_handle_t *handle)
close the chip
uint8_t hx711_get_mode(hx711_handle_t *handle, hx711_mode_t *mode)
get the chip mode
hx711_mode_t
hx711 mode enumeration definition
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
@ 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_register_test(void)
register 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]