Other Parts Discussed in Thread: SN74LVC1G07
HI, All
We want to drive TMP1826 with MCU GPIO, but it can not work. we have set up it with recommended circuit from datasheet. it is used with bus powered application.when debugging it, we have tried to adjust the pullup resistance from 330 ohm~ 11k ohm, but it still can not work. we also try to change the MCU with 3.3V type, but the result still is same. Who can help to check it?
Below is the debug code, use CMD: ReadTemperature, ReadROM, but it only reply with 0xFF,
bit Init_DS18B20(void)
{
bit dat=0;
DQ = 1; //DQ reset
DelayUs2x(5); //delay
DQ = 0; //drive low
Delay500us(); // // 480us< TMP1826 <560us
DelayUs2x(50); //20us
DQ = 1; //pullup
Delay50us(); //15~60us
DelayUs2x(50); //20us
dat=DQ; //check DQ
DelayUs2x(25); //
DelayUs2x(200);
DelayUs2x(200);
return dat;
}
unsigned char ReadOneChar(void)
{
unsigned char i=0;
unsigned char dat = 0;
for (i=8;i>0;i--)
{
DQ = 0; //
Delay3us() ;
dat>>=1;
DQ = 1; //
Delay20us() ;
if(DQ)
{dat|=0x80;}
Delay50us() ;
DQ = 1;
Delay20us() ;
}
return(dat);
}
void WriteOneChar(unsigned char dat)
{
unsigned char i=0;
DQ = 1;
SPower=1;
for (i=8; i>0; i--)
{
if (dat&0x01)
{
DQ = 0;
Delay_5us();
DQ = 1;
Delay50us();
Delay20us();
}
else
{
DQ = 0;
Delay20us();
Delay50us();
Delay20us();
}
dat>>=1;
DQ = 1;
Delay20us();
}
}
unsigned int ReadTemperatureTMP1826(void)
{
unsigned char a=0;
unsigned int b=0;
unsigned int t=0;
Init_DS18B20();
WriteOneChar(0xCC); // skip
WriteOneChar(0x44); //
Delay50ms();
Init_DS18B20();
WriteOneChar(0xCC); //
WriteOneChar(0xBE); //
a=ReadOneChar(); //low byte
b=ReadOneChar(); //high byte
Init_DS18B20();
b<<=8;
t=a+b;
return(t);
}
/*------------------------------------------------
Read ROM 64bit ID
------------------------------------------------*/
void ReadROM(void)
{
unsigned char i=0;
DelayUs2x(100);
Init_DS18B20();
WriteOneChar(0x33); //
for (i=0;i<8;i++)
{
BUF[i]=ReadOneChar();
}
}