DS18b20 Codevision

Go To Last Post
23 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Has anyone got the DS18B20 working with the codevision lib functions. I can read the rom code, write to the device and do some other stuff but I cannot read the temp using their function from the library.

Anyone else having the same problem?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ok...I am done trying to figure out why it is not working.

Here is my own code...still not working.

PLEASE HELP!!

#define THERM_DECIMAL_STEPS_12BIT 625 //.0625 625

void therm_read_temperature(void)
{
        uint8_t temperature[2];
        int8_t digit;
        uint16_t decimal;
        
        ready = 0;
        if( rom_code[0] == 0x28 || rom_code[0] == 0x10 )// temperature sensor
        { 
                lcd_clear();
                lcd_puts("Device valid");
                delay_ms(2000);
                reset_ds();
                w1_write(0xCC);//skip rom
                do
                {
                ready = w1_write(0x44);//convert temp
                }while(ready=!1); //wait for temp convert 
                reset_ds();
                w1_write(0xCC);//skip rom
                w1_write(0xbe);//read scratchpad - ONLY 2 FIRST BYTES
                temperature[0]=therm_read_byte();
                temperature[1]=therm_read_byte();
                reset_ds();
                //Store temperature integer digits and decimal digits
                digit=temperature[0]>>4;
                digit|=(temperature[1]&0x7)<<4;
                //Store decimal digits
                decimal=temperature[0]&0xf;
                decimal*=THERM_DECIMAL_STEPS_12BIT;
                //Format temperature into a string [+XXX.XXXX C]
                sprintf(buffer, "%+d.%04u\xdfC", digit, decimal);
                lcd_clear();
                lcd_puts(buffer);
                delay_ms(5000);              
        }
        else
        { 
                lcd_clear();
                lcd_puts("Device not valid");
                while(1);
        };

}

and some other parts that might help in understanding my code

uint8_t therm_read_byte(void)
{
uint8_t i=8, n=0;
while(i--)
{
//Shift one position right and store read value
n>>=1;
n|=(w1_read()<<7);
}
return n;
}

void reset_ds (void)
{
        PORTD.OUTCLR = 0x04;
        delay_us(480);
        PORTD.OUTSET = 0x04;
        delay_us(480);
}
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

skyfreak wrote:

//=========================================================================
         do
         {
                ready = w1_write(0x44);//convert temp
         }while(ready=!1); //wait for temp convert 
         reset_ds();

Is your sensor wired up for non-parasitic power? or do you have power supplied to its Vdd pin?

Even with non-parasitic power, I couldn't get the 'polling for ready' to work. So you could try

    w1_write(0x44);//convert temp
    delay_ms(750); 
    reset_ds();
    ...

instead.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I am using external power on the sensor.

I am raeding something from the sensor but it cannot be right because it is something like +127.9835 and it stay constant (it never change)...and no I am not on the hottest place on earth :lol:

The ready that I am using is only to test if the temp values are ready to be read from the sensor...that will be a 1 when ready.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I am having a timing problem...I get the power on reset temp reading from the sensor, any advice?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The problem seems to be on my reset line.

void reset_ds(void)
{
//Pull line low and wait for 480uS
PORTD.OUTCLR = 0x04;
PORTD.DIR = 0x0F; //0000 1111 set as output pin 3
delay_us(480);
//Release line and wait for 60uS
PORTD.DIR = 0x0B; //0000 1011  set as input pin 3
delay_us(60);
//Store line value and wait until the completion of 480uS period
delay_us(420);
}

...any suggestions?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

skyfreak wrote:
I am using external power on the sensor.

I am raeding something from the sensor but it cannot be right because it is something like +127.9835 and it stay constant (it never change)...and no I am not on the hottest place on earth :lol:

The ready that I am using is only to test if the temp values are ready to be read from the sensor...that will be a 1 when ready.

I'm not familiar with the CodeVision One Wire library, but shouldn't the wait loop be more like:

    presence = ds_reset();
    if(presence) {
        // device not present error
    } else {
        w1_write(0xCC);//skip rom 
        w1_write(0x44);//convert temp
        do {
            ready = w1_read_bit();
        } while (ready != 1);
        ds_reset();
        // read scratchpad ...
    }

Your ds_reset() should return the pin level read after the 60uS delay.

What value pull up resistor are you using?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I am using a 4k7. I will add a return after the reset to make sure that the sensor are ready.

