Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of OneWire by
Revision 7:a42114ac702f, committed 2017-09-12
- Comitter:
- mooreaa
- Date:
- Tue Sep 12 20:28:25 2017 +0000
- Parent:
- 6:28e60d774095
- Commit message:
- Initial tweaks to get library to perform correctly
Changed in this revision
OneWire.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 28e60d774095 -r a42114ac702f OneWire.cpp --- a/OneWire.cpp Sat Sep 09 09:10:49 2017 +0000 +++ b/OneWire.cpp Tue Sep 12 20:28:25 2017 +0000 @@ -137,67 +137,63 @@ { uint16_t retries = 20000; - /*if( reset(false) == ONEWIRE_ERROR ) - return ONEWIRE_ERROR;*/ - + //if( reset() != ONEWIRE_OK ) + // return ONEWIRE_ERROR; + reset(); - //wire.input(); should be input coming out of reset + //wire.input(); should be input coming out of reset + wait_us(80); - /* uint8_t result = wire.read_bit(); - - if ( result == 0 ) + while( wire == 0 ) { - while( result == 0) - { - result = wire.read_bit(); - - if (--retries == 0) { - return ONEWIRE_NO_RESPONSE; - } + if (--retries == 0) { + return ONEWIRE_NO_RESPONSE; } - - return ONEWIRE_OK; + wait_us(20); } - return ONEWIRE_NO_RESPONSE;*/ + return ONEWIRE_OK; + + - return ONEWIRE_OK; } uint8_t OneWire::reset( bool force/* = true*/ ) { - uint8_t retries = 125; + /*uint8_t retries = 125; - /*wire.input(); - // wait until the wire is high... just in case - do { - if (--retries == 0) { - if( force ) + wire.input(); + // wait until the wire is high... just in case + + do { + if (--retries == 0) + { + if( force ) break; else return ONEWIRE_ERROR; } wait_us(2); - } while (wire.read() != 1);*/ + } while (wire != 1);*/ wire.output(); wire = 0; - wait_us(500); + wait_us(480); wire.input(); - wait_us(70); - uint8_t err = wire; //just do the reset, use init_seq function to do more + //wait_us(70); + /*uint8_t err = wire; //just do the reset, use init_seq function to do more wait_us(240); if ( wire == 0 ) { // short circuit printf("OneWire::reset SHORT_CIRCUIT\r\n"); return ONEWIRE_ERROR_SHORT_CIRCUIT; - } + }*/ - printf("OneWire::reset OK\r\n"); + //printf("OneWire::reset OK\r\n"); return ONEWIRE_OK; } @@ -234,9 +230,10 @@ wire = 0; wait_us(2); //modified to meet ray's values wire.input(); - wait_us(14); - r = wire; - wait_us(45); + wait_us(14); + r = wire.read(); + wait_us(48); + return r; } @@ -250,7 +247,7 @@ void OneWire::write(uint8_t v, uint8_t power /* = 0 */) { uint8_t bitMask; - printf("OneWire::write => %#x\r\n", v); + //printf("OneWire::write => %#x\r\n", v); for (bitMask = 0x01; bitMask; bitMask <<= 1) { OneWire::write_bit( (bitMask & v)?1:0); @@ -279,15 +276,19 @@ uint8_t bitMask; uint8_t r = 0; - for (bitMask = 0x01; bitMask; bitMask <<= 1) { - if ( OneWire::read_bit()) r |= bitMask; + for (bitMask = 0x01; bitMask; bitMask <<= 1) + { + if ( OneWire::read_bit()) r |= bitMask; } + return r; } void OneWire::read_bytes(uint8_t *buf, uint16_t count) { - for (uint16_t i = 0 ; i < count ; i++) - buf[i] = read(); + for (uint16_t i = 0 ; i < count ; i++) + { + buf[i] = read(); + } } //