Electronics > Beginners
How to Implement 1-wire Devices
(1/6) > >>
Docara:
Hi,

I wish to implement 3x temperature sensing, remote I/O Switches, RTCC and possibly EEPROM functionality on one 1-wire bus. It seems the use of a Master DS2840B line driver which incorporates a search algorithm (partial) 12C to RS232 conversion would aide things no-end.

Initially, I looked into using an Arduino and an available library but, generally, they seem flaky and only meant for one DS18B20 device.


Looking through the Datasheets - I am struggling to properly understand the communication requirements of these devices. For a non-programmer - the search algorithm, even with the DS2840B, looks horrendous to implement as does the CRC on the fly checking.

Has anyone used these in anger and could offer some guidance?

Many thanks
Matt

P.S. this is the best example of real world example I could findhttp://itech.fgcu.edu/faculty/zalewski/CDA4170/files/1wire.pdf] [url]http://itech.fgcu.edu/faculty/zalewski/CDA4170/files/1wire.pdf[/url]
BradC:
I did it in a PIC 12F615 in C, so it's not hard. I was memory constrained for storing the serial numbers so I simply iterated the search algorithm and then reported the temperature of the next sensor as they were detected. I also do it in SPIN on a Parallax Propeller. Again, not difficult and much easier when you have more ram to play with.

If I get a chance over the next couple of days I'll see if I can dig out the code and post it.
madires:
You can download several app notes on 1-Wire from Maxim which explain everything, some include code examples. Though, the slightly different specs for the protocol timing in each app note are a bit confusing. The search algorithm for ROM codes is similar to a binary search tree. And there are tons of examples for CRC8 and CRC16 (be aware that different CRC versions use different polynomials and start values).

This is the CRC8 I've written:


--- Code: ---/* CRC */
uint8_t        CRC8;          /* current CRC-8 */

/*
 *  calculate CRC-8
 *  - CRC = X^8 + X^5 + X^4 + 1
 *  - start value: 0x00
 *  - uses variable CRC8 to track current CRC
 *
 *  requires:
 *  - Byte: new input byte
 */

void OneWire_CRC8(uint8_t Byte)
{
  uint8_t           n = 0;         /* counter */
  uint8_t           Bit;           /* LSB */

  while (n < 8)          /* 8 bits */
  {
    /* XOR current LSB of input with CRC8's current X^8 */
    Bit = CRC8 ^ Byte;        /* XOR */
    Bit &= 0b00000001;        /* filter LSB */

    /* shift CRC right */
    CRC8 >>= 1;               /* for next bit */

    if (Bit)                  /* XORed LSB is 1 */
    {
      /*
       *  XOR CRC's X^5 and X^4 with 1
       *  - XOR with 0b00011000
       *  - since CRC is already shifted right: XOR with 0b00001100
       *  - since we have to feed the XORed LSB back into the CRC
       *    and the MSB is 0 after shifting: XOR with 0b10001100
       */

      CRC8 ^= 0b10001100;     /* XOR */
    }
    /*  when 0:
     *  - XOR would keep the original bits
     *  - MSB will be 0 after a right shift anyway
     */

    /* shift input right */
    Byte >>= 1;               /* for next input bit */

    n++;                      /* next bit */
  }
}


--- End code ---
Docara:
Hi Brad,

Thanks for the reply.

I have to be honest I was wondering to whether or not to just kick the search algorithm into touch and just do a local 1 pin bit banged search for any new or replacement devices.

As you have programmed the 1-wire stuff would you mind doing me a favour and a look through the DS2840B datasheets and let me know if using this might have made things easier for you

https://www.maximintegrated.com/en/products/interface/controllers-expanders/DS2480B.html
http://pdfserv.maximintegrated.com/en/an/AN192.pdf

Thanks
Matt
towlerg:
Definatley the bit bang, save serial numbers is eeprom (if you have). Where you have more than one temperature sensor you usually need to know pyhsically where each device is, either write one time data collection routine or if you're lazy use your programmer to write directly to eeprom.

If you don't have eeprom most processors will allow you to read and write program memory.

As to libruaries I know thats the Arduino goto move but if I were you I would dissect a working lib for the bit bang and work from there.
Navigation
Message Index
Next page
There was an error while thanking
Thanking...

Go to full version
Powered by SMFPacks Advanced Attachments Uploader Mod