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