EmbeddedRelated.com
Forums
The 2024 Embedded Online Conference

1-wire driver

Started by carlochiesa78 September 15, 2008
I'm designing a new board with LPC2378/88 and I have to read the code
inside a Maxim DS2401 chip using the 1-wire protocol.

Which peripheral is suggested for this type of communication?

Any sample code is available for the LPC2xxx family?

An Engineer's Guide to the LPC2100 Series

You can use ext. int. for rx and any gpio for tx. For first presence pulse you shold use ext int. and than set that pin as gpio. You can read application note 159 from dallas.

I attached source codes you will need. You can use

if(iIbutton == TRUE)
{
if(ibuttonReset() == 0)
{
if(ibuttonReadSerial(ibuttonSerial) == TRUE)
{
isIbutton = FALSE;
return TRUE;
}
}
}


----- Original Message ----
From: carlochiesa78
To: l...
Sent: Monday, September 15, 2008 6:53:44 PM
Subject: [lpc2000] 1-wire driver
I'm designing a new board with LPC2378/88 and I have to read the code
inside a Maxim DS2401 chip using the 1-wire protocol.

Which peripheral is suggested for this type of communication?

Any sample code is available for the LPC2xxx family?



----------

//---

// Function......: extInt3ISR

// Description...: external interrupt ISR

// Return Value..: ...

// Parameters....: ...

//---

void extInt3ISR(void) __irq

{

interruptClose(EXTERNAL3_INTERRUPT);



arm_gpioSetPinAsGpio(P0PIN20);

delayUs(7000);

isIbutton = TRUE;

interruptRelease();

}

//---

// Function......: extIntInit

// Description...: external interrupt ilk derleri

// Return Value..: ...

// Parameters....: ...

//---

void extIntInit(void)

//---

{

arm_gpioSetPinFunction(P0PIN20, PIN_FUNC_THIRD_ALTERNATE);

EXTINT = 0x08; //extint3, clearlenir

EXTPOLAR = 0x00; //den kenar

EXTMODE = 0x08; //extint3, kenar duyarlbr />
interruptOpen(EXTERNAL3_INTERRUPT, extInt3ISR);

}







//---

// Function......: setSpeed

// Description...: ibutton haberleme hayarlar

// standart in (standard=1), overdrive in (standard=0).

// Return Value..: herhangi bir ibutton bulursa 0 bulamazsa 1 dd

// Parameters....: ...

//---

void setSpeed(u8 standard)

{

if (standard)

{

// Standard Speed

A = 6;

B = 64;

C = 60;

D = 10;

E = 9;

F = 55;

G = 0;

H = 480;

I = 70;

J = 410;

}

else

{

// Overdrive Speed

A = 2;

B = 8;

C = 8;

D = 8;

E = 1;

F = 7;

G = 3;

H = 70;

I = 9;

J = 40;

}

}





//---

// Function......: ibuttonReset

// Description...: 1-Wire hattresetler ve ibutton var sinyali bekler

// Return Value..: herhangi bir ibutton bulursa 0 bulamazsa 1 dd

// Parameters....: ...

//---

u8 ibuttonReset(void)

{

u8 result = 1;

delayUs(G);

gpioSetPin(IBUTTON_TX);

delayUs(H);

gpioClearPin(IBUTTON_TX);

delayUs(I);



result = gpioReadPin(IBUTTON_RX);

delayUs(J); // Complete the reset sequence recovery



return result;

}



//---

// Function......: ibuttonWriteBit

// Description...: ibutton a 1 bit yazar

// Return Value..:

// Parameters....: ...

//---

void ibuttonWriteBit(u8 bit)

{

if (bit)

{

// Write '1' bit

gpioSetPin(IBUTTON_TX);

delayUs(A);

gpioClearPin(IBUTTON_TX);

delayUs(B); // Complete the time slot and 10us recovery

}

else

{

// Write '0' bit

gpioSetPin(IBUTTON_TX);

delayUs(C);

gpioClearPin(IBUTTON_TX);

delayUs(D);

}

}





//---

// Function......: ibuttonReadBit

