NewbieQuestion about I2C

Started by sleidiman June 15, 2005
Hello!

(Ive posted this question on www.freegeeks.net, but I didnt
receive
an answer)

An absolut NewbieQuestion:

I want to measure temperature with DS1721 (Dallas Maxim). Thats
why i
have to work with I2C. Now, I have problems with the protocol.
First I want to send the Adress to the Sensor.
Here my example:

while((IBSR&0x20)==0x00);
{
}
IBCR=0xB0;
IBDR=0x90; /*Sensor Adress*/
while((IBSR&0x80)==0x00);
{
}

(I know, it is not very professional but it should only work for now)
Must I shift the bits out of the DataRegisters, or does it work in
this example? When I have to shift the Bits, can you tell me, how it
functions and can you give me an example?

Greetings


sleidiman, (what kind of man ist that :o) ??)

> while((IBSR&0x20)==0x00);

Shouldn't this read:
while((IBSR&0x20)!=0x00);
IBB will be SET if the bus is busy, so you want to
wait for it to clear.

> {
> }

what are these for?

> IBCR=0xB0;
> IBDR=0x90; /*Sensor Adress*/
> while((IBSR&0x80)==0x00);
> {
> }

again, what are the braces for?

> (I know, it is not very professional but it should only
> work for now)
> Must I shift the bits out of the DataRegisters, or does it
> work in this example? When I have to shift the

if you change the first while loop to wait for IBB to clear,
this code should work perfectly.

hth
-uwe


> sleidiman, (what kind of man ist that :o) ??)
Its a creative fantasy-name. You dont like it?!
[Furthermore, I dint want to use a nickname of a famous trademark
:-)
Look here: http://www.heise.de/newsticker/meldung/60586
Its just in german; Sorry!]

> Shouldn't this read:
> while((IBSR&0x20)!=0x00);
> IBB will be SET if the bus is busy, so you want to
> wait for it to clear.
Hmm No, thats wrong, I think. The IBSR is just a Status Register
which is read-only. I wanted to compare the result of the bit by bit
addition with 0x00. When the a start signal is detected the IBB-Bit is
1, then the bus is busy. When a stop signal is detected, IBB is
cleared.

> > {
> > }
> again, what are the braces for?
Okay, the braces are useless. Youre right! I thought it looks
better :-)

> > Must I shift the bits out of the DataRegisters, or does it
> > work in this example? When I have to shift the

Okay, thus I dont need to shift the bits (to the bus)?!?
Thats great!!!
Another question:
There is only 1 Data Register in the I2c-Module. When i received 1
byte, i have to save this byte in an another register to receive the
second byte. It is right?

> hth
> -uwe

tal
sleidiman :-)


Sleidiman,

> > sleidiman, (what kind of man ist that :o) ??)
> Its a creative fantasy-name. You dont like it?!

No, it's ok, I was just curious and maybe trying to be funny,
hence the smiley.

> [Furthermore, I dint want to use a nickname of a famous trademark
> :-)
> Look here: http://www.heise.de/newsticker/meldung/60586
> Its just in german; Sorry!]

the one or the other four letter word comes to mind when reading
stuff like that.

> > Shouldn't this read:
> > while((IBSR&0x20)!=0x00);
> > IBB will be SET if the bus is busy, so you want to
> > wait for it to clear.
> Hmm No, thats wrong, I think. The IBSR is just a Status Register
> which is read-only. I wanted to compare the result of the bit by bit
> addition with 0x00. When the a start signal is detected the IBB-Bit is
> 1, then the bus is busy. When a stop signal is detected, IBB is
> cleared.

IBB (bit5, 0x20) is one, if the bus is busy, correct.
Thus "while((IBSR&0x20)==0x00);", like you had it,
waits for the bus to become busy, the opposite of what
one should do prior to using the bus, so I definitely
think it should be "while((IBSR&0x20)!=0x00);"

> > > {
> > > }
> > again, what are the braces for?
> Okay, the braces are useless. Youre right! I thought it looks
> better :-)

curly braces are cute, sure. ;o)

> Another question:
> There is only 1 Data Register in the I2c-Module. When i received 1
> byte, i have to save this byte in an another register to receive the
> second byte. It is right?

Yup, right! Preferably in memory.

hth
-uwe


> the one or the other four letter word comes to mind when reading
> stuff like that.
Oh, is it right, youre german? Me too alternatively I am! Thats why,
my English is so bad! Sorry!

> IBB (bit5, 0x20) is one, if the bus is busy, correct.
> Thus "while((IBSR&0x20)==0x00);", like you had it,
> waits for the bus to become busy, the opposite of what
> one should do prior to using the bus, so I definitely
> think it should be "while((IBSR&0x20)!=0x00);"

I believe, youre right.
"while((IBSR&0x20)!=0x00);" --> While the bus is busy, do nothing!
Thats the translation of your code-example, right?

Thanks a lot!


Sleidiman,

> > the one or the other four letter word comes to mind when reading
> > stuff like that.
> Oh, is it right, youre german? Me too alternatively I am! Thats why,
> my English is so bad! Sorry!

yup, right. Alternatively german?, what's the other alternative(s)? :o)

> > IBB (bit5, 0x20) is one, if the bus is busy, correct.
> > Thus "while((IBSR&0x20)==0x00);", like you had it,
> > waits for the bus to become busy, the opposite of what
> > one should do prior to using the bus, so I definitely
> > think it should be "while((IBSR&0x20)!=0x00);"
>
> I believe, youre right.
> "while((IBSR&0x20)!=0x00);" --> While the bus is busy, do nothing!
> Thats the translation of your code-example, right?

Exactly!

> Thanks a lot!

Bitte sch!
-uwe


> yup, right. Alternatively german?, what's the other alternative(s)? :o)
Argh, youve missunderstood me. I lay the blame on my bad english :-)

> Exactly! > Bitte sch!

And i become almost desperate, with my English.
Herrlich! :-)

-bfn-
sleidiman