Browse Source

Upload files to ''

master
IanF 5 years ago
parent
commit
3359d0ef47
  1. 33
      FakeD2413.ino

33
FakeD2413.ino

@ -1,3 +1,18 @@
/* Ian Fleet 2018
All files, software, schematics and designs are provided as-is with no warranty.
All files, software, schematics and designs are for experimental/hobby use.
Under no circumstances should any part be used for critical systems where safety,
life or property depends upon it. You are responsible for all use.
You are free to use, modify, derive or otherwise extend for your own purposes
*/
// This example emulates a DS2413 device on an Arduino UNO or ATTINY85
// note : physical DS2413 devices found in 2018 are often clones with
// a device code different to the Maxim datasheet
#include "Arduino.h" #include "Arduino.h"
#include "OneWireSlave.h" #include "OneWireSlave.h"
#include "comptime.h" #include "comptime.h"
@ -13,7 +28,7 @@ Pin oneWireData(2); // PB2 only attiny85 pin with rising/falling interrupts
// This sample emulates a DS2413 device , so we start by defining the available commands // This sample emulates a DS2413 device , so we start by defining the available commands
const byte DS2413_FAMILY_ID = 0x3A; // Maxim DS2413 device code const byte DS2413_FAMILY_ID = 0x3A; // Maxim DS2413 device code
const byte CLONE_FAMILY_ID = 0x85; // Chinese clone device code const byte CLONE_FAMILY_ID = 0x85; // clone device code
const byte DS2413_ACCESS_READ = 0xF5; const byte DS2413_ACCESS_READ = 0xF5;
const byte DS2413_ACCESS_WRITE = 0x5A; const byte DS2413_ACCESS_WRITE = 0x5A;
const byte DS2413_ACK_SUCCESS = 0xAA; const byte DS2413_ACK_SUCCESS = 0xAA;
@ -90,13 +105,13 @@ static uint8_t getstatus() {
////////////////////////////////////////// //////////////////////////////////////////
static void port(int led, bool stat) { static void port(int PIO, bool stat) {
if (stat) { if (stat) {
digitalWrite(led, HIGH); digitalWrite(PIO, HIGH);
pinMode(led, INPUT); pinMode(PIO, INPUT);
} else { } else {
pinMode(led, OUTPUT); pinMode(PIO, OUTPUT);
digitalWrite(led, LOW); digitalWrite(PIO, LOW);
} }
} }
@ -107,7 +122,7 @@ static void set(uint8_t val) {
latch = val; latch = val;
port(PIOA, latch & 1); port(PIOA, latch & 1);
port(PIOB, latch & 2); port(PIOB, latch & 2);
//eeprom_write_byte((uint8_t*)10, (unsigned char)latch); //TODO copy latch to EEPROM
} }
////////////////////////////////////////// //////////////////////////////////////////
@ -124,8 +139,6 @@ void owReceive(OneWireSlave::ReceiveEvent evt, byte data)
{ {
case DS2413_ACCESS_WRITE: case DS2413_ACCESS_WRITE:
state = DS_WaitingStatus1; state = DS_WaitingStatus1;
//OWSlave.beginWriteBit(0, true); // send zeros as long as the conversion is not finished
break; break;
case DS2413_ACCESS_READ: case DS2413_ACCESS_READ:
@ -153,7 +166,7 @@ void owReceive(OneWireSlave::ReceiveEvent evt, byte data)
set(statusbyte1); set(statusbyte1);
response[0] = DS2413_ACK_SUCCESS; response[0] = DS2413_ACK_SUCCESS;
} else { } else {
response[0] = 0x11; // mark error response[0] = 0x11; // mark error - real DS2413 does not do this
} }
response[1] = getstatus(); response[1] = getstatus();
OWSlave.beginWrite((const byte*)response, 2, 0); OWSlave.beginWrite((const byte*)response, 2, 0);

Loading…
Cancel
Save