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");
}