The while loop test for a 1. I have added a delay to give the sensor enough time to respond after the convert temp command. That is when the sensor are done with the temp conversion and the avr can go and read it from the scratcpad.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

skyfreak wrote:
Has anyone got the DS18B20 working with the codevision lib functions. I can read the rom code, write to the device and do some other stuff but I cannot read the temp using their function from the library.

Anyone else having the same problem?

I am absolutely certain that I must have tried the CodeVision example program several years ago. My memory says that it all worked fine. I even had two DS18B20's running at once.

So I thought that I should just try it again. And sure enough, it does not seem to work. I either get a constant 85.0000C or a constant 127.9375C. My house is not that warm!

I checked both of the DS18B20's individually with the default Arduino sketch. They both worked fine.
The GCC example project from danni works fine too. This applies to both regular and Parasitic-powered. I am using a 4k7 pull-up with Vcc between 3.3V and 5.0V.

The CodeVision bus read and write functions all look ok, so I am mystified. The weirdest thing is that the CodeVision ds18b20 functions start working if you use a 2k2 pull-up resistor.

@danni,

Do you have any ideas? CodeVision appears to read and write bits ok with 4k7, allows sufficient Temperature conversion time etc. Yet the pull-up seems to affect the conversion.

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ok..so if I am reading your post correctly you are saying that changing the 4k7 to a 2k2 changes the timing and the program work?

I tried everything in code to make it work without luck...I am still getting the +85.0000 value.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

@david

Quote:
The GCC example project from danni works fine too.

Do you maybe have a link for the example?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Dunno about you, but when I type "DS18B20" in the search engine with author="danni" I hit this:

https://www.avrfreaks.net/index.p...

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

skyfreak wrote:
Ok..so if I am reading your post correctly you are saying that changing the 4k7 to a 2k2 changes the timing and the program work?

I tried everything in code to make it work without luck...I am still getting the +85.0000 value.

Yes. Try it with 2k2 pull-up instead of 4k7.
No, the timing looks exactly the same with a Logic Analyser.

I am still mystified as to what the problem is. When I write the onewire in either C or ASM, it is fine with 4k7 and 3.3V.

I must confess that both my DS18B20 chips have had a hard life. Reverse voltage, overheating, conflicting output drive ...

So I am not rushing to blame Pavel's code. I am sure that 1000's of people must have used his DS18B20.lib code. If there are others with the same experience, I will make a report to HPInfotech.

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

According to the guys from Codevision their lib and their example are working fine :roll: :roll: :roll:

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Have you tried a 2k2 pull-up? Or even a 1k pull-up.

My experience may be down to mistreatment of the DS18B20 chips.
Has your chip had a hard life?

It would be nice to hear from a CV user that has a DS18B20 + 4k7 actually running.

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have not yet tried the 2k2...will do so ASAP. My sensor is brand new. I designed a little board to play with the xmega and added some peripherals. I cannot believe that something so simple give me such a hard time. I post again after I tried the 2k2. It will be really nice to hear from another CV user.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I wrote my own code that is working with the same sensor that I used with the codevision code. I did not change the resistor...same as in datasheet. Now I wonder why this sensor is working with my code but not with the example code from codevision....they said to me that there is nothing wrong with their code :?: :!: :?: :roll:

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Also, might compare against Sylvain's code at microsyl (he uses the imagecraft compiler, but the ds1820 stuff should be not have any compiler dependencies). Are you real sure you trust the cv delay functions? Can you accidently fool them by declaring the xtal freq incorrectly by mistake?

Imagecraft compiler user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

What version of CodeVision are you using??

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
Are you real sure you trust the cv delay functions? Can you accidently fool them by declaring the xtal freq incorrectly by mistake?

Well, I stopped trusting them after a couple of tries using their code. If you put in the wrong freq that is your fault, but this problem is a codevision problem.

I am using V2.04.9a.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

It seems the CodeWizard only puts in the .h include for DS1820/DS18S20, not the .h include for DS18B20.

Have you included the correct .h file?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Same thing:
If I use 4K7 resistor i get a constant 127.937...
With 2K2 / 1K everything works fine.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ask Pavel. I have studied the CV code and it all looks fine. I have also looked via a Logic Analyser. All the timings seem fine. One-wire comms look fine.

A stronger pull-up (2k2) seems to make CV work.
danni's one-wire code works fine with 4k7.
My one-wire code works fine with 4k7.

It is a mystery.

David.