boxtec Forum
Microcontroller => PIC => : Mennging May 17, 2017, 10:50:10 AM
-
Here I've issue related to DS1621 (http://www.kynix.com/uploadfiles/pdf8827/DS1621S.pdf) digital thermometer interfacing with PIC18F26J50 controller.
Below you can see my code and this code I build in MPLAB X v.1.4 IDE with C18 compiler:
unsigned char i2c_read(void)
{
char buf[20];
unsigned char i,j;
j=0;
i=DATA;
for(i=0;i<8;i++)
{
j<<=1;
CLOCK = HIGH;
j|=DATA;
delay_ms(100);
CLOCK = LOW;
}
//////////////////////
**sprintf(buf,"%d",j); // 255
transmit_str1(buf); //UART transmit string**
/////////////////////
return buf;//return j;
}
main()
{
while(1)
{
i2c_start();
i2c_write(0x90);
i2c_write(0xAC);
i2c_write(0x02);
i2c_stop();
i2c_start();
i2c_write(0x90);
i2c_write(0xEE);
i2c_stop();
i2c_start();
i2c_write(0x90);
i2c_write(0xAA);
i2c_start();
i2c_write(0x91);
ch = i2c_read();
i2c_stop();
///////////////////
temperature = 0;
convert(ch); //convert binary to Decimal
if(flag==FALSE_)
{
flag = TRUE_;
tmp=temperature;
//itoa(tmp,buffer);
sprintf(tmp,"%s",temperature);
}
else
{
if(tmp!=temperature)
{
tmp=temperature;
sprintf(str,"%d%s",temperature,"Centigrade");
}
}
}
}
Here I'm interfacing DS1621 Thermometer with PIC18F26J50.
and I'm doing I2C communication between them. and I see this result on UART, but I get "255" data.
This "255" data string I got from "i2c_read(void)" function.
Here I'm attaching a screenshot of Oscilloscope from Proteus software. (YELLOW: SDA | BLUE: SCL).
Can you please tell me how to get reading from DS1621?
(https://i.stack.imgur.com/UPGFH.jpg)
-
The code you posted is not complete.
Explain why you don't use the hardware I2C bus but some badly designed software emulation.
Provide schematics of how you wired your hardware.
What is the max/min voltage of the SDA in the screenshot?