Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Getting corrupted data when reading DS18B20's ROM code.

Status
Not open for further replies.

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.
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;
	}
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.

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;
}
this is what I get in proteus
14.06.png
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.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top