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 support@ccsinfo.com

I2C/DS1631 question

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



Joined: 16 Jun 2008
Posts: 30

View user's profile Send private message

I2C/DS1631 question
PostPosted: Tue Jun 24, 2008 8:38 am     Reply with quote

I'm using a PIC16F877A, and a DS1631 temperature sensor through I2C. I'm wondering if I can add another DS1631 on the same pins, like piggyback it on n whatnot, and then get the temp from both. I've used the one-wire sensors like the DS1820, and I know you can do that to them (at least on the board I used), so I want to know if I can do it with the DS1631. If I can, could anybody point me towards some helpful code?

Thanks,
-Nick
stewart



Joined: 28 Nov 2005
Posts: 12

View user's profile Send private message

PostPosted: Tue Jun 24, 2008 8:59 am     Reply with quote

Milkman45,

After a quick look at the data sheet, if you have one talking, then is should be a simple matter of getting 7 of them on the same bus.

In the back of my mind I wonder how you have one working and still be asking this question?

from the data sheet
Quote:
INITIATING 2-WIRE COMMUNICATION
To initiate 2-wire communication, the master generates a START followed by a control byte containing
the DS1631, DS1631A, or DS1731slave address. The R/
W bit of the control byte must be a 0 (“write”)
since the master next writes a command byte. The DS1631/DS1631A/DS1731 responds with an ACK
after receiving the control byte. This must be followed by a command byte from the master, which
indicates what type of operation is to be performed. The DS1631/DS1631A/DS1731 again respond with
an ACK after receiving the command byte.
Embarassed

Stewart
rnielsen



Joined: 23 Sep 2003
Posts: 852
Location: Utah

View user's profile Send private message

PostPosted: Tue Jun 24, 2008 9:10 am     Reply with quote

As you look at the data sheet it talks about the 2-wire communications. The control byte is configured as:

1 0 0 1 A2 A1 A0 R/W

A2, A1 & A0 correspond to the A2, A1 & A0 pins on the part. This will enable you to have multiple parts on the same bus. If you have all of the address pins (A2-A0) tied to ground then the control byte will be:

1 0 0 1 0 0 0 R/W

This should allow you to talk to up to eight devices individually.

Ronald
Ttelmah
Guest







PostPosted: Tue Jun 24, 2008 9:11 am     Reply with quote

Actually 8 (three address bits). Addresses are 1001xxx.

The supplied code, is for the three bits all set to '0', addresses 0x90, (and 0x91 for reading). All that has to be done, is to change the four points where this is used in the supplied code, to use a variable instead. So, in the init_temp code, and temp_config code, instead of I2C_WRITE(0x90), use a variable here. Similarly in the read_full_temp, and latter where '91' (the read address) is used, substitute the value in the variable+1.
Set the variable to the value for the chip required, and call the code as is currently done.
Then add the extra chip, and set the input pins to match the new address selected. So with A0=1, use address 0x92.
Reading the data sheet, is the best place to start. This paragraph "says it all".

"Every slave device on the bus has a unique 7-bit address that allows the master to access that device. The 7-bit bus address is 1 0 0 1 A2 A1 A0, where A2, A1, and A0 are user-selectable through the corresponding input pins. The three address pins allow up to eight DS1621s to be multidropped on the same bus"...

Best Wishes
stewart



Joined: 28 Nov 2005
Posts: 12

View user's profile Send private message

PostPosted: Tue Jun 24, 2008 9:40 am     Reply with quote

Ttelmah

Yes of course, I was thinking "7 more".

Thanks for clearing up the confusion my simple error might have created

Stewart
milkman41



Joined: 16 Jun 2008
Posts: 30

View user's profile Send private message

PostPosted: Tue Jun 24, 2008 9:55 am     Reply with quote

I probably should have mentioned that I am pretty much a total n00b (:p), and that alot of this goes whooooosh over my head, haha, but thank you for the suggestions, I will look into it, and see if I can't figure something out.

Also, the way I got the first one to work was cuz I got the development kit and it has an example for the DS1631, so yeah. But I will try to implement what you guys have told me, thanks again.

-Nick
milkman41



Joined: 16 Jun 2008
Posts: 30

View user's profile Send private message

PostPosted: Tue Jun 24, 2008 11:26 am     Reply with quote

Ttelmah wrote:
[...]So with A0=1, use address 0x92[...]


With A0 = 1, this would be for write, and 0x93 would be for read? Or am I misunderstanding? All of this address stuff confuses me, I'm a hardware guy, haha.
stewart



Joined: 28 Nov 2005
Posts: 12

View user's profile Send private message

PostPosted: Tue Jun 24, 2008 2:11 pm     Reply with quote

Time to get out the data sheet and do some "light" reading:
http://datasheets.maxim-ic.com/en/ds/DS1631-DS1731.pdf

Open the hymnal to page 11 of 15.

The high half is always 1001 (9 in HEX)
D3.D2.D1 is the address of the device you want to talk to.
D0 is the R/W bit 1=Read 0=Write

If you want to play in this sand box, you have to do some reading and playing.

So the address pins on the chip are marked A2, A1, A0, and all are grounded, then the chip's address is 000 or 0.
if A2 = 0, A1 = 0, A0 = 1, that is 001 or 1
if A2 = 0, A1 = 1, A0 = 0, that is 010 or 2
if A2 = 0, A1 = 1, A0 = 1, that is 011 or 3
if A2 = 1, A1 = 0, A0 = 0, that is 100 or 4

and so on.

The confusing part is that in the control word these 3 bits are shifted to the left by the R/W bit.

Hope that this helps, you don't have to read and understand the entire data sheet, but do take a look at the area of need.

Have fun, play with it.

Stewart
Ttelmah
Guest







PostPosted: Tue Jun 24, 2008 2:47 pm     Reply with quote

milkman41 wrote:
Ttelmah wrote:
[...]So with A0=1, use address 0x92[...]


With A0 = 1, this would be for write, and 0x93 would be for read? Or am I misunderstanding? All of this address stuff confuses me, I'm a hardware guy, haha.


That is why I said use the value +1, for the read operation.

It is an area of I2C, that can be confusing. Unfortunately, different companies have approached it different ways. The 'address', is really the top 7 bits in the value sent to the chip. So (thinking this way), is really:

100 1000

For the first device (0x48). This is then multiplied by 2, and added to the bit for read/write, to give the 0x90, and 0x91 values sent for write and read.

As Stewart says, adding seven more devices, should be a doddle. :-)

Best Wishes
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