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: AustraliaPosts: 911 |
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: AustraliaPosts: 935 |
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. |
||||
TassyJim Guru Joined: 07/08/2011 Location: AustraliaPosts: 5913 |
Adapting Bobs code a bit Jim VK7JH MMedit  MMBasic Help |
||||
OA47 Guru Joined: 11/04/2012 Location: AustraliaPosts: 911 |
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: AustraliaPosts: 5913 |
I had an error on line 4. Only a problem if we get a frost tonight! Jim VK7JH MMedit  MMBasic Help |
||||
BobD Guru Joined: 07/12/2011 Location: AustraliaPosts: 935 |
[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: AustraliaPosts: 911 |
And it did! -2.1 degrees this morning and a frost to boot..... Graeme |
||||
Phil23 Guru Joined: 27/03/2016 Location: AustraliaPosts: 1664 |
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 StatesPosts: 3018 |
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 KingdomPosts: 1985 |
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 |
||||
Print this page |