Download file
Library containing support for battery backed SRAM provided by realtime clock MCP7941x.
v0.0.2.1 stable initial public release
devdescr.xml: vendor id set to 0003, device id set to 0009, see https://forge.codesys.com/drv/io-drivers/database/Home/ for details.
<DeviceIdentification>
<Type>500</Type>
<Id>0003 0009</Id>
<Version>0.0.2.1</Version>
</DeviceIdentification>
In order to set up a MCP79410 real time clock, start by connecting it to the RPi and a quartz crystal.
The following a rough sketch on how to connect the pins to point one in the right direction - in practice, one might need capacitors to smooth signals or resitors to pull-up the SCL- and SDA-interface, depending for example on the battery and quartz crystal used.
X1: Connect to external 32.768 kHz quartz crystal
X2: Connect to external 32.768 kHz quartz crystal
VBAT: Connect to external battery
VSS: Connect to GND (e.g. RPi-Pin 9)
VCC: Connect to RPi-Pin 1 (3.3V)
MFP: -
SCL: Connect to RPi-Pin 5 (GPIO3_SCL1)
SDA: Connect to RPi-Pin 3 (GPIO3_SDA1)
After connecting the hardware, activated the i2c bus of via
sudo raspi-config
Choose Advanced Options -> "activate I2C" -> "Yes" and exit the tool.
Now update the repository and install i2c-tools
sudo apt-get update
sudo apt-get install i2c-tools
Once you have it installed check that the RTC has been detected using:
sudo i2cdetect -y 0 # (if using v1 Raspberry Pi or)
sudo i2cdetect -y 1 # (if using v2 Raspberry Pi)
This will look something like;
aliazzz@Raspbian:~ $ sudo i2cdetect -y 1
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- 18 -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- 57 -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 6f
70: -- -- -- -- -- -- -- --
The MCP7941x has two i2c adresses: 0x57 and 0x6f, if the addresses show up they are ready for communication.
0x57 leads to the EEPROM, a status register and a unique ID register whereas 0x6f is the address that leads to the SRAM and RTC itself
The MCP7941x is now ready for use with CODESYS
**NOTE: If you install this chip for linux use, you cannot get access to the SRAM from CODESYS as linux has permanently claimed this resource!
Continue at your own risk **
In order to establish a permanent linux OS connection add, first follow the steps to enable the RTC for use in CODESYS (see above)
Once the above steps are completed, follow the below steps.
In "/etc/modules" add "rtc-mcp7941x"
sudo nano /etc/modules
Edit the file and close it via alt-x and save the changes
In "/boot/config.txt" add "dtoverlay=i2c-rtc,mcp7941x"
sudo nano /boot/config.txt
Again, edit the file and close it via alt-x and save the changes.
Now reboot,
After reboot the 'sudo i2cdetect' yields;
aliazzz@Raspbian:~ $ sudo i2cdetect -y 1
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- 18 -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- 57 -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- UU
70: -- -- -- -- -- -- -- --
The RTC module has been loaded and activated and the RTC is used by linux.
In "/lib/udev/hwclock-set"
sudo nano /lib/udev/hwclock-set
comment out the lines;
#if [ -e /run/systemd/system ] ; then
# exit 0
#fi
Now, synchronize the RTC using the command
sudo hwclock -w
From now on, the RTC will keep the time and resynchronize the RPi's system time automatically on startup or manually by entering
sudo hwclock -r
The RTC is now in permanent use of the Linux OS!
CODESYS cannot use the SRAM from the RTC if the resource is in permanent use of the OS.