Пытаюсь на основе библиотеки для DS2406https://github.com/dustin/arduino-2406
сделать библиотеку для DS2413.
Вроде бы согласно даташиту поменял все, но упорно не работает.
Кто-нибудь сталкивался с подобным.
Подскажите,где ошибка
Спасибо.
ds2413.h
Код: Выделить всё
#include <OneWire.h>
#include <inttypes.h>
#define DS2413_FAMILY 0x3A
#define DS2413_WRITE_STATUS 0x5A
#define DS2413_READ_STATUS 0xF5
#define PIO_A 0x20
#define PIO_B 0x40
// Represents a single 1wire switch on an MLan.
class ds2413Switch {
public:
// Construct the OneWireSwitch with the given OneWire bus and address.
// addr must be 8 bytes.
ds2413Switch(OneWire *b, uint8_t *addr);
// Get the switch state.
// An optional argument indicates *which* switch state in the case
// where you have a TSOC package with two ports.
bool get2413State(int port = PIO_A);
// Set the switch state(s).
void set2413State(bool pio_a, bool pio_b = false);
private:
OneWire *bus;
uint8_t address[8];
void read2413Status(uint8_t *buffer);
};
Код: Выделить всё
#include <DS2413.h>
ds2413Switch::ds2413Switch(OneWire *b, uint8_t *addr) {
bus = b;
for(int i = 0; i<8; i++) {
address[i] = addr[i];
}
}
bool ds2413Switch::get2413State(int port) {
uint8_t status[10];
read2413Status(status);
return (status[7] & port) == 0;
}
void ds2413Switch::set2413State(bool pio_a, bool pio_b) {
uint8_t state = (pio_a << 5) | (pio_b << 6) | 0xf;
bus->reset();
bus->select(address);
bus->write(DS2413_WRITE_STATUS);
bus->write(0xF0);
bus->write(0);
bus->write(state);
// Read the CRC data
for (int i = 0; i < 6; i++) {
bus->read();
}
// Write the status back.
bus->write(0xFF,1);
}
void ds2413Switch::read2413Status(uint8_t *buffer) {
bus->reset();
bus->select(address);
bus->write(DS2413_READ_STATUS, 1);
bus->write(0, 1);
bus->write(0, 1);
for(int i = 0; i<10; i++) {
buffer[i] = bus->read();
}
bus->reset();
}