On a Raspberry Pi 3 B+ I'm trying to read from a DS3231 RTC at boot time, sync the time to the system time and then unload the device. All the commands function from the terminal so I thought it would be easy enough to put them in /etc/rc.local or /etc/xdg/lxsession/LXDE-pi/autostart, but in both cases the device is registered, the clock syncs, but the device does not unload. I need to unload the device because it's no longer needed and I have a C++ GUI (QT) which accesses the temperature sensor on the RTC chip and this is blocked if the device is registered elsewhere.
The commands being run are:-
echo ds1307 0x68 | sudo tee /sys/class/i2c-adapter/i2c-1/new_device
sudo hwclock -s
echo 0x68 | sudo tee /sys/class/i2c-adapter/i2c-1/delete-device
After booting, the hwclock can still be accessed and the device can be deleted with the last command shown above when run in the terminal. Am I missing something blindingly obvious?
sudo rmmod rtc_ds1307
or whatever the driver name is. Then delete the device.