Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

1wire DS18B20

Status
Not open for further replies.

tresca

Member
Is there a minimum time before you can issue a convert command ?

I have the convert command running in an endless loop and each time it displays a few of the scratchpad registers on a glcd. I notice that it works once, and only once. (i.e if i take the convert command out of the loop and just run it once and then display, it works, but if i run the command again, i get 0xff.

If needed I can post my code, but im just curious if there is min time before each command. I did check the datasheet and i couldnt see anything in there.
 
All of the timing specs' are available in the Data Sheet.

Are you waiting for the conversion to complete before reading issuing the "read scratchpad" command (using a time delay or polling for the 'conversion compete' bit)?

Mike
 
Well like i said it works the first time, if it works the first time then it should work the next time.

Code:
void onewire_ConvertT()
{
  unsigned char scratchBuffer[9];
	char x=0;
 unsigned char temperature[3];
	char CRC[8];
	unsigned char  temp1,temp2,temp;
	int result;
	
//	temperature[2]=0b10011001;
	
//	if(onewire_reset())
//		write_lcd(3,0,"Device not found.");
//	else{
		onewire_reset();
		onewire_write_byte(skipRom);
		onewire_write_byte(convertT);
		
		delay480us();
		delay480us();
		
		onewire_reset();
		onewire_write_byte(skipRom);
		onewire_write_byte(readScratchpad);
		
		
		scratchBuffer[0]=onewire_read_byte();
		scratchBuffer[1]=onewire_read_byte();
		
		scratchBuffer[2]=onewire_read_byte();
		scratchBuffer[3]=onewire_read_byte();
		scratchBuffer[4]=onewire_read_byte();
		scratchBuffer[5]=onewire_read_byte();
		scratchBuffer[6]=onewire_read_byte();
		scratchBuffer[7]=onewire_read_byte();
		scratchBuffer[8]=onewire_read_byte();
		
		
	//	scratchBuffer[0]=0b10001010;
	//	scratchBuffer[1]= 0b00000001;
		
		
		temp1=scratchBuffer[0]>>4; //only care about 8bits(no fractions)
		temp=scratchBuffer[1]&0x07;
		temp<<=4;
		temp=temp1 | temp; 
		
		scratchBuffer[4]=temp;
		
		btoa(scratchBuffer[0],temperature);
		write_lcd_data(0,0,temperature);
	
		//scratchBuffer[0]=(scratchBuffer[0]>>4)|((scratchBuffer[1]&0x07)<<4);	
			
		btoa(temp,temperature);
	//	write_lcd(0,3,"Temperature:");
		write_lcd_data(0,1,temperature);
	

		
		
		
		
	
	
	
	
}

its not exactly nice right now, i just want it to work before i worry about anything else.
 
tresca, as Mike has said, using the default 12 bit resolution,you have to either wait over 3/4 second between convert commands (it takes that long to get a reading) or you have to keep polling it until it has finished processing each reading.
 
Conversion Time

Tresca

I just had a look at the datasheet and it does say that the max conversion time is 750 ms and I see you only have 960us. Is it an issue with the library as I know it does not work with DS1821.

Rupert
 
Well I modified the code to poll rather than go through a timed delay.

Still the same problem.

Looking at the registers it alternates between these two values
Temp LSB = 1010 1011
Temp LSB = 1111 1111

when temp is reading 1's across the board, I looked the rest of the scratchpad, and they are also all 1's. So it seems that the ds18B20 is not responding on occassion (i.e after a command. )

I just dont get why it works the FIRST time (every time), but as soon as I try to get the temperature, its always 1's.
 
Sigh. Figured it out.

When I was working on my GLCD code, i used a byte load for PORTC (which happens to be a mix of things).

Thanks for info.
 
Ok, I jumped the gun before. I thought I knew where it was. I dont.

I know WHAT the problem is (found a work around), but Im still in the works to figuring out exactly where the problem occurs and why.
 
OK NOW ! I got it.

I've read on this forum about Read-modify ports. I never really had a problem with them, and never really knew what the LAT register was truly for.

I dooooo now.

My GLCD uses some pins on PORTC as does my 1wire device. When I change CS1 and CS2 I am indirectly affecting my 1wire device.

Now it works.

Get resolution to work next and multiple devices.

I'll release my code to the public just to get an idea. I've searched and most of the code I found I had problems with and just wouldnt work. So im writing my own.

Stay tuned !
 
If you have a powerful enough pull-up you can read multiple devices at nearly the same time. You only have to wait for one lot of 750 ms

If you issue the reset, (receive presence pulse) then skip ROM and start conversion, then enable the strong pull up, all the devices will convert the temperature. You then read one at a time.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top