File tree 1 file changed +22
-0
lines changed
tests/validation/i2c_master
1 file changed +22
-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,25 @@ void test_api() {
245
247
Wire.flush ();
246
248
}
247
249
250
+ void scan_bus () {
251
+ std::vector<uint8_t > found_addresses;
252
+ std::vector<uint8_t > expected_addresses = {DS1307_ADDR};
253
+ uint8_t err;
254
+
255
+ for (uint8_t address = 1 ; address < 127 ; ++address) {
256
+ Wire.beginTransmission (address);
257
+ err = Wire.endTransmission ();
258
+ log_d (" Address: %d, Error: %d" , address, err);
259
+ if (err == 0 ) {
260
+ found_addresses.push_back (address);
261
+ } else if (address == DS1307_ADDR) {
262
+ TEST_FAIL_MESSAGE (" Failed to find DS1307" );
263
+ }
264
+ }
265
+
266
+ TEST_ASSERT_TRUE (found_addresses == expected_addresses);
267
+ }
268
+
248
269
/* Main */
249
270
250
271
void setup () {
@@ -258,6 +279,7 @@ void setup() {
258
279
259
280
log_d (" Starting tests" );
260
281
UNITY_BEGIN ();
282
+ RUN_TEST (scan_bus);
261
283
RUN_TEST (rtc_set_time);
262
284
RUN_TEST (rtc_run_clock);
263
285
RUN_TEST (change_clock);
You can’t perform that action at this time.
0 commit comments