nanoFramework.Iot.Device.Mcp7940xx
1.0.642
Prefix Reserved
dotnet add package nanoFramework.Iot.Device.Mcp7940xx --version 1.0.642
NuGet\Install-Package nanoFramework.Iot.Device.Mcp7940xx -Version 1.0.642
<PackageReference Include="nanoFramework.Iot.Device.Mcp7940xx" Version="1.0.642" />
paket add nanoFramework.Iot.Device.Mcp7940xx --version 1.0.642
#r "nuget: nanoFramework.Iot.Device.Mcp7940xx, 1.0.642"
// Install nanoFramework.Iot.Device.Mcp7940xx as a Cake Addin #addin nuget:?package=nanoFramework.Iot.Device.Mcp7940xx&version=1.0.642 // Install nanoFramework.Iot.Device.Mcp7940xx as a Cake Tool #tool nuget:?package=nanoFramework.Iot.Device.Mcp7940xx&version=1.0.642
Mcp7940xx/MCP79400/MCP79401/MCP79402 - I2C Real-Time Clock/Calendar with SRAM
The MCP7940M Real-Time Clock/Calendar (RTCC) tracks time using internal counters for hours, minutes, seconds, days, months, years, and day of week. Alarms can be configured on all counters up to and including months.
Documentation
Original code was written for ESP32
Usage
Important: Make sure you properly setup the I2C pins for ESP32 before creating the I2cDevice
. For this, make sure you install the nanoFramework.Hardware.Esp32
NuGet and use the Configuration
class to configure the pins:
//////////////////////////////////////////////////////////////////////
// when connecting to an ESP32 device, need to configure the I2C GPIOs used for the bus.
Configuration.SetPinFunction(Gpio.IO21, DeviceFunction.I2C1_DATA);
Configuration.SetPinFunction(Gpio.IO22, DeviceFunction.I2C1_CLOCK);
For other devices like STM32, please make sure you're using the preset pins for the I2C bus you want to use.
The following example demonstrates using the clock and alarm functions of the Mcp7940xx family.
using System;
using System.Device.I2c;
using System.Diagnostics;
using System.Threading;
using Iot.Device.Mcp7940xx;
using nanoFramework.Hardware.Esp32;
// Setup ESP32 I2C port.
Configuration.SetPinFunction(Gpio.IO21, DeviceFunction.I2C1_DATA);
Configuration.SetPinFunction(Gpio.IO22, DeviceFunction.I2C1_CLOCK);
// Setup Mcp7940m device.
I2cConnectionSettings i2cSettings = new I2cConnectionSettings(1, Mcp7940m.DefaultI2cAddress);
I2cDevice i2cDevice = new I2cDevice(i2cSettings);
Mcp7940m clock = new Mcp7940m(i2cDevice, ClockSource.ExternalCrystal);
clock.SetTime(DateTime.UtcNow);
clock.StartClock(true);
// Set Alarm 1 to trigger on the 4th minute of every hour.
Mcp7940m.Alarm alarm1 = new Mcp7940m.Alarm(AlarmMatchMode.Minute, minute: 4);
clock.SetAlarm1(alarm1);
clock.EnableAlarm1();
Debug.WriteLine($"Alarm 1 : {clock.GetAlarm1()}");
// Set Alarm 2 to trigger every Wednesday.
Mcp7940m.Alarm alarm2 = new Mcp7940m.Alarm(AlarmMatchMode.DayOfWeek, dayOfWeek: DayOfWeek.Wednesday);
clock.SetAlarm2(alarm2);
clock.EnableAlarm2();
Debug.WriteLine($"Alarm 2 : {clock.GetAlarm2()}");
while (true)
{
// Get current time.
DateTime currentTime = clock.GetTime();
Debug.WriteLine($"Time: {currentTime.ToString("yyyy/MM/dd HH:mm:ss")}");
// Check if alarm 1 has triggered.
if (clock.IsTriggeredAlarm1)
{
Debug.WriteLine("[ALARM 1]");
// Clear alarm 1 flag.
clock.ResetAlarm1();
}
// Check if alarm 2 has triggered.
if (clock.IsTriggeredAlarm2)
{
Debug.WriteLine("[ALARM 2]");
// Clear alarm 2 flag.
clock.ResetAlarm2();
// Turn off alarm 2.
clock.DisableAlarm2();
}
// Wait for one second.
Thread.Sleep(1000);
}
The following example demonstrates accessing the protected EEPROM and EUI of the Mcp79401.
using System;
using System.Device.I2c;
using System.Diagnostics;
using System.Threading;
using Iot.Device.Mcp7940xx;
using nanoFramework.Hardware.Esp32;
// Setup ESP32 I2C port.
Configuration.SetPinFunction(Gpio.IO21, DeviceFunction.I2C1_DATA);
Configuration.SetPinFunction(Gpio.IO22, DeviceFunction.I2C1_CLOCK);
// Setup Mcp79401 eeprom device.
I2cConnectionSettings i2cSettings = new I2cConnectionSettings(1, Mcp79401.Eeprom.DefaultI2cAddress);
I2cDevice i2cDevice = new I2cDevice(i2cSettings);
Mcp79401.Eeprom eeprom = new Mcp79401.Eeprom(i2cDevice);
// Read and write to EEPROM.
byte byteAddress = 0;
eeprom.WriteByte(byteAddress, 0xA6);
byte value = eeprom.ReadByte(byteAddress);
// Read EUI from EEPROM.
byte[] eui = eeprom.ReadEui();
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET Framework | net is compatible. |
-
- nanoFramework.CoreLibrary (>= 1.15.5)
- nanoFramework.Iot.Device.Common.NumberHelper (>= 1.2.693)
- nanoFramework.Runtime.Events (>= 1.11.18)
- nanoFramework.System.Device.Gpio (>= 1.1.41)
- nanoFramework.System.Device.I2c (>= 1.1.16)
- nanoFramework.System.Math (>= 1.5.43)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.0.642 | 79 | 12/16/2024 |
1.0.631 | 99 | 12/4/2024 |
1.0.619 | 95 | 10/23/2024 |
1.0.577 | 112 | 8/28/2024 |
1.0.541 | 94 | 7/24/2024 |
1.0.536 | 107 | 7/17/2024 |
1.0.516 | 113 | 6/14/2024 |
1.0.506 | 112 | 5/29/2024 |
1.0.498 | 115 | 5/17/2024 |
1.0.494 | 109 | 5/15/2024 |
1.0.482 | 137 | 4/15/2024 |
1.0.460 | 129 | 3/22/2024 |
1.0.382 | 246 | 11/10/2023 |
1.0.362 | 138 | 11/8/2023 |
1.0.330 | 162 | 9/6/2023 |
1.0.275 | 151 | 5/26/2023 |
1.0.262 | 148 | 5/16/2023 |
1.0.259 | 148 | 5/12/2023 |
1.0.254 | 157 | 5/11/2023 |
1.0.248 | 174 | 5/10/2023 |
1.0.243 | 149 | 5/3/2023 |
1.0.219 | 214 | 3/17/2023 |
1.0.199 | 252 | 2/22/2023 |
1.0.158 | 308 | 1/5/2023 |
1.0.154 | 323 | 1/3/2023 |
1.0.149 | 301 | 12/28/2022 |
1.0.99 | 375 | 11/5/2022 |
1.0.87 | 377 | 10/25/2022 |
1.0.74 | 391 | 10/22/2022 |
1.0.68 | 431 | 10/12/2022 |
1.0.60 | 428 | 10/8/2022 |
1.0.41 | 445 | 9/22/2022 |
1.0.33 | 483 | 9/15/2022 |
1.0.19 | 400 | 9/8/2022 |
1.0.3 | 406 | 8/25/2022 |
1.0.1 | 411 | 8/25/2022 |