View previous topic :: View next topic |
Author |
Message |
rfreddy
Joined: 03 Jun 2007 Posts: 7
|
Help with DS1621 |
Posted: Tue Aug 14, 2007 10:49 am |
|
|
Hi,
I'm working with a 18f4550 and a DS1621. I was successful reading the temperature from the DS1621 but now I'm unable to set the th and tl values for the thermostat.
Does anybody have a working code to use the thermostat? I need to start a fan at certain temperature and shut it off when the temperature drops from certain value.
Thanks in advance,
Freddy. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Aug 14, 2007 4:31 pm |
|
|
Look in the i2c timing diagrams page in the DS1621 data sheet.
Find the diagram called "Write to a two-byte register (TH, TL)".
It shows the protocol as:
Quote: |
- Start bit
- Address byte (ie, Slave address)
- Command byte
- MSB of thermostat degrees
- LSB of thermostat degrees
- Stop bit
|
Then just translate that protocol into C source code, as shown below.
In the code below, I don't bother with the "1/2 degree" capability of
the ds1621. The routines only accept a signed byte, which contains
the degrees as a whole number, i.e., 25 degrees, 55 degrees, -10
degrees, for example. The "1/2 degree" byte is hard-coded to a zero
in the routines below.
Code: |
// Write to the "high temperature" thermostat register.
void write_TH(signed int8 degrees)
{
i2c_start();
i2c_write(0x90);
i2c_write(0xA1);
i2c_write(degrees);
i2c_write(0);
i2c_stop();
}
// Write to the "low temperature" thermostat register.
void write_TL(signed int8 degrees)
{
i2c_start();
i2c_write(0x90);
i2c_write(0xA2);
i2c_write(degrees);
i2c_write(0);
i2c_stop();
}
|
You can call these routines in this way:
Code: |
write_TH(25); // High Thermostat trip point = 25 deg.
write_TL(10); // Low Thermostat trip point = 10 deg.
|
Normally I would use #define statements to make symbolic constants
for the i2c slave address (0x90) and the two commands. But CCS
doesn't do this in their ds1621 driver, so I've just followed the same
method in the two routines shown above. (Just to make it easier for
you to understand). |
|
|
rfreddy
Joined: 03 Jun 2007 Posts: 7
|
Thanks |
Posted: Tue Aug 14, 2007 5:57 pm |
|
|
Hi, thank you very much for your prompt answer. I'll try this code asap!
Bye,
Freddy. |
|
|
spenyo
Joined: 06 Jun 2022 Posts: 2 Location: Hungary
|
|
Posted: Thu Sep 29, 2022 12:41 pm |
|
|
Hello,
There is a line after the writing register value : i2c_write(0);
What does it mean and why need to send it to the DS1621 ?
I have checked the DS1621 datasheet and the protocol is the follow :
Start
Send Address byte - DS1621 base address
Send Command byte - The address of the H or the L register
Send Data byte - Value of the register
Stop
The datasheet not write about "i2c_write(0)"...
Thanks for the info.. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Sep 30, 2022 12:16 am |
|
|
TH and TL are two-byte registers. Look at page 9 in the DS1621 data sheet.
It shows that TH and TL are two bytes each. The i2c_write(0) statement
is writing 0x00 to the LSB register.
https://pdfserv.maximintegrated.com/en/ds/DS1621.pdf |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19463
|
|
Posted: Fri Sep 30, 2022 2:15 am |
|
|
If you look at Figure 2 in the data sheet, what does it show being sent as
the second byte for the write?.
You could work in half degree steps by sending a non zero value for this
second byte.
Look also at their 'Memory function example'.
What does it show being sent for each of the temperature limits?.
In each case the 'degrees' byte is then followed by a '0' byte. Exactly
what PCM has done. |
|
|
spenyo
Joined: 06 Jun 2022 Posts: 2 Location: Hungary
|
|
Posted: Mon Oct 03, 2022 10:26 am |
|
|
Hello,
Thank you for the info. |
|
|
|