Discussion in "PIC Microcontroller Discussion" started by    abdul991    Apr 25, 2013.
Thu Apr 25 2013, 12:41 pm
#1
Hi, guys... I've upgraded my project from AT89S52 TO PIC ...

Lately i have implemented 2ds1820- using two Microcontroller pins - Read ROM command. i've attached the code....

Attachment
Thu Apr 25 2013, 12:45 pm
#2
And then using the received addresses i've implemented the Match Rom Command for a single IC and then implemented ConvTemp Command and ReadScratchPad Command using 1-wire, 2ds1820 IC. Here is the code attached.. I'm using MPLAB -PIC kit2 and xtal 12MHz....
Attachment
 ajay_bhargav like this.
Tags DS1820 interfacingDS1820 with PIC microcontroller1 wire protocol1 wire pic microcontrollerDS1820 digital thermometer pic microcontroller
Fri Apr 26 2013, 09:44 am
#3
Thanks for sharing.. your post is now tagged.
Sun May 05 2013, 05:51 pm
#4
I;m trying for searchRom command for 2 DS1820 1-Wire IC. i took the code from

http://pdfserv.maximintegrated.com/en/an/AN162.pdf

Customized it with my 12MHz xtal and Hyperterminal
But i am getting partial o/p.
i.e the two rom addresses with other values repeating every 240 bytes ...
I've attached the code as well as the o/p snapshot....
Attachment
Mon May 06 2013, 03:14 pm
#5

i.e the two rom addresses with other values repeating every 240 bytes ...

abdul991



Can you explain with example, coz nothing is understandable from screenshot you've posted.
Mon May 06 2013, 08:49 pm
#6
in the snapshot the highlighted part is the actual ROM address i require.. But the display is continuous which i don't understand.. i altered the code a little bit and got the o/p as attached below.

Explaination for the search Rom :

See the concept is Search Rom command gives 64 bits of ds1820 rom address for each ds1820 IC connected on the 1 wire.

This 64bit is permanently stored in FndROM[3][8].

The procedure is as follows
1. Reset is done in Finddevices() and it calls to initialize in First().
2. First() initializes lastDiscrep = 0; doneFlag = FALSE; // will explain later
3. First() calls next().
4. Next() initializes few more variables // explained below.
5. mask bit k=1 used for storing the read bit in Rom[n] while securing other bits of that byte from getting altered.
6. m=1 is the bit counter. So total 65 bits has to be counted.
7. n=0 is the byte counter. Total 0-7 bytes. do-while() of the Next() exits if n>7, indicating that one DS1820IC has been detected.
8. O/p write bit is g. What g holds is written back to the 1-Wire, so that , the particular DS1820 IC's are 'alive' on 1-wire for the remaining bits to be read.
9. the nxt is used to return true/false value to the FindDevice(), if false is returned the search is ended/closed.
10. Every time the Next() is called – if there are DS-ic’s on 1-wire then 8-bytes are put in the ROM[] and then stored into the FndROM[][] inside the FindDevice().


11. So, when PIC sends F0 command, each 1-Wireâ„¢ device will returns the bit, and its compliment bit. That is for each 64 bits , two bits are read by PIC .
PIC reads each of these two bits as the 'And' result of the bit- each DS1820 puts on 1-wire.

12. if PIC reads 11 then no devices are present and Next() returns false.
13. if 01 is read, by PIC, all the DS1820 devices have 0 at that bit position.
14. if 10 is read, all the 1-wire devices have 1 at that read bit position.
15. if 00 is read, some DS1820 device have 0 and some have 1 at that bit position.

16. this 00 condition is the discrepancy condition, used to identify and narrow down the 1-wire devices.
17. from here it gets little tricky.
18. In this case(when 00 is read) if 0 is written back in g then those 1-wire devices which had ‘0’ in the bit position will remain alive in search loop inside the do-while in Next().
19. Value of x is also tricky but easy. You need to figure is out yourself.
20. Then for 00- case initially 0 is written back by PIC and descepMarker stores the latest bit position at which '00' case existed.
21. when Next() is called again, if 00 case occurs ,if descrepMarker == bitposition then ‘1’ is written back into g on the 1-wire. so that the DS1820 ic having '1' at this bit position is/are selected and remain alive.
22. Rest of the code is to be understood alone.
23. I've below posted the part when case '00' occurs (2nd else)

else    // 1st else
{
// when this condition will never occur x=0.
if(x>
0) // 01 or 10  condition
g = x>
>
1; // bit write value for search

else   // 2nd else  00 condition
{
// if this discrepancy is before the last
// discrepancy on a previous Next then pick
// the same as last time
if(m<lastDiscrep)
g = ((ROM[n]&k)>
0);
else // if equal to last pick 1
g = (m==lastDiscrep); // if not then pick 0
// if 0 was picked then record
// position with mask k
if (g==0)  discrepMarker = m;

}   // 2nd else is closed 


if(g==1) // isolate bit in ROM[n] with mask k
ROM[n] |= k;
else
ROM[n] &= ~k;
write_bit(g); // ROM search write
m++; // increment bit counter m
k = k<<1; // and shift the bit mask k
if(k==0) // if the mask is 0 then go to new ROM
{ 

n++;    k++;
}

}  // 1st else closed
}while(n<8); //loop until through all ROM bytes 0-7
 




[ Edited Thu May 09 2013, 01:28 pm ]
Wed May 08 2013, 09:50 am
#7
Trust me abdul, you've written quite a logic there. It becomes more and more complex as I keep on reading. And it needs time for me to understand I am always in hurry when answering posts right now I do not have any answer for your problem. But I might answer later.
Thu May 09 2013, 12:47 pm
#8
k. no problem. its has complex logic.. i know for sure... i will clarify if any doubt is there in the code as best i can... But entire code cannot be explained...
Fri May 10 2013, 12:47 pm
#9
RELAX..... AJAY... ITS COMPLETED.... 3 DS IC SEARCH ROM IS PERFECTLY WORKING AND IT CAN BE EXTENDED TO ANY NO. 1-WIRE DEVICES... HERE IS THE CODE ATTACHED...

AND YOU CAN TAG THIS POST AS-WELL....
REST OF THE CODE IS SAME AS EARLIER POSTED..

Attachment
 ajay_bhargav like this.
Tags DS1820 interfacingDS1820 with PIC microcontroller1 wire protocol1 wire pic microcontrollerDS1820 digital thermometer pic microcontroller
Mon May 13 2013, 10:02 am
#10
ah! relaxed!! so what was the issue?? and how did you solve it.

Get Social

Information

Powered by e107 Forum System

Downloads

Comments

Bobbyerilar
Thu Mar 28 2024, 08:08 am
pb58
Thu Mar 28 2024, 05:54 am
Clarazkafup
Thu Mar 28 2024, 02:24 am
Walterkic
Thu Mar 28 2024, 01:19 am
Davidusawn
Wed Mar 27 2024, 08:30 pm
Richardsop
Tue Mar 26 2024, 10:33 pm
Stevencog
Tue Mar 26 2024, 04:26 pm
Bernardwarge
Tue Mar 26 2024, 11:15 am