File tree 1 file changed +24
-0
lines changed
tests/validation/i2c_master
1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change 5
5
#include < Arduino.h>
6
6
#include < unity.h>
7
7
#include < Wire.h>
8
+ #include < vector>
9
+ #include < algorithm>
8
10
9
11
/* DS1307 functions */
10
12
@@ -245,6 +247,27 @@ void test_api() {
245
247
Wire.flush ();
246
248
}
247
249
250
+ void scan_bus () {
251
+ std::vector<uint8_t > found_addresses;
252
+ uint8_t err;
253
+
254
+ for (uint8_t address = 1 ; address < 127 ; ++address) {
255
+ Wire.beginTransmission (address);
256
+ err = Wire.endTransmission ();
257
+ log_d (" Address: 0x%02X, Error: %d" , address, err);
258
+ if (err == 0 ) {
259
+ log_i (" Found device at address: 0x%02X" , address);
260
+ found_addresses.push_back (address);
261
+ } else if (address == DS1307_ADDR) {
262
+ TEST_FAIL_MESSAGE (" Failed to find DS1307" );
263
+ }
264
+ }
265
+
266
+ // Find DS1307_ADDR in found_addresses
267
+ auto it = std::find (found_addresses.begin (), found_addresses.end (), DS1307_ADDR);
268
+ TEST_ASSERT_TRUE (it != found_addresses.end ());
269
+ }
270
+
248
271
/* Main */
249
272
250
273
void setup () {
@@ -258,6 +281,7 @@ void setup() {
258
281
259
282
log_d (" Starting tests" );
260
283
UNITY_BEGIN ();
284
+ RUN_TEST (scan_bus);
261
285
RUN_TEST (rtc_set_time);
262
286
RUN_TEST (rtc_run_clock);
263
287
RUN_TEST (change_clock);
You can’t perform that action at this time.
0 commit comments