Skip to content

Commit 51d4958

Browse files
committed
ci(i2c): Make i2c test more reliable
1 parent ff3dd5b commit 51d4958

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

tests/validation/i2c_master/i2c_master.ino

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ void ds1307_get_time(uint8_t *sec, uint8_t *min, uint8_t *hour, uint8_t *day, ui
108108
void ds1307_set_time(uint8_t sec, uint8_t min, uint8_t hour, uint8_t day, uint8_t month, uint16_t year) {
109109
Wire.beginTransmission(DS1307_ADDR);
110110
Wire.write(0x00);
111-
Wire.write(DEC2BCD(sec));
111+
Wire.write(DEC2BCD(sec) | 0x80); //Set halt bit to stop clock
112112
Wire.write(DEC2BCD(min));
113113
Wire.write(DEC2BCD(hour));
114114
Wire.write(DEC2BCD(0)); //Ignore day of week
@@ -212,6 +212,22 @@ void change_clock() {
212212
TEST_ASSERT_EQUAL(start_day, read_day);
213213
TEST_ASSERT_EQUAL(start_month, read_month);
214214
TEST_ASSERT_EQUAL(start_year, read_year);
215+
216+
//Run clock for 5 seconds to check that we can write
217+
ds1307_start();
218+
delay(5000);
219+
ds1307_stop();
220+
221+
//Get time
222+
ds1307_get_time(&read_sec, &read_min, &read_hour, &read_day, &read_month, &read_year);
223+
224+
//Check time
225+
TEST_ASSERT_NOT_EQUAL(start_sec, read_sec); //Seconds should have changed
226+
TEST_ASSERT_EQUAL(start_min, read_min);
227+
TEST_ASSERT_EQUAL(start_hour, read_hour);
228+
TEST_ASSERT_EQUAL(start_day, read_day);
229+
TEST_ASSERT_EQUAL(start_month, read_month);
230+
TEST_ASSERT_EQUAL(start_year, read_year);
215231
}
216232

217233
void swap_pins() {

0 commit comments

Comments
 (0)