Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 3 of 3

Thread: OneWire library for Teensy 3 (DS18B20)

  1. #1
    Senior Member
    Join Date
    Nov 2012
    Posts
    357

    OneWire library for Teensy 3 (DS18B20)

    I've been trying to get the OneWire library working so that I can use a DS18B20 and have finally succeeded. I started with Paul's OneWire library V2.1 for the Arduino which can be downloaded here: http://www.pjrc.com/teensy/td_libs_OneWire.html
    Unzip it into your libraries directory.

    In OneWire.cpp two changes are required to remove the use of PROGMEM from the original Arduino code.
    - at line 439 remove PROGMEM from the declaration.
    - change line 469 from this:
    Code:
    		crc = pgm_read_byte(dscrc_table + (crc ^ *addr++));
    to this:
    Code:
    		crc = dscrc_table[crc ^ *addr++];
    In OneWire.h at line 77 is this code:
    Code:
    #else
    //#error "Please define I/O register types here"
    #endif
    Change those three lines to this:
    Code:
    #else
    // PAH - add 1Wire for Teensy 3 (works with DS18B20)
    #define PIN_TO_BASEREG(pin)             (digital_pin_to_info_PGM[(pin)].reg)
    #define PIN_TO_BITMASK(pin)             (1)
    #define IO_REG_TYPE uint32_t
    #define IO_REG_ASM
    #define DIRECT_READ(base, mask)         (*(base+128))
    #define DIRECT_MODE_INPUT(base, mask)   (*(base+160) = PORT_PCR_MUX(1))
    #define DIRECT_MODE_OUTPUT(base, mask)  (*(base+160) = 1)
    #define DIRECT_WRITE_LOW(base, mask)    (*(base+64) = 1)
    #define DIRECT_WRITE_HIGH(base, mask)   (*(base+32) = 1)
    #endif
    I've only tested it with the DS18B20 but the device is found and the temperature is read so it's at least a good start :-)
    When Paul has time perhaps he can cast his experienced eye over my fixes to make sure I've done this properly and haven't missed anything.

    Pete

  2. #2
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    4,658
    I am working on OneWire 2.2, with support for Teensy 3.0 and several small improvements.

    Here's a pre-release copy. Please let me know how it works if you try it?

    http://www.pjrc.com/teensy/beta/OneW...22_17jan13.zip

  3. #3
    Senior Member
    Join Date
    Nov 2012
    Posts
    357
    It works with the DS18B20 which is the only onewire device I have.

    Pete

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •