This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

interfacing LPC2368 with DS1820

Hi ,
I have problems with interfacing DS1820 to LPC2368. i can see only "127" on display. Thnks.

Parents
  • Hi,

    I have problems with communicating LPC2368 and DS1820

    I connected DS1820 to P2.7 pin of LPC. and 4.7K to Vdd of LPC.

    i connected DS1820 's Vdd pin to 5Vdc. Because in datasheet i saw that DS1820's working voltage is between 3.6V - 5V. LPC Vdd is 3.2V

    And here is my code :

    ----------------------------------------------------

    #define DQ_SET FIO2SET |= 0x00000080;
    #define DQ_CLR FIO2CLR |= 0x00000080;

    void onewire_reset()

    {

    FIO2DIR = 0XFFFFFFFF; FIO2MASK = 0xFFFFFF00;

    DQ_CLR delay_us(600); DQ_SET delay_us(600); DQ_CLR

    }

    void command(BYTE data) { int i;

    FIO2DIR = 0XFFFFFFFF; FIO2MASK = 0xFFFFFF00;

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

    DQ_CLR

    delay_us(16);

    if (data & 1 << i) DQ_SET

    else DQ_CLR

    delay_us(240);

    DQ_SET

    delay_us(16);

    } }

    int read_bit() { int bit=1;

    FIO2DIR = 0XFFFFFFFF; FIO2MASK = 0xFFFFFF00;

    DQ_CLR

    delay_us(16);

    DQ_SET

    delay_us(16);

    FIO2DIR = 0XFFFFFF7F; FIO2MASK = 0xFFFFFF00;

    if(!(FIO2PIN & 128)) bit=0;

    return bit;

    }

    unsigned char read_byte(void)
    { unsigned char i;
    unsigned char value = 0;

    for (i=0;i<8;i++)
    { if( read_bit() ) value|= 1 << i; delay_us(240);

    }
    return(value);
    }

    unsigned char Read_Temperature(void)
    { int lsb=0; int msb=0; int temp=0; float temp_c=0;

    onewire_reset();

    command(0xCC); command(0x44);

    onewire_reset();

    command(0xCC); command(0xBE);

    msb = read_byte(); // Read msb

    lsb = read_byte();

    temp = msb<<8 + lsb;

    temp_c = (temp>>5) * 0.125;

    sprintf(sicaklik_deger,"T:%2.1f",temp_c);

    return(1);

    }

Reply
  • Hi,

    I have problems with communicating LPC2368 and DS1820

    I connected DS1820 to P2.7 pin of LPC. and 4.7K to Vdd of LPC.

    i connected DS1820 's Vdd pin to 5Vdc. Because in datasheet i saw that DS1820's working voltage is between 3.6V - 5V. LPC Vdd is 3.2V

    And here is my code :

    ----------------------------------------------------

    #define DQ_SET FIO2SET |= 0x00000080;
    #define DQ_CLR FIO2CLR |= 0x00000080;

    void onewire_reset()

    {

    FIO2DIR = 0XFFFFFFFF; FIO2MASK = 0xFFFFFF00;

    DQ_CLR delay_us(600); DQ_SET delay_us(600); DQ_CLR

    }

    void command(BYTE data) { int i;

    FIO2DIR = 0XFFFFFFFF; FIO2MASK = 0xFFFFFF00;

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

    DQ_CLR

    delay_us(16);

    if (data & 1 << i) DQ_SET

    else DQ_CLR

    delay_us(240);

    DQ_SET

    delay_us(16);

    } }

    int read_bit() { int bit=1;

    FIO2DIR = 0XFFFFFFFF; FIO2MASK = 0xFFFFFF00;

    DQ_CLR

    delay_us(16);

    DQ_SET

    delay_us(16);

    FIO2DIR = 0XFFFFFF7F; FIO2MASK = 0xFFFFFF00;

    if(!(FIO2PIN & 128)) bit=0;

    return bit;

    }

    unsigned char read_byte(void)
    { unsigned char i;
    unsigned char value = 0;

    for (i=0;i<8;i++)
    { if( read_bit() ) value|= 1 << i; delay_us(240);

    }
    return(value);
    }

    unsigned char Read_Temperature(void)
    { int lsb=0; int msb=0; int temp=0; float temp_c=0;

    onewire_reset();

    command(0xCC); command(0x44);

    onewire_reset();

    command(0xCC); command(0xBE);

    msb = read_byte(); // Read msb

    lsb = read_byte();

    temp = msb<<8 + lsb;

    temp_c = (temp>>5) * 0.125;

    sprintf(sicaklik_deger,"T:%2.1f",temp_c);

    return(1);

    }

Children