Library to communicate with Maxim OneWire protocol devices Modified timings and IRQ overrides
Fork of Onewire by
Onewire.h@4:b678c7c8203c, 2015-02-21 (annotated)
- Committer:
- Bobty
- Date:
- Sat Feb 21 18:01:10 2015 +0000
- Revision:
- 4:b678c7c8203c
- Parent:
- 1:8e9464e05ddf
- Child:
- 6:d2452e9b169b
Tidied up
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 | |
simonbarker | 0:d961f715d82b | 8 | class Onewire{ |
simonbarker | 0:d961f715d82b | 9 | |
simonbarker | 0:d961f715d82b | 10 | public: |
Bobty | 1:8e9464e05ddf | 11 | Onewire(PinName oneBus); |
Bobty | 1:8e9464e05ddf | 12 | void writeBit(int bit); |
simonbarker | 0:d961f715d82b | 13 | int readBit(); |
simonbarker | 0:d961f715d82b | 14 | int init(); |
simonbarker | 0:d961f715d82b | 15 | int readByte(); |
simonbarker | 0:d961f715d82b | 16 | void writeByte(char data); |
simonbarker | 0:d961f715d82b | 17 | unsigned char CRC(unsigned char* addr, unsigned char len); |
simonbarker | 0:d961f715d82b | 18 | |
Bobty | 1:8e9464e05ddf | 19 | // Clear the search state so that if will start from the beginning again. |
Bobty | 1:8e9464e05ddf | 20 | void reset_search(); |
Bobty | 1:8e9464e05ddf | 21 | // Look for the next device. Returns 1 if a new address has been |
Bobty | 1:8e9464e05ddf | 22 | // returned. A zero might mean that the bus is shorted, there are |
Bobty | 1:8e9464e05ddf | 23 | // no devices, or you have already retrieved all of them. It |
Bobty | 1:8e9464e05ddf | 24 | // might be a good idea to check the CRC to make sure you didn't |
Bobty | 1:8e9464e05ddf | 25 | // get garbage. The order is deterministic. You will always get |
Bobty | 1:8e9464e05ddf | 26 | // the same devices in the same order. |
Bobty | 1:8e9464e05ddf | 27 | uint8_t search(uint8_t *newAddr); |
Bobty | 1:8e9464e05ddf | 28 | |
simonbarker | 0:d961f715d82b | 29 | private: |
Bobty | 1:8e9464e05ddf | 30 | DigitalInOut oneBus_; |
Bobty | 1:8e9464e05ddf | 31 | |
Bobty | 1:8e9464e05ddf | 32 | // search state |
Bobty | 1:8e9464e05ddf | 33 | unsigned char _search_ROM_NO[8]; |
Bobty | 1:8e9464e05ddf | 34 | uint8_t _search_LastDiscrepancy; |
Bobty | 1:8e9464e05ddf | 35 | uint8_t _search_LastFamilyDiscrepancy; |
Bobty | 1:8e9464e05ddf | 36 | uint8_t _search_LastDeviceFlag; |
simonbarker | 0:d961f715d82b | 37 | }; |
simonbarker | 0:d961f715d82b | 38 | #endif |