// Description...: ibutton dan 1 bit okur

// Return Value..:

// Parameters....: ...

//---

u8 ibuttonReadBit(void)

{

u8 result;



gpioSetPin(IBUTTON_TX);

delayUs(A);



gpioClearPin(IBUTTON_TX);

delayUs(E);



result = gpioReadPin(IBUTTON_RX);

delayUs(F);



return result;

}





//---

// Function......: ibuttonWriteByte

// Description...: ibutton a 1 byte yazar

// Return Value..:

// Parameters....: ...

//---

void ibuttonWriteByte(u8 data)

{

u8 loop;



// Loop to write each bit in the byte, LS-bit first

for (loop = 0; loop < 8; loop++)

{

ibuttonWriteBit(data & 0x01);



// shift the data byte for the next bit

data >>= 1;

}

}







//---

// Function......: ibuttonReadByte

// Description...: ibutton dan 1 byte okur

// Return Value..:

// Parameters....: ...

//---

u8 ibuttonReadByte(void)

{

u8 loop, result=0;



for (loop = 0; loop < 8; loop++)

{

// shift the result to get it ready for the next bit

result >>= 1;



// if result is one, then set MS bit

if (ibuttonReadBit())

result |= 0x80;

}

return result;

}



//---

// Function......: ibuttonTouchByte

// Description...: Ezamanlokuma ve yazma(data '1' ise oku '0' yaz)

// Return Value..: 0(yazma durumunda) veya okunan bit deri

// Parameters....:

//---

//ibuttonTouchByte(0xFF) == ibuttonReadByte()

//ibuttonTouchByte(0xFF) == ibuttonReadByte()



u8 ibuttonTouchByte(u8 data)

{

u8 loop, result=0;



for (loop = 0; loop < 8; loop++)

{

// shift the result to get it ready for the next bit

result >>= 1;



// If sending a '1' then read a bit else write a '0'

if (data & 0x01)

{

if (ibuttonReadBit())

result |= 0x80;

}

else

ibuttonWriteBit(0);



// shift the data byte for the next bit

data >>= 1;

}

return result;

}





//---

// Function......: ibuttonBlock

// Description...: aynbuffer erinden ezamanlokuma ve yazma

// Return Value..:

// Parameters....:

//---

void ibuttonBlock(u8 *data, u8 data_len)

{

u8 loop;



for (loop = 0; loop < data_len; loop++)

{

data[loop] = ibuttonTouchByte(data[loop]);

}

}





//---

// Function......: ibuttonReadSerial

// Description...: read rom(33h),

// Return Value..:

// Parameters....:

//---

bool ibuttonReadSerial(u8 *serialArray)

{

u8 i, crc = 0;



setSpeed(1); //standart hda haberle

ibuttonWriteByte(0x33); //read rom



for(i = 0; i < 8; i++)

{

serialArray[i] = ibuttonReadByte();



crc = crcTable[crc ^ serialArray[i]];

}

if((serialArray[0] > 0) && (crc == 0))

{

return TRUE;

}

else

{

extIntInit();

return FALSE;

}

}







//
Thank you for your suggestions.

I tryed to compile your code but I got an error in setSpeed() function
for H and J standard values because I assumed that their size is 8-bits.

ibutton.c(97): warning: #69-D: integer conversion resulted in truncation
ibutton.c(99): warning: #69-D: integer conversion resulted in truncation
And the delayUs() function really accepts microseconds as input?
Moreover what do you mean with the functions
interrupt[Open|Close|Release]() ?

Yes you are right for H and J it is error.
delayUs() really accept microseconds as input.

int. open:
write vector register
write ctrl register
write enable register
int. close:
write enable clear register
int. release:
VICVectAddr = 0x00000000;
----- Original Message ----
From: carlochiesa78
To: l...
Sent: Tuesday, September 16, 2008 11:04:12 AM
Subject: [lpc2000] Re: 1-wire driver
Thank you for your suggestions.

I tryed to compile your code but I got an error in setSpeed() function
for H and J standard values because I assumed that their size is 8-bits.

