1

I am struggling with programming my DS2436 chip using an Arduino UNO. To be honest, I am trying to modify DS18B20 code (the one that is anywhere on the internet) to work with DS2436. It's just harder for me to understand how whole memory and adressing thing work, since DS2436 has those pages of memory blocks, unlike DS18B20, which has only 1. Also the language factor is stopping me, I am not a native speaker.

I keep getting wrong data/temperature/CRC. Can someone assist me, please? I need this thing to show me voltage/temperature and cycles.

#include <OneWire.h>
OneWire  ds(10); 

void setup(void) {
  Serial.begin(9600); 
}

void loop(void) {
  byte i; 
  byte addr[8];
  byte data[32];
  byte type_s;
  byte present = 0;
  float celsius, fahrenheit;

  if (!ds.search(addr)) {
    ds.reset_search();
    delay(1000);
    return;
  }

  Serial.print("ROM ="); 
  for( i = 0; i < 8; i++) {
    Serial.write(' ');
    Serial.print(addr[i], HEX);
  }
  Serial.print("\n");
  if (OneWire::crc8(addr, 7) != addr[7]) {
    Serial.println("CRC is not valid!");
    return;
    Serial.print("\n");
  }
  if (addr[0] != 0x1B) {
    Serial.print("Device is not a DS2436 family device!");
    Serial.print("\n");
  }
  {
    Serial.print("CRC= "); 
    Serial.print(OneWire::crc8(data, 8), HEX);
  }
  Serial.print("\n");
  ds.reset(); 
  ds.select(addr); 
  ds.write(0xD2, 1);
  delay(1000); 
  present = ds.reset(); 
  ds.select(addr); 
  ds.write(0xB2); 
  Serial.print("  Data = ");
  for (int i = 0; i < 13; i++) {             
    data[i] = ds.read();
    Serial.print(data[i], HEX);
    Serial.print(" ");
  }
  Serial.print(" CRC=");
  Serial.print(OneWire::crc8(data, 8), HEX);
  Serial.println();
  unsigned int raw = (data[1] << 8) | data[0];
  int sig = raw & 0x8000;   
  if (sig) {                               
    raw = (raw ^ 0xffff) + 1;               
  }
  celsius = (float)raw * 0.03125;
  Serial.print("Temperature = ");
  Serial.print(celsius);
  Serial.print(" Celsius ");
  Serial.print("\n");
  Serial.print("_______________________________________________");
  Serial.print("\n");
}

enter image description here

2

1 Answer 1

0

Yes necro, but having my own example of a DS2436 to try this out on, and having to write code for it with little else to go on, seems like the IC doesn't really know what to send you when reading the bus after sending the read register command.

As per the datasheet, 0xFF is data the IC sends when the bus master reaches the end of a page or an address that's reserved. Adding in ds.write(0x60); before performing the read cycles fixes most of this.

Haven't gotten into much past that, but it seems like there's also something not quite right going on with your arithmetic to turn your binary into temperature. Even with my fix getting something serviceable as output, I get 1024.00 Celsius.

1
  • Re “there's also something not quite right going on with your arithmetic to turn your binary into temperature”: It is indeed broken. Try this fix: int16_t raw = (uint16_t) data[1] << 8 | data[0]; float celsius = raw * (1.0/256); Oct 19 at 8:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.