this post may seems duplicate as Windows IoT and DS3231 RTC clock but it doesn't seem to work for me. i don't have experience using i2c in this environment.
My intended functionality is,
- at startup check if there is any network connectivity to update system clock
- if offline the system will read
datetime
fromDS3231
and update the systemdatetime
- any changes of
datetime
fromdatepicker
ortimepicker
it will updateDS3231
My problem is
- How to check for network availibility to update system clock.
to read from
DS3231
usingi1cdevice.writeread
requires towrite
read address
separately? does thei2c
automatically reads all the data untilstop
bit is received or i have to setup a counter ?private const byte DS3231_I2C_WADDR = 0xD0; private const byte DS3231_I2C_RADDR = 0xD1; private I2cDevice DS3231_RTC; byte[] i2CWriteBuffer; byte[] i2CReadBuffer; private async void Read_DS3231_RTC() { var settings = new I2cConnectionSettings(DS3231_I2C_RADDR); settings.BusSpeed = I2cBusSpeed.StandardMode; var controller = await I2cController.GetDefaultAsync(); DS3231_RTC = controller.GetDevice(settings); try { DS3231_RTC.WriteRead(new byte[] { DS3231_I2C_RADDR }, i2CReadBuffer); } catch (Exception e) { StatusMessage.Text = "Fail to Init I2C:" + e.Message; return; } }
to write to
DS3231
there aredateicker
&timepicker
for time setting upon setting thedatetime
how could I update toDS3231
private void DatePicker_DateChanged(object sender, DatePickerValueChangedEventArgs e) { DateTimeSettings.SetSystemDateTime(e.NewDate.UtcDateTime); SetTime_DS3231(); } private void TimePicker_TimeChanged(object sender, TimePickerValueChangedEventArgs e) { var currentDate = DateTime.Now.ToUniversalTime(); var newDateTime = new DateTime(currentDate.Year, currentDate.Month, currentDate.Day, e.NewTime.Hours, e.NewTime.Minutes, e.NewTime.Seconds); DateTimeSettings.SetSystemDateTime(newDateTime); }
Thank you.