Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DS2413 device communication protocol not implemented correctly #79

Open
thomasesr opened this issue Jun 24, 2019 · 3 comments
Open

DS2413 device communication protocol not implemented correctly #79

thomasesr opened this issue Jun 24, 2019 · 3 comments

Comments

@thomasesr
Copy link

Ack Success (0xAA) and Ack Failure(0xFF) Bytes are not implemented correctly on the DS2413 emulated device. The proper protocol should be
Master: Reset
Slave: Presence Pulse
Master: Select ROM
Master: 0x5A - Access Write
Master: 0xFE - Turn on Latch A
Master: 0x01 - Inverse of previous Byte for integrity check
Slave: 0xAA - if Success 0xFF - if Failure
slave: 0x3C - Access Read byte with PIO and Latch states
Master: Reset pulse

@orgua
Copy link
Owner

orgua commented Dec 29, 2019

Yeah, you could be right! Also there seems to be an endless loop for more latching after that. Don't know how i could miss that! Will look into it

@lindenaar
Copy link

I fixed this in my local install in this way, in src/DS2413.cpp I replaced

void DS2413::duty(OneWireHub * const hub)
{
    uint8_t cmd, data, check;

    if (hub->recv(&cmd)) return;

    switch (cmd)
    {
        case 0x5A:      // PIO ACCESS WRITE

            if (hub->recv(&data)) return;
            data = ~data; // Write inverse

            if (hub->send(&data)) return; // send inverted form for safety
            setPinLatch(0, (data & static_cast<uint8_t>(0x01)) != 0);// A
            setPinLatch(1, (data & static_cast<uint8_t>(0x02)) != 0);// B

            break;

        case 0xF5:      // PIO ACCESS READ

            data = 0;

with

void DS2413::duty(OneWireHub * const hub)
{
    uint8_t cmd, data, check;

    if (hub->recv(&cmd)) return;

    switch (cmd)
    {
        case 0x5A:      // PIO ACCESS WRITE

            if (hub->recv(&data)) return;
            data = ~data; // Write inverse

            if (hub->recv(&check)) return;
            if (data == check) {
                    setPinLatch(0, (data & static_cast<uint8_t>(0x01)) != 0);// A
                    setPinLatch(1, (data & static_cast<uint8_t>(0x02)) != 0);// B
                    hub->send(0xAA);
                    goto sendstatus;
            } else {
                    hub->send(0xFF);
            }

            break;

        case 0xF5:      // PIO ACCESS READ
sendstatus:
            data = 0;

Which seems in line with the datasheet and stops my Raspberry Pi giving read errors on the device.

@Koxx3
Copy link

Koxx3 commented Apr 19, 2021

I confirm ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants