Add check for valid Chip ID and fail early

Confused myself by plugging this into a BG base. It gave all the appearance of working, but the time was not counting up.
Turns out the library will happily talk to no device whatsoever and when you "set_time" it's stored in an C array and returned as if it came from the RTC.
pull/141/head
Phil Howard 2021-05-10 15:24:35 +01:00
rodzic 0a804a426b
commit 904bf657bb
3 zmienionych plików z 11 dodań i 1 usunięć

Wyświetl plik

@ -74,6 +74,12 @@ namespace pimoroni {
gpio_pull_up(interrupt);
}
uint8_t chip_id = 0;
read_bytes(RV3028_ID, &chip_id, 1);
if(chip_id != (RV3028_CHIP_ID | RV3028_VERSION)) {
return false;
}
return true;
}

Wyświetl plik

@ -84,6 +84,8 @@ Distributed as-is; no warranty is given.
//ID register
#define RV3028_ID 0x28
#define RV3028_CHIP_ID 0x30
#define RV3028_VERSION 0x03
//EEPROM Registers
#define EEPROM_Clkout_Register 0x35

Wyświetl plik

@ -12,7 +12,9 @@ int main() {
gpio_init(PICO_DEFAULT_LED_PIN);
gpio_set_dir(PICO_DEFAULT_LED_PIN, GPIO_OUT);
rtc.init();
if(!rtc.init()) {
printf("Init failed! Check your connections and i2c pin choices.\n");
}
// rtc.setup(false);
// Uncomment the below line on first run to set the RTC date and time to the program's compiler time