EmbeddedRelated.com
Forums
The 2024 Embedded Online Conference

1-wire protocol functions -Dont work, why ?

Started by madid87 August 18, 2006
I have two 1-wire devices. Both termo sensors. DS1820 and DS18B20.
They will be used in LPC2129 projects.

But for some reason something is wrong with my function to communicate with
1-wire devices. I'm trying to fix them for 2 days now and nothing so far :(

So if someone have some experiance with 1-wire protocol please take a peak
at my C functions. For communication I use P0.0 (do I have to use a open
drain pin??). Thank you very much !

int init_ds1820(void)
{
IODIR0=0x01; // P0.0 out
IOCLR0=0x01; // Low level
delayus(500);
IODIR0=0x00; // Free line
delayus(100);
if(!(IOPIN0 & 1))
return 1;
delayus(500);
return 0;
}

void write_0()
{
IODIR0=0x01; // P0.0 out
IOCLR0=0x01; // Low level
delayus(1);
IODIR0=0x01; // Free line
delayus(60);
}

void write_1()
{
IODIR0=0x01; // P0.0 out
IOCLR0=0x01; // Low level
delayus(1);
IODIR0=0x01; // Free line
delayus(60); // Wait till the end of time slot
}

void command(int data)
{
int i;
for(i=0; i<8; i++)
{
if(data & 1)
write_1();
else
write_0();
dataa>>1;
}
}

int read_bit()
{
int bit=1;
IODIR0=0x01; // P0.0 out
IOCLR0=0x01; // Low level
delayus(1);
IODIR0=0x01; // Free line
delayus(5); // Wait some time
if(!(IOPIN0 & 1))
bit=0;
delayus(60);
return bit;
}

int read_owi(int bits)
{
int i,data=0;
for(i=0; i {
if(read_bit())
dataa | 1<<(bits-1);
dataa>>1;
}
return data;
}

An Engineer's Guide to the LPC2100 Series

> void write_0()
> {
> IODIR0=0x01; // P0.0 out
> IOCLR0=0x01; // Low level
> delayus(1);
> IODIR0=0x01; // Free line
> delayus(60);
> }
>
> void write_1()
> {
> IODIR0=0x01; // P0.0 out
> IOCLR0=0x01; // Low level
> delayus(1);
> IODIR0=0x01; // Free line
> delayus(60); // Wait till the end of time slot
> }

There is no difference between your write-0 and write-1 code :)

To write zero you need to delay for 60us *while* holding the
bus low.

http://www.ovro.caltech.edu/~dwh/correlator/pdf/sys_hdl.pdf

p88 has some scope traces

Dave
> For communication I use P0.0 (do I have to use a open
> drain pin??). Thank you very much !

Yes you do, since either the master or the slave drives
the bus low.

Note that for EEPROM and temperature devices, you can
drive the bus high while its performing a conversion
to provide it with additional current.

Dave
You do realise you need some additional circuitry? You cannot hook-up the
one-wire directly to an I/O pin.

There is some ported Dallas code at http://www.aeolusdevelopment.com

Robert
Original Message:
-----------------
From: madid87 m...@yahoo.com
Date: Fri, 18 Aug 2006 17:07:58 -0000
To: l...
Subject: [lpc2000] 1-wire protocol functions -Dont work, why ?
I have two 1-wire devices. Both termo sensors. DS1820 and DS18B20.
They will be used in LPC2129 projects.

But for some reason something is wrong with my function to communicate with
1-wire devices. I'm trying to fix them for 2 days now and nothing so far :(

So if someone have some experiance with 1-wire protocol please take a peak
at my C functions. For communication I use P0.0 (do I have to use a open
drain pin??). Thank you very much !

int init_ds1820(void)
{
IODIR0=0x01; // P0.0 out
IOCLR0=0x01; // Low level
delayus(500);
IODIR0=0x00; // Free line
delayus(100);
if(!(IOPIN0 & 1))
return 1;
delayus(500);
return 0;
}

void write_0()
{
IODIR0=0x01; // P0.0 out
IOCLR0=0x01; // Low level
delayus(1);
IODIR0=0x01; // Free line
delayus(60);
}

void write_1()
{
IODIR0=0x01; // P0.0 out
IOCLR0=0x01; // Low level
delayus(1);
IODIR0=0x01; // Free line
delayus(60); // Wait till the end of time slot
}

void command(int data)
{
int i;
for(i=0; i<8; i++)
{
if(data & 1)
write_1();
else
write_0();
dataa>>1;
}
}

int read_bit()
{
int bit=1;
IODIR0=0x01; // P0.0 out
IOCLR0=0x01; // Low level
delayus(1);
IODIR0=0x01; // Free line
delayus(5); // Wait some time
if(!(IOPIN0 & 1))
bit=0;
delayus(60);
return bit;
}

int read_owi(int bits)
{
int i,data=0;
for(i=0; i {
if(read_bit())
dataa | 1<<(bits-1);
dataa>>1;
}
return data;
}
--- In l..., "subscriptions@..."
wrote:
> You do realise you need some additional circuitry? You cannot hook-up
the
> one-wire directly to an I/O pin.
> There is some ported Dallas code at http://www.aeolusdevelopment.com

I know. 4.7k pull up is on the line!
It doesn't work :(
--- In l..., David Hawkins wrote:

> There is no difference between your write-0 and write-1 code :)
> To write zero you need to delay for 60us *while* holding the
> bus low.
> http://www.ovro.caltech.edu/~dwh/correlator/pdf/sys_hdl.pdf
> p88 has some scope traces
> Dave
This is a copy paste bug here on forums :)
Correct function is this.
Simply, it doesn't work !

