[AVR] Reading DS18B20 chip ?

Status
Not open for further replies.

bianchi77

Advanced Member level 4
Joined
Jun 11, 2009
Messages
1,313
Helped
21
Reputation
44
Reaction score
20
Trophy points
1,318
Location
California
Activity points
9,442
Guys,

I tried to read DS18B20...
but the output in USART is

Temperature : ?

What should I change in this code ? thanks
Code:
char printbuff[100];
	double d = 0;
	int d1 = d; 
		
	usart_init(BAUD_PRESCALE);
	usart_pstr("TEST DS18B20 \n" );
	//init interrupt
	sei();
	
	while(1)
	{
		d = ds18b20_gettemp();
		//printf(printbuff,"%d",d1);
		
		sprintf(printbuff, "%.2f", d);
		usart_pstr("Temperature:");
		usart_pstr(printbuff);
		usart_pstr("\r\n");
		_delay_ms(500);
		
	}
 

Possible, start converion command missed? Also, delay 750ms needed for conversion.
 

Attached is a Windows Liberty Basic program the uses the LinkUSB adapter
perhaps you can get some idea from it...
 

Attachments

  • LB-1wire.zip
    5.2 KB · Views: 65

Attached is a Windows Liberty Basic program the uses the LinkUSB adapter
perhaps you can get some idea from it...

adding attachment

low level send rom address or skip rom - must select device
send convert cmd wait 750 ms if in parasite mode
send read scratch pad to get values
process the values

does you hi level get-temperature
does your hilevel support the adapter you are using, I use LinkUSB [DS9097U]
 

Attachments

  • LB-1wire.zip
    5.2 KB · Views: 74

It depends on what the function "ds18b20_gettemp()" does and whether it includes all the delays and commands needed for the device to return a value.

You are assigning the result to a double so printing it as a float wont work!

Brian.
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…