Hi, I know @DrAzzy was going to look at this, but the bits arrived and I couldn't resist.
Note: you need a 0.2-2.2k pullup resistor - so pretty hefty (not like the ~10k you can get away with on the DS18B20).
var ow = new OneWire(B15);
var code = ow.search()[0];
function write(addr, data) {
while (data.length>0) {
var l = data.length;
if (l>8) l=8; // 32 works with DS2433, but need 8 for DS2431
ow.reset();
ow.select(code);
ow.write(0x0F); // write spad
ow.write(addr&0xFF);
ow.write(addr>>16);
for (var i=0;i<l;i++)
ow.write(data.charCodeAt(i));
ow.reset();
ow.select(code);
ow.write(0xAA); // read spad
var a=[ow.read(),ow.read(),ow.read()];
ow.reset();
ow.select(code);
ow.write(0x55); // copy spad to eeprom
ow.write(a[0]);
ow.write(a[1]);
ow.write(a[2],true/*pull up for write*/);
// TODO: maybe we should delay here?
// get ready for next iteration, if there is one
data=data.substr(l);
addr+=l;
}
}
function read(addr, cnt) {
ow.reset();
ow.select(code);
ow.write(0xF0); // read
ow.write(addr&0xFF);
ow.write(addr>>16);
var res = "";
while (cnt--) res += String.fromCharCode(ow.read());
return res;
}
write(0,"Hello World")
read(0,16)
// ="Hello World\x00\x00\x00\x00\x00"
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
Hi, I know @DrAzzy was going to look at this, but the bits arrived and I couldn't resist.
Note: you need a 0.2-2.2k pullup resistor - so pretty hefty (not like the ~10k you can get away with on the DS18B20).
I'll stick it in a module soon.