ibutton.c(97) : warning: #69-D: integer conversion resulted in truncation
ibutton.c(99) : warning: #69-D: integer conversion resulted in truncation

And the delayUs() function really accepts microseconds as input?

Moreover what do you mean with the functions
interrupt[Open| Close|Release] () ?





Hi Mehmet,

is it OK if I use your code in an open source project (http://www.vscp.org)?

Cheers
/Ake

On Tue, Sep 16, 2008 at 1:59 PM, Mehmet Kurnaz wrote:
> Yes you are right for H and J it is error.
> delayUs() really accept microseconds as input.
>
> int. open:
> write vector register
> write ctrl register
> write enable register
> int. close:
> write enable clear register
> int. release:
> VICVectAddr = 0x00000000;
>
> ----- Original Message ----
> From: carlochiesa78
> To: l...
> Sent: Tuesday, September 16, 2008 11:04:12 AM
> Subject: [lpc2000] Re: 1-wire driver
>
> Thank you for your suggestions.
>
> I tryed to compile your code but I got an error in setSpeed() function
> for H and J standard values because I assumed that their size is 8-bits.
>
> ibutton.c(97) : warning: #69-D: integer conversion resulted in truncation
> ibutton.c(99) : warning: #69-D: integer conversion resulted in truncation
>
> And the delayUs() function really accepts microseconds as input?
>
> Moreover what do you mean with the functions
> interrupt[Open| Close|Release] () ?
>
>

--
---
Ake Hedman (YAP - Yet Another Programmer)
D of Scandinavia, Brattbergavagen 17, 820 50 LOS, Sweden
Phone: (46) 73 0533 146
Company home: http://www.dofscandinavia.com
Personal homepage: http://www.dofscandinavia.com/akhe
Automated home: http://www.vscp.org

Ok there is no problem.

----- Original Message ----
From: YAP
To: l...
Sent: Tuesday, September 16, 2008 3:48:41 PM
Subject: Re: [lpc2000] Re: 1-wire driver
Hi Mehmet,

is it OK if I use your code in an open source project (http://www.vscp. org)?

Cheers
/Ake

On Tue, Sep 16, 2008 at 1:59 PM, Mehmet Kurnaz wrote:
> Yes you are right for H and J it is error.
> delayUs() really accept microseconds as input.
>
> int. open:
> write vector register
> write ctrl register
> write enable register
> int. close:
> write enable clear register
> int. release:
> VICVectAddr = 0x00000000;
>
> ----- Original Message ----
> From: carlochiesa78
> To: lpc2000@yahoogroups .com
> Sent: Tuesday, September 16, 2008 11:04:12 AM
> Subject: [lpc2000] Re: 1-wire driver
>
> Thank you for your suggestions.
>
> I tryed to compile your code but I got an error in setSpeed() function
> for H and J standard values because I assumed that their size is 8-bits.
>
> ibutton.c(97) : warning: #69-D: integer conversion resulted in truncation
> ibutton.c(99) : warning: #69-D: integer conversion resulted in truncation
>
> And the delayUs() function really accepts microseconds as input?
>
> Moreover what do you mean with the functions
> interrupt[Open| Close|Release] () ?
>
>

--
---
Ake Hedman (YAP - Yet Another Programmer)
D of Scandinavia, Brattbergavagen 17, 820 50 LOS, Sweden
Phone: (46) 73 0533 146
Company home: http://www.dofscand inavia.com
Personal homepage: http://www.dofscand inavia.com/ akhe
Automated home: http://www.vscp. org


On Tue, Sep 16, 2008 at 8:02 PM, Mehmet Kurnaz wrote:
> Ok there is no problem.

Thanks a lot!

Cheers
/Ake

---
Ake Hedman (YAP - Yet Another Programmer)
D of Scandinavia, Brattbergavagen 17, 820 50 LOS, Sweden
Phone: (46) 73 0533 146
Company home: http://www.dofscandinavia.com
Personal homepage: http://www.dofscandinavia.com/akhe
Automated home: http://www.vscp.org


The 2024 Embedded Online Conference