Library to communicate with Maxim OneWire protocol devices Modified timings and IRQ overrides
Fork of Onewire by
Onewire.h@6:d2452e9b169b, 2015-10-05 (annotated)
- Committer:
- Bobty
- Date:
- Mon Oct 05 14:03:29 2015 +0000
- Revision:
- 6:d2452e9b169b
- Parent:
- 4:b678c7c8203c
- Child:
- 7:0a87f8c2d9e6
Changed return code from search to be more meaningful about the reason for failure
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 | |
Bobty | 4:b678c7c8203c | 6 | #define ONEWIRE_ADDR_BYTES 8 |
Bobty | 4:b678c7c8203c | 7 | |
Bobty | 6:d2452e9b169b | 8 | const int ONEWIRE_OK = 0; |
Bobty | 6:d2452e9b169b | 9 | const int ONEWIRE_SEARCH_ALL_DONE = 1; |
Bobty | 6:d2452e9b169b | 10 | const int ONEWIRE_SEARCH_INIT_FAIL = 2; |
Bobty | 6:d2452e9b169b | 11 | const int ONEWIRE_SEARCH_NOT_FOUND = 3; |
simonbarker | 0:d961f715d82b | 12 | |
Bobty | 6:d2452e9b169b | 13 | class Onewire |
Bobty | 6:d2452e9b169b | 14 | { |
Bobty | 6:d2452e9b169b | 15 | |
Bobty | 6:d2452e9b169b | 16 | public: |
Bobty | 1:8e9464e05ddf | 17 | Onewire(PinName oneBus); |
Bobty | 1:8e9464e05ddf | 18 | void writeBit(int bit); |
simonbarker | 0:d961f715d82b | 19 | int readBit(); |
simonbarker | 0:d961f715d82b | 20 | int init(); |
simonbarker | 0:d961f715d82b | 21 | int readByte(); |
simonbarker | 0:d961f715d82b | 22 | void writeByte(char data); |
simonbarker | 0:d961f715d82b | 23 | unsigned char CRC(unsigned char* addr, unsigned char len); |
simonbarker | 0:d961f715d82b | 24 | |
Bobty | 1:8e9464e05ddf | 25 | // Clear the search state so that if will start from the beginning again. |
Bobty | 1:8e9464e05ddf | 26 | void reset_search(); |
Bobty | 6:d2452e9b169b | 27 | // Look for the next device. |
Bobty | 6:d2452e9b169b | 28 | // Returns |
Bobty | 6:d2452e9b169b | 29 | // ONEWIRE_OK if a new address has been returned. |
Bobty | 6:d2452e9b169b | 30 | // ONEWIRE_SEARCH_ALL_DONE = all devices found |
Bobty | 6:d2452e9b169b | 31 | // ONEWIRE_SEARCH_INIT_FAIL = failed to init |
Bobty | 6:d2452e9b169b | 32 | // ONEWIRE_SEARCH_NOT_FOUND = no devices found |
Bobty | 6:d2452e9b169b | 33 | // It might be a good idea to check the CRC to make sure you didn't |
Bobty | 1:8e9464e05ddf | 34 | // get garbage. The order is deterministic. You will always get |
Bobty | 1:8e9464e05ddf | 35 | // the same devices in the same order. |
Bobty | 1:8e9464e05ddf | 36 | uint8_t search(uint8_t *newAddr); |
Bobty | 1:8e9464e05ddf | 37 | |
simonbarker | 0:d961f715d82b | 38 | private: |
Bobty | 1:8e9464e05ddf | 39 | DigitalInOut oneBus_; |
Bobty | 1:8e9464e05ddf | 40 | |
Bobty | 1:8e9464e05ddf | 41 | // search state |
Bobty | 1:8e9464e05ddf | 42 | unsigned char _search_ROM_NO[8]; |
Bobty | 1:8e9464e05ddf | 43 | uint8_t _search_LastDiscrepancy; |
Bobty | 1:8e9464e05ddf | 44 | uint8_t _search_LastFamilyDiscrepancy; |
Bobty | 1:8e9464e05ddf | 45 | uint8_t _search_LastDeviceFlag; |
simonbarker | 0:d961f715d82b | 46 | }; |
simonbarker | 0:d961f715d82b | 47 | #endif |