void write_0()
{
IODIR0=0x01; // P0.0 izlazni
IOCLR0=0x01; // Niska razina
delayus(60);
IODIR0=0x01; // Otpusti liniju
}
--- In l..., David Hawkins wrote:
> There is no difference between your write-0 and write-1 code :)

Here copy-paste bug here on forum :)

Correct functions

void write_0()
{
IODIR0=0x01; // P0.0 izlazni
IOCLR0=0x01; // Niska razina
delayus(60);
IODIR0=0x00; // Otpusti liniju
}

void write_1()
{
IODIR0=0x01; // P0.0 izlazni
IOCLR0=0x01; // Niska razina
delayus(1);
IODIR0=0x00; // Otpusti liniju
delayus(60); // Do kraja write slota
}
madid87 wrote:
> --- In l..., David Hawkins wrote:
>> There is no difference between your write-0 and write-1 code :)
>
> Here copy-paste bug here on forum :)
>
> Correct functions
>
> void write_0()
> {
> IODIR0=0x01; // P0.0 izlazni
> IOCLR0=0x01; // Niska razina
> delayus(60);
> IODIR0=0x00; // Otpusti liniju
> }

You'll probably still need a delay after, eg.

void write_0()
{
IODIR0=0x01; // P0.0 izlazni
IOCLR0=0x01; // Niska razina
delayus(60);
IODIR0=0x00; // Otpusti liniju
delayus(1);
}

otherwise back-to-back calls to write_0() will probably not
deassert the bus (since the RC time of the bus is probably
longer than the back-to-back calls).

Try that.

Also try looking on the bus with a scope :)

Dave
You'll need more that that. One-wire requires that the slave can pull the
line down (there are other requirements relating to drive currents etc..)
so yo cannot drive it high during the off periods. There are a number of
circuits lying around. If I get a chance this weekend I'll try to post the
one I've been using.

Robert

Original Message:
-----------------
From: madid87
Date: Fri, 18 Aug 2006 18:07:47 -0000
To: l...
Subject: [lpc2000] Re: 1-wire protocol functions -Dont work, why ?
--- In l..., "subscriptions@..."
wrote:
> You do realise you need some additional circuitry? You cannot hook-up
the
> one-wire directly to an I/O pin.
> There is some ported Dallas code at http://www.aeolusdevelopment.com

I know. 4.7k pull up is on the line!
It doesn't work :(

--------------------------------
mail2web - Check your email from the web at
http://mail2web.com/ .
I am using the DS1820 with an AVR micro (gasp). It is on a GPIO pin
which I can set to high impedance.

Make sure you disable interrupts during communications or you will
hose your timeslots.

Rich

--- In l..., "subscriptions@..."
wrote:
>
> You do realise you need some additional circuitry? You cannot
hook-up the
> one-wire directly to an I/O pin.
>
> There is some ported Dallas code at http://www.aeolusdevelopment.com
>
> Robert
> Original Message:
> -----------------
> From: madid87 madid87@...
> Date: Fri, 18 Aug 2006 17:07:58 -0000
> To: l...
> Subject: [lpc2000] 1-wire protocol functions -Dont work, why ?
> I have two 1-wire devices. Both termo sensors. DS1820 and DS18B20.
> They will be used in LPC2129 projects.
>
> But for some reason something is wrong with my function to
communicate with
> 1-wire devices. I'm trying to fix them for 2 days now and nothing so
far :(
>
> So if someone have some experiance with 1-wire protocol please take
a peak
> at my C functions. For communication I use P0.0 (do I have to use a
open
> drain pin??). Thank you very much !
>
> int init_ds1820(void)
> {
> IODIR0=0x01; // P0.0 out
> IOCLR0=0x01; // Low level
> delayus(500);
> IODIR0=0x00; // Free line
> delayus(100);
> if(!(IOPIN0 & 1))
> return 1;
> delayus(500);
> return 0;
> }
>
> void write_0()
> {
> IODIR0=0x01; // P0.0 out
> IOCLR0=0x01; // Low level
> delayus(1);
> IODIR0=0x01; // Free line
> delayus(60);
> }
>
> void write_1()
> {
> IODIR0=0x01; // P0.0 out
> IOCLR0=0x01; // Low level
> delayus(1);
> IODIR0=0x01; // Free line
> delayus(60); // Wait till the end of time slot
> }
>
> void command(int data)
> {
> int i;
> for(i=0; i<8; i++)
> {
> if(data & 1)
> write_1();
> else
> write_0();
> dataa>>1;
> }
> }
>
> int read_bit()
> {
> int bit=1;
> IODIR0=0x01; // P0.0 out
> IOCLR0=0x01; // Low level
> delayus(1);
> IODIR0=0x01; // Free line
> delayus(5); // Wait some time
> if(!(IOPIN0 & 1))
> bit=0;
> delayus(60);
> return bit;
> }
>
> int read_owi(int bits)
> {
> int i,data=0;
> for(i=0; i > {
> if(read_bit())
> dataa | 1<<(bits-1);
> dataa>>1;
> }
> return data;
> }
>
>
>

The 2024 Embedded Online Conference