TMP141- 1 Wire woes.

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

 I am trying to interface the TMP141(Datasheet,in PDF) temperature sensor that uses a 1 wire protocol,(quite similar,_not_ identical though.. to the one from Dallas Semi.) with the PSoC 3.(030)

   

 

   

So I wrote code to do 8-bit reads,and 16-bit reads.Heres the funny part.

   

While I can read 8bit registers flawlessly(i.e the expected defaults are read in consistently),the 16bit registers are giving me a headache.

   

If I do a 16bit read,on register address 0x01(Manufacturer ID- Expected 0x104C),all I get is 0x004C.Similarly,if I do a 16bit read on register address 0x08(Temp. Capabilities - Expected 0x014A),what I get is 0x004A.Where is half my data going?

   

But wait,there is more.If I do an 8bit read on a 16 bit register,like on register address 0x01(Manufacturer ID- Expected 0x104C),I do get the elusive 0x10.

   

It cant be an issue of the wrong drive mode(currently is Hi-Z),or pull-up resistor,since the 8bit reads come in with no issues at all.Also,since the 16bit and 8bit read functions use the same underlying Bit Read/Write functions,they cant be bad either.So whats going wrong? I am not able to locate the fault.

   

I'm attaching my code,but note that I use breakpoints to debug,so the main() has nothing much really.I usually place a breakpoint on the TMP141_Read16()'s return line,and watch the local register values.

0 Likes
1 Solution
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

And here seems to be the other one:

   

   

uint16 TMP141_Read16(){

       

   

for (shiftcount=15; shiftcount>0;shiftcount--) {

   

// And what's about Bit Number Zero ?? use int8 shiftcount and  >= 0

   

   

IncomingWord |= (

       

   

uint16)((TMP141_ReadBit())<<shiftcount);

   

   

}

    return(IncomingWord);   

   

Bob

View solution in original post

0 Likes
18 Replies
Anonymous
Not applicable

 I have written about this in further detail on my blog,if anyone is interested.

   

http://kmmankad.blogspot.com/2011/12/psoc3-and-tmp141-part-1.html

   

Attached is my code,so far.

0 Likes
Anonymous
Not applicable

not able to attach files.trying again.

0 Likes
Anonymous
Not applicable

 Heres the code,linked over from my 4shared account.

   

http://www.4shared.com/zip/eT7yiA-s/TMP141_21Dec.html

0 Likes
Anonymous
Not applicable

 I dont have any test equipment to look at the signal in the real sense,but my testing is basically just setting breakpoints and reading in values and bits.

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Is there any reason I cannot see that you read a 16-bit value into an 8-bit var?

   

   

 

   

 

   

   

uint8 RecdData;

   

RecdData=TMP141_RegRead16(0x01,0x01);

   

That's an obvious one, checking for more...

   

Bob

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

And here seems to be the other one:

   

   

uint16 TMP141_Read16(){

       

   

for (shiftcount=15; shiftcount>0;shiftcount--) {

   

// And what's about Bit Number Zero ?? use int8 shiftcount and  >= 0

   

   

IncomingWord |= (

       

   

uint16)((TMP141_ReadBit())<<shiftcount);

   

   

}

    return(IncomingWord);   

   

Bob

0 Likes
Anonymous
Not applicable

 Hey Bob,

   

thanks for looking at my files.About the first part,I dont go so far into the program.I mean,I just set a Breakpoint on the return of the TMP_Read16 function,and watch the "Incoming Word" there.

0 Likes
Anonymous
Not applicable

 Well,the your suggestion and the current version do the same thing essentially.But anyway,that doesnt seem to explain the missing first 8 bits.

0 Likes
Anonymous
Not applicable

 I still dont know why the above attached code doesnt work,but heres what does:

   

 

   

   


Anonymous
Not applicable

So yeah,thats 2 8bit reads,with their results combined into a 16bit result.

   

Now that these are working,I'll go onto Parity Calculations to wind up the read functions in their entirety.

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Will you please check, that the following function does not return 0xffffffff !

   

 

   

uint16 TestShift(void)
{
uint16 Result = 0;
uint8 ShiftCount;
 for(ShiftCount = 15; ShiftCount > 0; ShiftCount--)
 {
  Result |= (uint16)(0x00000001u << ShiftCount);
 }
 return Result;
}
 

   

If you used a similar construct throughout your program, then mani things will not work as you expected. Check the transmition of bits in and out fot the correct nimber of bits!

   

Happy Byting

   

Bob

Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Just read your last post, Same loop error?

   

Bob

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

What do you think of

   

uint16 TestShift(void)
{
uint16 Result = 0;
uint8 ShiftCount;
 for(ShiftCount = 0; ShiftCount < 16; ShiftCount++)
 {
  Result <<= 1;
  Result |= (uint16)(Tmp141_ReadBit());
 }
 return Result;
}
 

   

you may as well parameterize the loop-count with 8 or 16 for bytes and words (or even 32 for longs)

   

Bob

0 Likes
Anonymous
Not applicable

 Hey Bob,

   

thanks for the help and code.I'll check the code you've suggested soon.As I've posted above,I have got the 16bit reads working with no issues.I'm now onto figuring out the parity calculations.

0 Likes
Anonymous
Not applicable

 Thoroughly inspired by the lastest post on the PSoC Insiders Blog,I'm going to try and see where I can get by doing this in hardware.

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Check your writes as well, I just found this in your progam

   

   

//Write a byte to the slave. #UNTESTED

        void TMP141_Write8(uint8 payload){   

   

uint8 BitPayload,i,shiftcount=0;

   

for (shiftcount=0; shiftcount<=7;shiftcount++) {

   

BitPayload = (payload << shiftcount) & 0x80;

   

You shift bit 8 out, before you mask it off, so you're going to miss it. Bob (Linebreak doesn't work here now, no signature)

   

   

TMP141_WriteBit(BitPayload);

   

}

   

}

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Ooops! No, YOU're right that works. I didn't see the shitf left zero!

   

Sorry, I should use glasses

   

Bob

Anonymous
Not applicable

 Thanks to all those who helped.

   

I'm now getting stable temperature readings,and heres the final part of a brief explanation(why rob the datasheet of its purpose?) and source files over at my blog:

   

 http://kmmankad.blogspot.com/2011/12/psoc3-and-tmp141-part-3.html

   

One thing I'd like to mention here is this cool(IMHO) parity calculation hack I've used.

   

   

Say we want to calculate the parity of a byte of data,all we need to do is load it into the Accumulator Register and then check the P flag.What does that mean in code? Well,just one line:

   

uint8 parity=(ACC=DataByte,P); 

0 Likes