D@rkD@iver
Newbie level 1
- Joined
- Apr 22, 2012
- Messages
- 1
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,281
- Activity points
- 1,290
Hi, I'm trying to read ROM code from DS18B20 using AtTiny2313.
DS18B20 gives presense signal as it supposed to. Then I sent 0x33 command and read 8 bytes.
I read 8 non-0xFF bytes. but they are not representing the ROM code (LS byte isn't 0x28).
I tested it in proteus and in real device. the result is similar - just 8 numbers (diffrent for device and proteus). But those numbers repeat after I restart the system.
DS_Send_Byte function should be right, DS18B20 recognizes it. I think so because I read exactly 8 numbers(ninth byte is 0xFF) and if I change 0x33 to other command it receives all 0xFFs.
I'm concerned with DS_Read_Byte function.
this is what I get in proteus
LCD is fine I double checked it.
By the way the code of DS18B20 in proteus is B8C530
So what might be the problem?
Thank you.
DS18B20 gives presense signal as it supposed to. Then I sent 0x33 command and read 8 bytes.
I read 8 non-0xFF bytes. but they are not representing the ROM code (LS byte isn't 0x28).
I tested it in proteus and in real device. the result is similar - just 8 numbers (diffrent for device and proteus). But those numbers repeat after I restart the system.
Code:
if (DS_isPresent())
{
LCD_Clear_Display();
DS_Send_Byte(0x33);
for (int i=0; i<8; i++)
{
byte b = DS_Read_Byte();
LCD_Show_Byte(b);
}
return 0;
}
I'm concerned with DS_Read_Byte function.
Code:
byte DS_Read_Bit()
{
byte r = 0;
DSDDR |= 1<<DSBIT;
DSPORT &= ~(1<<DSBIT);
_delay_us(15);
DSDDR &= ~(1<<DSBIT);
_delay_us(15);
if (DSPIN&(1<<DSBIT))
{
r = 1;
}
_delay_us(30);
return r;
}
byte DS_Read_Byte()
{
byte b = 0;
for (int i=0; i<8; i++)
{
b = b << 1;
b = b + DS_Read_Bit();
}
return b;
}
LCD is fine I double checked it.
By the way the code of DS18B20 in proteus is B8C530
So what might be the problem?
Thank you.