LibDriver BMP180
Loading...
Searching...
No Matches
driver_bmp180_register_test.c
Go to the documentation of this file.
1
37
39
40static bmp180_handle_t gs_handle;
41
50{
51 uint8_t res;
52 bmp180_mode_t mode;
53 bmp180_info_t info;
54
55 /* link interface function */
63
64 /* get bmp180 info */
65 res = bmp180_info(&info);
66 if (res != 0)
67 {
68 bmp180_interface_debug_print("bmp180: get info failed.\n");
69
70 return 1;
71 }
72 else
73 {
74 /* print bmp180 */
75 bmp180_interface_debug_print("bmp180: chip is %s.\n", info.chip_name);
76 bmp180_interface_debug_print("bmp180: manufacturer is %s.\n", info.manufacturer_name);
77 bmp180_interface_debug_print("bmp180: interface is %s.\n", info.interface);
78 bmp180_interface_debug_print("bmp180: driver version is %d.%d.\n", info.driver_version / 1000, (info.driver_version % 1000) / 100);
79 bmp180_interface_debug_print("bmp180: min supply voltage is %0.1fV.\n", info.supply_voltage_min_v);
80 bmp180_interface_debug_print("bmp180: max supply voltage is %0.1fV.\n", info.supply_voltage_max_v);
81 bmp180_interface_debug_print("bmp180: max current is %0.2fmA.\n", info.max_current_ma);
82 bmp180_interface_debug_print("bmp180: max temperature is %0.1fC.\n", info.temperature_max);
83 bmp180_interface_debug_print("bmp180: min temperature is %0.1fC.\n", info.temperature_min);
84 }
85
86 /* start register test */
87 bmp180_interface_debug_print("bmp180: start register test.\n");
88 res = bmp180_init(&gs_handle);
89 if (res != 0)
90 {
91 bmp180_interface_debug_print("bmp180: init failed.\n");
92
93 return 1;
94 }
95
96 /* bmp180_set_mode/bmp180_get_mode test */
97 bmp180_interface_debug_print("bmp180: bmp180_set_mode/bmp180_get_mode test.\n");
98
99 /* set BMP180_MODE_ULTRA_LOW */
100 res = bmp180_set_mode(&gs_handle, BMP180_MODE_ULTRA_LOW);
101 if (res != 0)
102 {
103 bmp180_interface_debug_print("bmp180: set mode failed.\n");
104 (void)bmp180_deinit(&gs_handle);
105
106 return 1;
107 }
108 bmp180_interface_debug_print("bmp180: set ultra low mode.\n");
109 res = bmp180_get_mode(&gs_handle, &mode);
110 if (res != 0)
111 {
112 bmp180_interface_debug_print("bmp180: get mode failed.\n");
113 (void)bmp180_deinit(&gs_handle);
114
115 return 1;
116 }
117 bmp180_interface_debug_print("bmp180: check mode %s.\n", mode == BMP180_MODE_ULTRA_LOW ? "ok" : "error");
118
119 /* set BMP180_MODE_STANDARD */
120 res = bmp180_set_mode(&gs_handle, BMP180_MODE_STANDARD);
121 if (res != 0)
122 {
123 bmp180_interface_debug_print("bmp180: set mode failed.\n");
124 (void)bmp180_deinit(&gs_handle);
125
126 return 1;
127 }
128 bmp180_interface_debug_print("bmp180: set standard mode.\n");
129 res = bmp180_get_mode(&gs_handle, &mode);
130 if (res != 0)
131 {
132 bmp180_interface_debug_print("bmp180: get mode failed.\n");
133 (void)bmp180_deinit(&gs_handle);
134
135 return 1;
136 }
137 bmp180_interface_debug_print("bmp180: check mode %s.\n", mode == BMP180_MODE_STANDARD ? "ok" : "error");
138
139 /* set BMP180_MODE_HIGH */
140 res = bmp180_set_mode(&gs_handle, BMP180_MODE_HIGH);
141 if (res != 0)
142 {
143 bmp180_interface_debug_print("bmp180: set mode failed.\n");
144 (void)bmp180_deinit(&gs_handle);
145
146 return 1;
147 }
148 bmp180_interface_debug_print("bmp180: set high mode.\n");
149 res = bmp180_get_mode(&gs_handle, &mode);
150 if (res != 0)
151 {
152 bmp180_interface_debug_print("bmp180: get mode failed.\n");
153 (void)bmp180_deinit(&gs_handle);
154
155 return 1;
156 }
157 bmp180_interface_debug_print("bmp180: check mode %s.\n", mode == BMP180_MODE_HIGH ? "ok" : "error");
158
159 /* set BMP180_MODE_ULTRA_HIGH */
160 res = bmp180_set_mode(&gs_handle, BMP180_MODE_ULTRA_HIGH);
161 if (res != 0)
162 {
163 bmp180_interface_debug_print("bmp180: set mode failed.\n");
164 (void)bmp180_deinit(&gs_handle);
165
166 return 1;
167 }
168 bmp180_interface_debug_print("bmp180: set ultra high mode.\n");
169 res = bmp180_get_mode(&gs_handle, &mode);
170 if (res != 0)
171 {
172 bmp180_interface_debug_print("bmp180: get mode failed.\n");
173 (void)bmp180_deinit(&gs_handle);
174
175 return 1;
176 }
177 bmp180_interface_debug_print("bmp180: check mode %s.\n", mode == BMP180_MODE_ULTRA_HIGH ? "ok" : "error");
178
179 /* finish register test */
180 bmp180_interface_debug_print("bmp180: finish register test.\n");
181 (void)bmp180_deinit(&gs_handle);
182
183 return 0;
184}
driver bmp180 register test header file
uint8_t bmp180_deinit(bmp180_handle_t *handle)
close the chip
struct bmp180_info_s bmp180_info_t
bmp180 information structure definition
bmp180_mode_t
bmp180 mode enumeration definition
struct bmp180_handle_s bmp180_handle_t
bmp180 handle structure definition
uint8_t bmp180_init(bmp180_handle_t *handle)
initialize the chip
uint8_t bmp180_info(bmp180_info_t *info)
get chip's information
uint8_t bmp180_get_mode(bmp180_handle_t *handle, bmp180_mode_t *mode)
get the measurement mode
uint8_t bmp180_set_mode(bmp180_handle_t *handle, bmp180_mode_t mode)
set the measurement mode
@ BMP180_MODE_ULTRA_LOW
@ BMP180_MODE_STANDARD
@ BMP180_MODE_HIGH
@ BMP180_MODE_ULTRA_HIGH
void bmp180_interface_delay_ms(uint32_t ms)
interface delay ms
uint8_t bmp180_interface_iic_deinit(void)
interface iic bus deinit
uint8_t bmp180_interface_iic_init(void)
interface iic bus init
uint8_t bmp180_interface_iic_write(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
interface iic bus write
void bmp180_interface_debug_print(const char *const fmt,...)
interface print format data
uint8_t bmp180_interface_iic_read(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
interface iic bus read
uint8_t bmp180_register_test(void)
register test
float supply_voltage_max_v
uint32_t driver_version
char manufacturer_name[32]
float supply_voltage_min_v
char chip_name[32]