MarkusLange / OneWireSlave

38 stars 9 forks source link

Issues emulating #6

Closed fdenzer closed 8 years ago

fdenzer commented 8 years ago

Project does not work for me

Two different programs do not recognize an emulated DS1990a:

My source code:

#include "OneWireSlave.h"

unsigned char rom[8] = {0x28, 0xAD, 0xDA, 0xCE, 0x0F, 0x00, 0x11, 0x00};

unsigned char scratchpad[10] = {0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01};

//{0x01, 0xC8, 0x01, 0x4B, 0x46, 0x7F, 0xFF, 0x08, 0x10, 0x3F};

OneWireSlave ds(2); //+5V behind Resistor and connection on pin 2

void setup() {
  Serial.begin(9600);
  ds.init(rom);
}

void loop() {
  Serial.println("loop");
  ds.waitForRequest(false);
}

One of the readers looks like this and runs on a separate Arduino Uno. It was originally written for DS1992 so loops taking memory into account might not end soon enough, yet i did not even get to this point. Disabling if (presence) continue seemed to not help much (see not yet proposed commit )

#include <OneWire.h>

OneWire  ds(2);    // 1-wire on pin 2
byte     addr[8];  // Contains the eeprom unique ID

void setup(void)
{
  Serial.begin(9600);
  digitalWrite(2, HIGH);
}

void loop(void)
{
  byte i;
  byte actually_useful_data[16];

  SearchAddress(addr);

  ReadAllMem();    //print all mem content

  Serial.print("Pause \n");
  delay(5000);
}

void SearchAddress(byte* address) //Search for address and confirm it
{
  int i;
  if ( !ds.search(address))
  {
    Serial.print("No device found.\n");
    ds.reset_search();
    delay(250);
  }

  Serial.print("ADDR= ");
  for ( i = 0; i < 8; i++)
  {
    Serial.print(address[i], HEX);
    Serial.print(" ");
  }

  if ( OneWire::crc8( address, 7) != address[7])
  {
    Serial.print("CRC is not valid, address is corrupted\n");
    return;
  }

  if ( address[0] != 0x08)
  {
    Serial.print("Device is not a 1-wire Eeprom.\n");
    return;
  }
  Serial.println();
}

void ReadAllMem()
{
  int i;
  ds.reset();
  ds.select(addr);
  ds.write(0xF0, 1); // Read Memory
  ds.write(0x00, 1); // Read Offset (xx): 00 xxh
  ds.write(0x00, 1); // Read Offset (yy): yy 00h

  for ( i = 1; i <= 128; i++) //whole mem is 144
  {

    Serial.print(ds.read(), HEX);
    Serial.print(" ");
    if ((i % 16) == 0){
      Serial.println(); 
    }
  }
  Serial.println();
}
orgua commented 8 years ago

Did you solve your issues or is there still a problem?

fdenzer commented 8 years ago

Didn't inquire further, since we broke off our little side project.