LibDriver BMP280
Loading...
Searching...
No Matches
driver_bmp280_read_test.c
Go to the documentation of this file.
1
36
38
39static bmp280_handle_t gs_handle;
40
51uint8_t bmp280_read_test(bmp280_interface_t interface, bmp280_address_t addr_pin, uint32_t times)
52{
53 uint8_t res;
54 uint32_t i;
55 uint32_t temperature_raw;
56 uint32_t pressure_raw;
57 float temperature_c;
58 float pressure_pa;
59 bmp280_info_t info;
60
61 /* link interface function */
73
74 /* get bmp280 info */
75 res = bmp280_info(&info);
76 if (res != 0)
77 {
78 bmp280_interface_debug_print("bmp280: get info failed.\n");
79
80 return 1;
81 }
82 else
83 {
84 /* print bmp280 */
85 bmp280_interface_debug_print("bmp280: chip is %s.\n", info.chip_name);
86 bmp280_interface_debug_print("bmp280: manufacturer is %s.\n", info.manufacturer_name);
87 bmp280_interface_debug_print("bmp280: interface is %s.\n", info.interface);
88 bmp280_interface_debug_print("bmp280: driver version is %d.%d.\n", info.driver_version / 1000, (info.driver_version % 1000) / 100);
89 bmp280_interface_debug_print("bmp280: min supply voltage is %0.1fV.\n", info.supply_voltage_min_v);
90 bmp280_interface_debug_print("bmp280: max supply voltage is %0.1fV.\n", info.supply_voltage_max_v);
91 bmp280_interface_debug_print("bmp280: max current is %0.2fmA.\n", info.max_current_ma);
92 bmp280_interface_debug_print("bmp280: max temperature is %0.1fC.\n", info.temperature_max);
93 bmp280_interface_debug_print("bmp280: min temperature is %0.1fC.\n", info.temperature_min);
94 }
95
96 /* start read test */
97 bmp280_interface_debug_print("bmp280: start read test.\n");
98
99 /* set interface */
100 res = bmp280_set_interface(&gs_handle, interface);
101 if (res != 0)
102 {
103 bmp280_interface_debug_print("bmp280: set interface failed.\n");
104
105 return 1;
106 }
107
108 /* set addr pin */
109 res = bmp280_set_addr_pin(&gs_handle, addr_pin);
110 if (res != 0)
111 {
112 bmp280_interface_debug_print("bmp280: set addr pin failed.\n");
113
114 return 1;
115 }
116
117 /* init */
118 res = bmp280_init(&gs_handle);
119 if (res != 0)
120 {
121 bmp280_interface_debug_print("bmp280: init failed.\n");
122
123 return 1;
124 }
125
126 /* set temperatue oversampling x2 */
128 if (res != 0)
129 {
130 bmp280_interface_debug_print("bmp280: set temperatue oversampling failed.\n");
131 (void)bmp280_deinit(&gs_handle);
132
133 return 1;
134 }
135
136 /* set pressure oversampling x16 */
138 if (res != 0)
139 {
140 bmp280_interface_debug_print("bmp280: set pressure oversampling failed.\n");
141 (void)bmp280_deinit(&gs_handle);
142
143 return 1;
144 }
145
146 /* set standby time 0.5ms */
148 if (res != 0)
149 {
150 bmp280_interface_debug_print("bmp280: set standby time failed.\n");
151 (void)bmp280_deinit(&gs_handle);
152
153 return 1;
154 }
155
156 /* set filter 16 */
157 res = bmp280_set_filter(&gs_handle, BMP280_FILTER_COEFF_16);
158 if (res != 0)
159 {
160 bmp280_interface_debug_print("bmp280: set filter failed.\n");
161 (void)bmp280_deinit(&gs_handle);
162
163 return 1;
164 }
165
166 /* set normal mode */
167 res = bmp280_set_mode(&gs_handle, BMP280_MODE_NORMAL);
168 if (res != 0)
169 {
170 bmp280_interface_debug_print("bmp280: set mode failed.\n");
171 (void)bmp280_deinit(&gs_handle);
172
173 return 1;
174 }
175
176 /* delay 1000ms */
178
179 /* continue read test */
180 bmp280_interface_debug_print("bmp280: continue read test.\n");
181
182 /* loop */
183 for (i = 0; i < times; i++)
184 {
185 /* read temperature pressure */
186 res = bmp280_read_temperature_pressure(&gs_handle, &temperature_raw, &temperature_c,
187 &pressure_raw, &pressure_pa);
188 if (res != 0)
189 {
190 bmp280_interface_debug_print("bmp280: read temperature pressure failed.\n");
191 (void)bmp280_deinit(&gs_handle);
192
193 return 1;
194 }
195
196 /* delay 1000ms */
198
199 /* output */
200 bmp280_interface_debug_print("bmp280: temperature is %0.2fC.\n", temperature_c);
201 bmp280_interface_debug_print("bmp280: pressure is %0.2fpa.\n", pressure_pa);
202 }
203
204 /* set sleep mode */
205 res = bmp280_set_mode(&gs_handle, BMP280_MODE_SLEEP);
206 if (res != 0)
207 {
208 bmp280_interface_debug_print("bmp280: set mode failed.\n");
209 (void)bmp280_deinit(&gs_handle);
210
211 return 1;
212 }
213
214 /* delay 1000ms */
216
217 /* shot read test */
218 bmp280_interface_debug_print("bmp280: shot read test.\n");
219
220 /* loop */
221 for (i = 0; i < times; i++)
222 {
223 /* read temperature pressure */
224 res = bmp280_read_temperature_pressure(&gs_handle, &temperature_raw, &temperature_c,
225 &pressure_raw, &pressure_pa);
226 if (res != 0)
227 {
228 bmp280_interface_debug_print("bmp280: read temperature pressure failed.\n");
229 (void)bmp280_deinit(&gs_handle);
230
231 return 1;
232 }
233
234 /* delay 1000ms */
236
237 /* output */
238 bmp280_interface_debug_print("bmp280: temperature is %0.2fC.\n", temperature_c);
239 bmp280_interface_debug_print("bmp280: pressure is %0.2fpa.\n", pressure_pa);
240 }
241
242 /* finish read test */
243 bmp280_interface_debug_print("bmp280: finish read test.\n");
244 (void)bmp280_deinit(&gs_handle);
245
246 return 0;
247}
driver bmp280 read test header file
uint8_t bmp280_set_filter(bmp280_handle_t *handle, bmp280_filter_t filter)
set filter
uint8_t bmp280_info(bmp280_info_t *info)
get chip's information
uint8_t bmp280_set_mode(bmp280_handle_t *handle, bmp280_mode_t mode)
set mode
uint8_t bmp280_read_temperature_pressure(bmp280_handle_t *handle, uint32_t *temperature_raw, float *temperature_c, uint32_t *pressure_raw, float *pressure_pa)
read the temperature and pressure data
uint8_t bmp280_deinit(bmp280_handle_t *handle)
close the chip
bmp280_interface_t
bmp280 interface enumeration definition
uint8_t bmp280_set_interface(bmp280_handle_t *handle, bmp280_interface_t interface)
set the interface
uint8_t bmp280_set_pressure_oversampling(bmp280_handle_t *handle, bmp280_oversampling_t oversampling)
set pressure oversampling
uint8_t bmp280_set_addr_pin(bmp280_handle_t *handle, bmp280_address_t addr_pin)
set the iic address pin
bmp280_address_t
bmp280 address enumeration definition
struct bmp280_info_s bmp280_info_t
bmp280 information structure definition
uint8_t bmp280_set_standby_time(bmp280_handle_t *handle, bmp280_standby_time_t standby_time)
set standby time
uint8_t bmp280_init(bmp280_handle_t *handle)
initialize the chip
struct bmp280_handle_s bmp280_handle_t
bmp280 handle structure definition
uint8_t bmp280_set_temperatue_oversampling(bmp280_handle_t *handle, bmp280_oversampling_t oversampling)
set temperatue oversampling
@ BMP280_FILTER_COEFF_16
@ BMP280_MODE_SLEEP
@ BMP280_MODE_NORMAL
@ BMP280_OVERSAMPLING_x16
@ BMP280_OVERSAMPLING_x2
@ BMP280_STANDBY_TIME_0P5_MS
uint8_t bmp280_interface_spi_read(uint8_t reg, uint8_t *buf, uint16_t len)
interface spi bus read
uint8_t bmp280_interface_iic_write(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
interface iic bus write
uint8_t bmp280_interface_spi_init(void)
interface spi bus init
uint8_t bmp280_interface_iic_read(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
interface iic bus read
uint8_t bmp280_interface_iic_deinit(void)
interface iic bus deinit
uint8_t bmp280_interface_spi_write(uint8_t reg, uint8_t *buf, uint16_t len)
interface spi bus write
void bmp280_interface_delay_ms(uint32_t ms)
interface delay ms
uint8_t bmp280_interface_iic_init(void)
interface iic bus init
void bmp280_interface_debug_print(const char *const fmt,...)
interface print format data
uint8_t bmp280_interface_spi_deinit(void)
interface spi bus deinit
uint8_t bmp280_read_test(bmp280_interface_t interface, bmp280_address_t addr_pin, uint32_t times)
read test
float supply_voltage_max_v
uint32_t driver_version
char manufacturer_name[32]
float supply_voltage_min_v
char chip_name[32]