As this will have a "linear" display, I wondered if I could also use it as a thermometer. I'm using the DS3231 which has a temperature sensing module in it.
Looking at the DS3231.h file, I see that two items are defined (DS3231_MSB_temp and DS3231_LSB_Temp) with the values of the two temperature registers 11h and 12h though are not mentioned further in the header.
Would I be correct in assuming that if I call: function DS3231_ReadRegister ( in DS_Value ) in a similar way to this, I will get the two values from the temperature registers.
I'm also assuming that the temperature is stored in BCD, similar to the time values.
{Update: The values are NOT in BCD, they are in pseudo "two's complement" decimal for the MSB and fractional representation using the uppermost two bits for the LSB}
Last edit: mkstevo 2021-01-28
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Just to clarify the operation of the temperature within the DS3231 should anyone be reading this in the future.
Calling the function DS3231_ReadRegister() with a value of 11h (0x11) will return the temperature MSB value, as a byte, in decimal. The uppermost bit, Bit.7, of this value is set to either '0' or '1'. When Bit.7 is set to '0' the remaining values indicate a positive temperature value. When set to '1' the remaining values indicate a negative temperature value. Therefore values of temperature can be returned in the range +127 to -127 degrees centigrade. You will see that I have tested the value returned, if it is above 127(decimal) it is a negative value, deducting 128(decimal) from that value gives the negative temperature value.
Calling the function DS3231_ReadRegister() with a value of 12h (0x12) gives a fractional value of the temperature. This value (oddly in my opinion) is placed in the uppermost two bits of the byte. Bits 5, 4, 3, 2, 1 and 0 are always zero and can be ignored.
Bit.7Bit.6FractionalValue000.0010.25100.50110.75
From my example, you can see I simply compared the decimal equivalents (0, 64, 128 and 192) and then converted those values into decimal representations (0, 25, 50 and 75) before printing them.
Neither of the two values returned are BCD encoded as the time values are.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I've done that. Of course on my Mac I've had to import the .docx file into Pages, then export it out again (as a .docx and a .pdf). There is a chance that some of the formatting is different to the original.
I have uploaded the updated files to GitHub.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I'm designing (yet) another clock.
As this will have a "linear" display, I wondered if I could also use it as a thermometer. I'm using the DS3231 which has a temperature sensing module in it.
Looking at the DS3231.h file, I see that two items are defined (DS3231_MSB_temp and DS3231_LSB_Temp) with the values of the two temperature registers 11h and 12h though are not mentioned further in the header.
Would I be correct in assuming that if I call: function DS3231_ReadRegister ( in DS_Value ) in a similar way to this, I will get the two values from the temperature registers.
I'm also assuming that the temperature is stored in BCD, similar to the time values.
{Update: The values are NOT in BCD, they are in pseudo "two's complement" decimal for the MSB and fractional representation using the uppermost two bits for the LSB}
Last edit: mkstevo 2021-01-28
Should work as you describe.
Try this....
Dim TemperatureWord as Word
Let TemperatureWord = DS3231_ReadRegister(12h)
Let TemperatureWord_h = DS3231_ReadRegister(11h)
This will load the low bytes into the lower byte of the word, and the high byte into the high (
_h
) byte of the word variable.Anobium
Many thanks. It does work much as anticipated.
It's telling me my office is 23.50' . Roughly correct.
Last edit: mkstevo 2021-01-27
Hot stuff!!!!
Well done
Just to clarify the operation of the temperature within the DS3231 should anyone be reading this in the future.
Calling the function DS3231_ReadRegister() with a value of 11h (0x11) will return the temperature MSB value, as a byte, in decimal. The uppermost bit, Bit.7, of this value is set to either '0' or '1'. When Bit.7 is set to '0' the remaining values indicate a positive temperature value. When set to '1' the remaining values indicate a negative temperature value. Therefore values of temperature can be returned in the range +127 to -127 degrees centigrade. You will see that I have tested the value returned, if it is above 127(decimal) it is a negative value, deducting 128(decimal) from that value gives the negative temperature value.
Calling the function DS3231_ReadRegister() with a value of 12h (0x12) gives a fractional value of the temperature. This value (oddly in my opinion) is placed in the uppermost two bits of the byte. Bits 5, 4, 3, 2, 1 and 0 are always zero and can be ignored.
From my example, you can see I simply compared the decimal equivalents (0, 64, 128 and 192) and then converted those values into decimal representations (0, 25, 50 and 75) before printing them.
Neither of the two values returned are BCD encoded as the time values are.
Interesting.
Can you pop this great info into the ds3231_commands.docx that it in the installation, or, update the same file here https://github.com/Anobium/Great-Cow-BASIC-Demonstration-Sources/tree/master/Real_Time_Clock_Solutions/clocks ?
If you update GitHub then the update will be included in the next release.
I've done that. Of course on my Mac I've had to import the .docx file into Pages, then export it out again (as a .docx and a .pdf). There is a chance that some of the formatting is different to the original.
I have uploaded the updated files to GitHub.
Look great. Thank you.