Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 17:15 05 May 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : RTC temperature measurements

Author Message
OA47

Guru

Joined: 11/04/2012
Location: Australia
Posts: 911
Posted: 05:58pm 01 May 2017
Copy link to clipboard 
Print this post

Can someone remind me how I can get the temp measurement from a DS3231. I remember doing it with a RTC GETREG but I cant find any references to it.
Thanks in advance
Graeme
 
BobD

Guru

Joined: 07/12/2011
Location: Australia
Posts: 935
Posted: 06:29pm 01 May 2017
Copy link to clipboard 
Print this post

Here is a bit of code from years back on the Maximite.
[code]
If RTCdata(17) < &h80 Then
Temperature = RTCdata(17) + (RTCdata(18) / 256)
Else
Temperature = -(((RTCdata(17) Xor &hFF) + 1) + (RTCdata(18) \ 256))
EndIf

t$=Format$(Temperature,"%+6.2f")
Print "Temperature is "; T$; " degrees Celsius"
[/code]

RTCData() is an array of the data from the DS3231 regs. So now you would use a Getreg to get the data. The temperature data is twos complement so needs some work to normalise it.

Edit: I can see a little bug in the code that escaped me all those years back. I used /256 and \256. I would suspect that \256 (integer divide) is required.

Edit again: There is a bit more to the code. I'm so rusty that I missed it. I've added the print formatting in the end of the code block. Someone may be able to help on how the print format worked. I think it is probably 6 digits to the left and 2 to the right of the point.Edited by BobD 2017-05-03
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 5914
Posted: 07:56pm 01 May 2017
Copy link to clipboard 
Print this post

  Quote   RTC GETREG 17, rtc17
RTC GETREG 18, rtc18

IF v17 < &h80 THEN
Temperature = rtc17 + (rtc18 /
256)
ELSE
Temperature = -(((rtc17
XOR &hFF) + 1) + (rtc18 / 256))
ENDIF

PRINT temperature


Adapting Bobs code a bit

Jim

VK7JH
MMedit   MMBasic Help
 
OA47

Guru

Joined: 11/04/2012
Location: Australia
Posts: 911
Posted: 08:26pm 01 May 2017
Copy link to clipboard 
Print this post

Thanks Jim, as you did, I managed to adapt Bobs code to work with RTC GETREG. Possibly a note to Geoffg to add this to the Micromite Manual.

Regards
Graeme
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 5914
Posted: 08:43pm 01 May 2017
Copy link to clipboard 
Print this post

I had an error on line 4.

Only a problem if we get a frost tonight!

  Quote   RTC GETREG 17, rtc17
RTC GETREG 18, rtc18

IF rtc17 < &h80 THEN
Temperature = rtc17 + (rtc18 /
256)
ELSE
Temperature = -(((rtc17
XOR &hFF) + 1) + (rtc18 / 256))
ENDIF

PRINT temperature


Jim
VK7JH
MMedit   MMBasic Help
 
BobD

Guru

Joined: 07/12/2011
Location: Australia
Posts: 935
Posted: 09:41pm 01 May 2017
Copy link to clipboard 
Print this post

[quote] Only a problem if we get a frost tonight!
[/quote]
Ha ha, That may happen. It's cool.
 
OA47

Guru

Joined: 11/04/2012
Location: Australia
Posts: 911
Posted: 11:26am 02 May 2017
Copy link to clipboard 
Print this post

And it did!
-2.1 degrees this morning and a frost to boot.....
Graeme
 
Phil23
Guru

Joined: 27/03/2016
Location: Australia
Posts: 1664
Posted: 11:38am 02 May 2017
Copy link to clipboard 
Print this post

  OA47 said   And it did!
-2.1 degrees this morning and a frost to boot.....
Graeme


Hmmm,

I get 13.25°....

There's a DS18B20 clipped under the table it's on,
It's reading 11.94°

Another up at roof level, about 4m up, shielded by the eves,
It's showing 13.5°.

Phil
 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3018
Posted: 01:29pm 02 May 2017
Copy link to clipboard 
Print this post

I didn't know the DS3231 had a built-in temperature sensor with output available (I knew it had one for temp compensation for the time). Ran this code and it read 24 a few centimeters away from a DS18B20 which read 25.

Thanks.

Lance

PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
CaptainBoing

Guru

Joined: 07/09/2016
Location: United Kingdom
Posts: 1985
Posted: 09:11pm 02 May 2017
Copy link to clipboard 
Print this post

  lizby said  
I didn't know the DS3231 had a built-in temperature sensor


Ah the joys of the data sheet and lots of other goodies besides...
https://datasheets.maximintegrated.com/en/ds/DS3231.pdf page 11 (or &h0b if you prefer)

I use this to give me ambient temperature of enclosures (and in one to give me the cold junction temperature for a thermo-couple calculation) - its no good if you need a proper range but none of my test kit is in the cold

Edited by CaptainBoing 2017-05-04
 
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024