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

DS2431 wrong answer (0x55) at Copy Scratchpad Command #133

Open
bauergeorg opened this issue Sep 12, 2023 · 1 comment
Open

DS2431 wrong answer (0x55) at Copy Scratchpad Command #133

bauergeorg opened this issue Sep 12, 2023 · 1 comment

Comments

@bauergeorg
Copy link

Hi folks,
we are using OneWireHub and we are very happy about this cool project. Thanks a lot!

Bug
By using the DS2431 with an own server implementation we found a hysteric behavior by writing memory function.
I found a different behavior between the real chip and the emulation. The real chip answers with 0xAA, the emulation answers with 0x55 (or different) during the “Copy Scratchpad” procedure.

Here is an extract of the DS2431s datasheet.

image

Below you can see a timing diagram of a logic analyzer (Saleae Logic Analyzer) of the real chip (Answer 0xAA):
image

Below you can see a timing diagram of a logic analyzer (Saleae Logic Analyzer) of the emulated chip (Answer 0x55):
image

Environment

  • We found the line in the code. But we can’t find any error. It looks perfect.
  • We used a Arduino Nano and a Arduino Uno. Same devices showed the same behavior (answering 0x55).
  • Changing the timing behavior (changing a little bit the code) we saw in some case an answer 0xFF.
  • We checked the same behavior with two one-wire-master applications: an own python application and Maxim's OneWireViewer.

Thank's a lot!

Georg

@bauergeorg
Copy link
Author

Comparing last commit bring me to change folling code section:

OneWireHub/src/DS2431.cpp

Lines 92 to 126 in 68e9392

case 0x55: // COPY SCRATCHPAD COMMAND
if (hub->recv(&data)) return;
if (data != reinterpret_cast<uint8_t *>(&reg_TA)[0]) break;
if (hub->recv(&data)) return;
if (data != reinterpret_cast<uint8_t *>(&reg_TA)[1]) break;
if (hub->recv(&data)) return;
if (data != reg_ES) return; // Auth code must match
if (getPageProtection(uint8_t(reg_TA)))
break; // stop if page is protected (WriteMemory also checks this)
if ((reg_ES & REG_ES_PF_MASK) != 0) break; // stop if error occurred earlier
reg_ES |= REG_ES_AA_MASK; // compare was successful
reg_TA &= ~uint16_t(SCRATCHPAD_MASK);
// Write Scratchpad to memory, writing takes about 10ms
writeMemory(scratchpad, SCRATCHPAD_SIZE,
reinterpret_cast<uint8_t *>(&reg_TA)[0]); // checks if copy protected
noInterrupts();
do {
hub->clearError();
hub->sendBit(true); // send passive 1s
}
while (hub->getError() == Error::AWAIT_TIMESLOT_TIMEOUT_HIGH); // wait for timeslots
interrupts();
while (!hub->send(&ALTERNATING_10))
; // alternating 1 & 0 after copy is complete
break;

My solution:
image

And I will see 0xAA with my own master and Maxims's one-wire-viewer. (The one wire viewer checks only 0xFF and not 0x55 as an wrong answer to copy scratchpad command).

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

1 participant