CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Help with DS1621

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
rfreddy



Joined: 03 Jun 2007
Posts: 7

View user's profile Send private message

Help with DS1621
PostPosted: Tue Aug 14, 2007 10:49 am     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Aug 14, 2007 4:31 pm     Reply with quote

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

View user's profile Send private message

Thanks
PostPosted: Tue Aug 14, 2007 5:57 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Sep 29, 2022 12:41 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Sep 30, 2022 12:16 am     Reply with quote

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: 19477

View user's profile Send private message

PostPosted: Fri Sep 30, 2022 2:15 am     Reply with quote

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. Smile
spenyo



Joined: 06 Jun 2022
Posts: 2
Location: Hungary

View user's profile Send private message

PostPosted: Mon Oct 03, 2022 10:26 am     Reply with quote

Hello,

Thank you for the info.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group