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
Onewire.h@1:8e9464e05ddf, 2015-02-21 (annotated)
- Committer:
- Bobty
- Date:
- Sat Feb 21 17:16:16 2015 +0000
- Revision:
- 1:8e9464e05ddf
- Parent:
- 0:d961f715d82b
- Child:
- 4:b678c7c8203c
Added search function to find existing addresses
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| simonbarker | 0:d961f715d82b | 1 | #ifndef Onewire_h |
| simonbarker | 0:d961f715d82b | 2 | #define Onewire_h |
| simonbarker | 0:d961f715d82b | 3 | |
| simonbarker | 0:d961f715d82b | 4 | #include "mbed.h" |
| simonbarker | 0:d961f715d82b | 5 | |
| simonbarker | 0:d961f715d82b | 6 | class Onewire{ |
| simonbarker | 0:d961f715d82b | 7 | |
| simonbarker | 0:d961f715d82b | 8 | public: |
| Bobty | 1:8e9464e05ddf | 9 | Onewire(PinName oneBus); |
| Bobty | 1:8e9464e05ddf | 10 | void writeBit(int bit); |
| simonbarker | 0:d961f715d82b | 11 | int readBit(); |
| simonbarker | 0:d961f715d82b | 12 | int init(); |
| simonbarker | 0:d961f715d82b | 13 | int readByte(); |
| simonbarker | 0:d961f715d82b | 14 | void writeByte(char data); |
| simonbarker | 0:d961f715d82b | 15 | unsigned char CRC(unsigned char* addr, unsigned char len); |
| simonbarker | 0:d961f715d82b | 16 | |
| Bobty | 1:8e9464e05ddf | 17 | // Clear the search state so that if will start from the beginning again. |
| Bobty | 1:8e9464e05ddf | 18 | void reset_search(); |
| Bobty | 1:8e9464e05ddf | 19 | // Look for the next device. Returns 1 if a new address has been |
| Bobty | 1:8e9464e05ddf | 20 | // returned. A zero might mean that the bus is shorted, there are |
| Bobty | 1:8e9464e05ddf | 21 | // no devices, or you have already retrieved all of them. It |
| Bobty | 1:8e9464e05ddf | 22 | // might be a good idea to check the CRC to make sure you didn't |
| Bobty | 1:8e9464e05ddf | 23 | // get garbage. The order is deterministic. You will always get |
| Bobty | 1:8e9464e05ddf | 24 | // the same devices in the same order. |
| Bobty | 1:8e9464e05ddf | 25 | uint8_t search(uint8_t *newAddr); |
| Bobty | 1:8e9464e05ddf | 26 | |
| simonbarker | 0:d961f715d82b | 27 | private: |
| Bobty | 1:8e9464e05ddf | 28 | DigitalInOut oneBus_; |
| Bobty | 1:8e9464e05ddf | 29 | |
| Bobty | 1:8e9464e05ddf | 30 | // search state |
| Bobty | 1:8e9464e05ddf | 31 | unsigned char _search_ROM_NO[8]; |
| Bobty | 1:8e9464e05ddf | 32 | uint8_t _search_LastDiscrepancy; |
| Bobty | 1:8e9464e05ddf | 33 | uint8_t _search_LastFamilyDiscrepancy; |
| Bobty | 1:8e9464e05ddf | 34 | uint8_t _search_LastDeviceFlag; |
| simonbarker | 0:d961f715d82b | 35 | }; |
| simonbarker | 0:d961f715d82b | 36 | #endif |
