darkbibble
Posts: 602
Joined: Mon Mar 09, 2015 5:20 pm
Location: corby, england

ds3231 clock temperature sensor access?

Mon Mar 27, 2017 1:57 pm

according to the spec sheet for the ds3231 clock it has a internal temprature sensor. is there any way to access this via the i2c??
Q; How many Windows users does it take to fix a Linux problem??
A; Whats a Linux problem

User avatar
DougieLawson
Posts: 38883
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: ds3231 clock temperature sensor access?

Mon Mar 27, 2017 2:21 pm

What does i2cdetect -y 1 show?
What does ls -la /sys/bus/i2c/devices/1-0068/* show? There might be a pseudo filesystem file there for the temperature sensor registers.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

darkbibble
Posts: 602
Joined: Mon Mar 09, 2015 5:20 pm
Location: corby, england

Re: ds3231 clock temperature sensor access?

Mon Mar 27, 2017 2:34 pm

Code: Select all

 pi@pi-top:~ $ i2cdetect -y 1
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- 0b -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- UU -- -- -- -- -- -- -- 
70: -- -- -- 73 -- -- -- --                         
pi@pi-top:~ $ ls -la /sys/bus/i2c/devices/1-0068/*
lrwxrwxrwx 1 root root    0 Mar 27 15:32 /sys/bus/i2c/devices/1-0068/driver -> ../../../../../../bus/i2c/drivers/rtc-ds1307
-r--r--r-- 1 root root 4096 Mar 27 15:32 /sys/bus/i2c/devices/1-0068/modalias
-r--r--r-- 1 root root 4096 Mar 27 15:32 /sys/bus/i2c/devices/1-0068/name
lrwxrwxrwx 1 root root    0 Mar 27 15:32 /sys/bus/i2c/devices/1-0068/of_node -> ../../../../../../firmware/devicetree/base/soc/i2c@7e804000/ds3231@68
lrwxrwxrwx 1 root root    0 Mar 27 14:09 /sys/bus/i2c/devices/1-0068/subsystem -> ../../../../../../bus/i2c
-rw-r--r-- 1 root root 4096 Mar 27 14:09 /sys/bus/i2c/devices/1-0068/uevent

/sys/bus/i2c/devices/1-0068/power:
total 0
drwxr-xr-x 2 root root    0 Mar 27 15:32 .
drwxr-xr-x 4 root root    0 Mar 27 14:09 ..
-rw-r--r-- 1 root root 4096 Mar 27 15:32 autosuspend_delay_ms
-rw-r--r-- 1 root root 4096 Mar 27 15:32 control
-r--r--r-- 1 root root 4096 Mar 27 15:32 runtime_active_time
-r--r--r-- 1 root root 4096 Mar 27 15:32 runtime_status
-r--r--r-- 1 root root 4096 Mar 27 15:32 runtime_suspended_time

/sys/bus/i2c/devices/1-0068/rtc:
total 0
drwxr-xr-x 3 root root 0 Mar 27 15:32 .
drwxr-xr-x 4 root root 0 Mar 27 15:32 ..
drwxr-xr-x 3 root root 0 Mar 27 14:09 rtc0
 
Q; How many Windows users does it take to fix a Linux problem??
A; Whats a Linux problem

User avatar
DougieLawson
Posts: 38883
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: ds3231 clock temperature sensor access?

Mon Mar 27, 2017 3:04 pm

What did you add to /boot/config.txt for your RTC?

Anything more in /sys/bus/i2c/drivers/rtc-ds1307/*
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

gregeric
Posts: 1509
Joined: Mon Nov 28, 2011 10:08 am

Re: ds3231 clock temperature sensor access?

Mon Mar 27, 2017 3:09 pm

DS3231 temperature sensor readout is in kernels >=4.6 AFAICR

darkbibble
Posts: 602
Joined: Mon Mar 09, 2015 5:20 pm
Location: corby, england

Re: ds3231 clock temperature sensor access?

Mon Mar 27, 2017 3:19 pm

Code: Select all

 # turn real time clock on
dtoverlay=i2c-rtc,ds3231
gpu_mem_256=128
gpu_mem_512=256
gpu_mem_1024=256
overscan_scale=1
dtparam=i2c1=on
dtparam=i2c1_baudrate=50000
 
pi@pi-top:/sys/bus/i2c/drivers/rtc-ds1307 $ ls
1-0068 bind module uevent unbind
Q; How many Windows users does it take to fix a Linux problem??
A; Whats a Linux problem

User avatar
DougieLawson
Posts: 38883
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: ds3231 clock temperature sensor access?

Mon Mar 27, 2017 3:22 pm

OK, so it looks like the kernel driver in the RPF kernel doesn't support reading the temperature registers from your ds3231.

Sorry, I can't fix it for sure. I don't have a ds3231 handy. Try sudo rpi-update to get the 4.9 kernel.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

gregeric
Posts: 1509
Joined: Mon Nov 28, 2011 10:08 am

Re: ds3231 clock temperature sensor access?

Mon Mar 27, 2017 3:46 pm

Or, cherry pick the newer rtc-ds1307.c source and build & replace rtc-ds1307.ko. That's what i did. Let me know if you need a quick run down on that.

User avatar
DougieLawson
Posts: 38883
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: ds3231 clock temperature sensor access?

Mon Mar 27, 2017 3:52 pm

gregeric wrote:Or, cherry pick the newer rtc-ds1307.c source and build & replace rtc-ds1307.ko. That's what i did. Let me know if you need a quick run down on that.
rpi-update to 4.9.17 is probably safer for a general user in this case, building kernels isn't for the faint hearted. I know we don't usually recommend rpi-update but this is one case where jumping from 4.4.50 to 4.9.17 may solve the OP's problems.

Twelve out of fourteen of my raspberries are running 4.9.17 so we can assume it's relatively safe and won't turn the OP's RPi into a brain-dead corpse that won't boot.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

gregeric
Posts: 1509
Joined: Mon Nov 28, 2011 10:08 am

Re: ds3231 clock temperature sensor access?

Mon Mar 27, 2017 4:06 pm

Build the module alone, not the entire kernel. I have a simple recipe for that, will post it later.

gregeric
Posts: 1509
Joined: Mon Nov 28, 2011 10:08 am

Re: ds3231 clock temperature sensor access?

Mon Mar 27, 2017 6:14 pm

So, to build only the required rtc-ds1307.ko to get DS3231 temperature support in kernels <4.6.

Firstly, get kernel header files:

Code: Select all

sudo apt-get update && sudo apt-get dist-upgrade
sudo apt-get install -y raspberrypi-kernel-headers
sudo reboot
After reboot,

Code: Select all

mkdir ds1307
cd ds1307
wget https://raw.githubusercontent.com/raspberrypi/linux/rpi-4.9.y/drivers/rtc/rtc-ds1307.c
nano Makefile
Makefile contents (indent is a single <tab>, not spaces):

Code: Select all

obj-m := rtc-ds1307.o
ccflags-y += -DCONFIG_RTC_DRV_DS1307_HWMON

all:
	make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules

clean:
	make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean

install:
	sudo cp rtc-ds1307.ko /lib/modules/$(shell uname -r)/kernel/drivers/rtc/
	sudo depmod -a
Backup old module, build & install:

Code: Select all

sudo cp /lib/modules/$(uname -r)/kernel/drivers/rtc/rtc-ds1307.ko /lib/modules/$(uname -r)/kernel/drivers/rtc/rtc-ds1307.ko.bak
make clean all install
sudo reboot
Test the sensor:

Code: Select all

sudo apt-get install -y lm-sensors
sensors
Output should be something like this:

Code: Select all

ds3231-i2c-1-68
Adapter: 20804000.i2c
temp1:        +20.8°C

darkbibble
Posts: 602
Joined: Mon Mar 09, 2015 5:20 pm
Location: corby, england

Re: ds3231 clock temperature sensor access?

Tue Mar 28, 2017 6:17 pm

thanks, i did "sudo rpi-update" to update kernal, then installed the sensor module,

works great
Q; How many Windows users does it take to fix a Linux problem??
A; Whats a Linux problem

Return to “Beginners”