On Thu, Mar 3, 2011 at 5:19 AM, Oli Glaser wrote:= =0A= > On 02/03/2011 23:18, Manu Abraham wrote:=0A= >> So, if the resistor is the STRONG_PULLUP, then why=0A= >> mention in the software flowchart, that STRONG_PULLUP is required in=0A= >> parasite mode ? Logically, I am more drawn to the micro pulling up the= =0A= >> pin using TRIS=3D0 and LAT=3D1, though I am not still very clear on that= =0A= >> aspect.=0A= >=0A= > The resistor is not the strong (enough) pull up. The datasheet=0A= > recommends a MOSFET to Vdd but it may be fine to use a PIC pin set to=0A= > high as the datasheet says there is no activity on the bus during the=0A= > time the strong pull up is activated. The current needed is about 1.5 mA= =0A= > so it should work okay.=0A= > The strong pull up is necessary in parasite mode as the 4k7 pull=0A= > up/parasite power capacitor cannot supply enough current for some=0A= > commands, namely Temperature Conversion and Write Scratchpad. The=0A= > DS18B20 says on page 5:=0A= >=0A= > In parasite power mode, the 1-Wire bus and CPP can provide sufficient=0A= > current to the DS18B20 for most=0A= > operations as long as the specified timing and voltage requirements are= =0A= > met (see the DC Electrical=0A= > Characteristics and AC Electrical Characteristics). However, when the=0A= > DS18B20 is performing=0A= > temperature conversions or copying data from the scratchpad memory to=0A= > EEPROM, the operating current=0A= > can be as high as 1.5mA. This current can cause an unacceptable voltage= =0A= > drop across the weak 1-Wire=0A= > pullup resistor and is more current than can be supplied by CPP. To=0A= > assure that the DS18B20 has sufficient=0A= > supply current, it is necessary to provide a strong pullup on the 1-Wire= =0A= > bus whenever temperature=0A= > conversions are taking place or data is being copied from the scratchpad= =0A= > to EEPROM. This can be=0A= > accomplished by using a MOSFET to pull the bus directly to the rail as=0A= > shown in Figure 4. The 1-Wire=0A= > bus must be switched to the strong pullup within 10=ECs (max) after a=0A= > Convert T [44h] or Copy Scratchpad=0A= > [48h] command is issued, and the bus must be held high by the pullup for= =0A= > the duration of the conversion=0A= > (tCONV) or data transfer (tWR =3D 10ms). No other activity can take place= =0A= > on the 1-Wire bus while the pullup=0A= > is enabled.=0A= =0A= That clears up almost all the doubts I had. Much appreciated.=0A= =0A= I have the following pseudo code in C18, does it look sane enough with=0A= regards to the timings ?=0A= =0A= #define OW_PORT LATAbits.LATA0=0A= #define OW_PORT_MODE TRISAbits.TRISA0=0A= =0A= #define OW_STRONG_PU (OW_PORT_MODE =3D 0, OW_PORT =3D 1)=0A= #define OW_PORT_HIGH OW_STRONG_PU=0A= #define OW_PORT_LOW (OW_PORT_MODE =3D 0, OW_PORT =3D 0)=0A= #define OW_PORT_RPU (OW_PORT_MODE =3D 1, OW_PORT =3D 0)=0A= =0A= const rom char crc_table[] =3D {=0A= 0,94,188,226,97,63,221,131,194,156,126,32,163,253,31,65,=0A= 157,195,33,127,252,162,64,30,95,1,227,189,62,96,130,220,=0A= 35,125,159,193,66,28,254,160,225,191,93,3,128,222,60,98,=0A= 190,224,2,92,223,129,99,61,124,34,192,158,29,67,161,255,=0A= 70,24,250,164,39,121,155,197,132,218,56,102,229,187,89,7,=0A= 219,133,103,57,186,228,6,88,25,71,165,251,120,38,196,154,=0A= 101,59,217,135,4,90,184,230,167,249,27,69,198,152,122,36,=0A= 248,166,68,26,153,199,37,123,58,100,134,216,91,5,231,185,=0A= 140,210,48,110,237,179,81,15,78,16,242,172,47,113,147,205,=0A= 17,79,173,243,112,46,204,146,211,141,111,49,178,236,14,80,=0A= 175,241,19,77,206,144,114,44,109,51,209,143,12,82,176,238,=0A= 50,108,142,208,83,13,239,177,240,174,76,18,145,207,45,115,=0A= 202,148,118,40,171,245,23,73,8,86,180,234,105,55,213,139,=0A= 87,9,235,181,54,104,138,212,149,203,41,119,244,170,72,22,=0A= 233,183,85,11,136,214,52,106,43,117,151,201,74,20,246,168,=0A= 116,42,200,150,21,75,169,247,182,232,10,84,215,137,107,53=0A= };=0A= =0A= void ow_parasite_init(void)=0A= {=0A= OW_STRONG_PU; /* initially power parasite */=0A= mdelay(1); /* wait a bit */=0A= }=0A= =0A= int8_t ow_parasite_reset(void)=0A= {=0A= int8_t detect;=0A= =0A= OW_PORT_LOW; /* DQ Low by Master */=0A= udelay250(); /* 480us min delay */=0A= udelay250();=0A= OW_PORT_RPU; /* resistor pulls it up */=0A= udelay80(); /* wait for slave to pull it down */=0A= detect =3D OW_PORT; /* read Slave state */=0A= udelay250(); /* wait for end of Slot */=0A= udelay250();=0A= return detect;=0A= }=0A= =0A= int8_t ow_parasite_get_bit(void)=0A= {=0A= int8_t val;=0A= =0A= OW_PORT_LOW; /* DQ LO by Master */=0A= udelay1(); /* wait for 1us */=0A= OW_PORT_RPU; /* release */=0A= udelay10(); /* master samples within 15us */=0A= val =3D OW_PORT; /* read parasite state */=0A= udelay50(); /* wait for end of Slot */=0A= }=0A= =0A= int8_t ow_parasite_set_bit(uint8_t b)=0A= {=0A= OW_PORT_LOW; /* master pulls LO */=0A= if (b) {=0A= udelay1();=0A= OW_PORT_HIGH;=0A= }=0A= udelay60();=0A= OW_PORT_RPU;=0A= }=0A= =0A= uint8_t ow_parasite_read(void)=0A= {=0A= uint8_t i, val;=0A= =0A= for (i =3D 0; i < 8; i++) {=0A= if (ow_parasite_get_bit())=0A= val |=3D (1 << i);=0A= udelay50();=0A= }=0A= return val;=0A= }=0A= =0A= void ow_parasite_write(uint8_t val)=0A= {=0A= uint8_t i;=0A= =0A= for (i =3D 0; i < 8; i++) {=0A= ow_parasite_set_bit((val >> i) & 0x01); =0A= udelay50();=0A= }=0A= } =0A= =0A= void read_temperature(void)=0A= {=0A= uint8_t owcrc, scratch[9];=0A= int16_t t;=0A= =0A= ADCON1 =3D 0x0f;=0A= =0A= ow_parasite_init(); /* parasite power */=0A= if (!ow_parasite_reset()) { /* detect parasite */=0A= dev_1w =3D 1;=0A= ow_parasite_write(0xcc); /* skip ROM cmds */=0A= ow_parasite_write(0x44); /* convert temp. */=0A= OW_STRONG_PU; /* master enables strong pullup */=0A= mdelay(250); /* wait 750ms */=0A= mdelay(250);=0A= mdelay(250);=0A= OW_PORT_RPU; /* master disables strong pullup */=0A= }=0A= if (!ow_parasite_reset()) {=0A= ow_parasite_write(0xcc); /* skip ROM cmds */=0A= ow_parasite_write(0xbe); /* read scratchpad */=0A= for (bytes =3D 0; bytes < 8; bytes++) {=0A= scratch[bytes] =3D ow_parasite_read();=0A= crc_table[owcrc ^ scratch[bytes]];=0A= }=0A= scratch[8] =3D ow_parasite_read();=0A= ow_parasite_reset();=0A= if (scratch[8] =3D=3D owcrc) {=0A= t =3D scratch[1] << 8 | scratch[0];=0A= if (t >=3D 0)=0A= t =3D (t + 8) / 16;=0A= else=0A= t =3D (t - 8) / 16;=0A= } else {=0A= t =3D 0;=0A= }=0A= }=0A= =0A= }=0A= =0A= -- =0A= http://www.piclist.com PIC/SX FAQ & list archive=0A= View/change your membership options at=0A= http://mailman.mit.edu/mailman/listinfo/piclist=0A= .