Library to communicate with Maxim OneWire protocol devices Modified timings and IRQ overrides
Fork of Onewire by
Onewire.h
00001 #ifndef Onewire_h 00002 #define Onewire_h 00003 00004 #include "mbed.h" 00005 00006 #define ONEWIRE_ADDR_BYTES 8 00007 00008 const int ONEWIRE_OK = 0; 00009 const int ONEWIRE_FAIL_STUCK_LOW = 1; 00010 const int ONEWIRE_SEARCH_ALL_DONE = 2; 00011 const int ONEWIRE_SEARCH_INIT_FAIL = 3; 00012 const int ONEWIRE_SEARCH_NOT_FOUND = 4; 00013 const int ONEWIRE_SEARCH_COMP_BIT_ERR = 5; 00014 00015 class Onewire 00016 { 00017 00018 public: 00019 Onewire(PinName oneBus); 00020 void writeBit(int bit); 00021 int readBit(); 00022 int init(); 00023 int readByte(); 00024 void writeByte(char data); 00025 unsigned char CRC(unsigned char* addr, unsigned char len); 00026 char* GetErrorStr(int errCode); 00027 00028 // Clear the search state so that if will start from the beginning again. 00029 void reset_search(); 00030 // Look for the next device. 00031 // Returns 00032 // ONEWIRE_OK if a new address has been returned. 00033 // ONEWIRE_SEARCH_ALL_DONE = all devices found 00034 // ONEWIRE_SEARCH_INIT_FAIL = failed to init 00035 // ONEWIRE_SEARCH_NOT_FOUND = no devices found 00036 // It might be a good idea to check the CRC to make sure you didn't 00037 // get garbage. The order is deterministic. You will always get 00038 // the same devices in the same order. 00039 uint8_t search(uint8_t *newAddr); 00040 00041 private: 00042 DigitalInOut oneBus_; 00043 00044 // search state 00045 unsigned char _search_ROM_NO[8]; 00046 uint8_t _search_LastDiscrepancy; 00047 uint8_t _search_LastFamilyDiscrepancy; 00048 uint8_t _search_LastDeviceFlag; 00049 }; 00050 #endif
Generated on Tue Jul 12 2022 21:42:30 by
1.7.2
