Library to communicate with Maxim OneWire protocol devices Modified timings and IRQ overrides
Fork of Onewire by
Onewire.h
- Committer:
- Bobty
- Date:
- 2015-10-05
- Revision:
- 6:d2452e9b169b
- Parent:
- 4:b678c7c8203c
- Child:
- 7:0a87f8c2d9e6
File content as of revision 6:d2452e9b169b:
#ifndef Onewire_h
#define Onewire_h
#include "mbed.h"
#define ONEWIRE_ADDR_BYTES 8
const int ONEWIRE_OK = 0;
const int ONEWIRE_SEARCH_ALL_DONE = 1;
const int ONEWIRE_SEARCH_INIT_FAIL = 2;
const int ONEWIRE_SEARCH_NOT_FOUND = 3;
class Onewire
{
public:
Onewire(PinName oneBus);
void writeBit(int bit);
int readBit();
int init();
int readByte();
void writeByte(char data);
unsigned char CRC(unsigned char* addr, unsigned char len);
// Clear the search state so that if will start from the beginning again.
void reset_search();
// Look for the next device.
// Returns
// ONEWIRE_OK if a new address has been returned.
// ONEWIRE_SEARCH_ALL_DONE = all devices found
// ONEWIRE_SEARCH_INIT_FAIL = failed to init
// ONEWIRE_SEARCH_NOT_FOUND = no devices found
// It might be a good idea to check the CRC to make sure you didn't
// get garbage. The order is deterministic. You will always get
// the same devices in the same order.
uint8_t search(uint8_t *newAddr);
private:
DigitalInOut oneBus_;
// search state
unsigned char _search_ROM_NO[8];
uint8_t _search_LastDiscrepancy;
uint8_t _search_LastFamilyDiscrepancy;
uint8_t _search_LastDeviceFlag;
};
#endif
