Code:
/********************
Basic1WireSlave.ino
Version 0.0.1
Last Modified 12/20/2013
By Jim Mayhugh
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
This software uses multiple libraries that are subject to additional
licenses as defined by the author of that software. It is the user's
and developer's responsibility to determine and adhere to any additional
requirements that may arise.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*********************/
#define dsslavepin 2
#include <OneWireSlave.h>
#include <MAX31855.h>
#include <t3mac.h>
// {Family , <---, ----, ----, ID--, ----, --->, CRC}
uint8_t rom[8] = {0xAA, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00};
// {TLSB, TMSB, THRH, TLRL, Conf, 0xFF, Rese, 0x10, CRC}
uint8_t scratchpad[9] = {0x00, 0x00, 0x4B, 0x46, 0x7F, 0xFF, 0x00, 0x10, 0x00};
// {TLSB, TMSB}
uint8_t temperature[2] = {0x7F, 0x09};
OneWireSlave ds(dsslavepin);
const int mxDO = 3;
const int mxCLK = 5;
const int mxCS = 4;
// Initialize the Thermocouple
MAX31855 eMX(mxCLK, mxCS, mxDO);
//Blinking
const int ledPin = 13;
int ledState = LOW; // ledState used to set the LED
//long previousMillis = 0; // will store last time LED was updated
elapsedMillis interval;
uint32_t interval_cnt = 250;
//long interval = 250; // interval at which to blink (milliseconds)
uint8_t setDebug = 0x0; // set to 0 to disable serial debug
void setup() {
if(setDebug)
{
delay(5000);
Serial.begin(115200);
delay(3000);
Serial.println(F("Serial Debug started at 115200 baud"));
}
read_mac();
memcpy( (uint8_t *) &rom[1], (uint8_t *) &mac, 6 );
rom[7]=ds.crc8(rom, rom[7]);
attachInterrupt(dsslaveassignedint, slave, CHANGE);
// Serial.begin(115200);
// while (!Serial) {
// ; // wait for serial port to connect. Needed for Leonardo only
// }
pinMode(ledPin, OUTPUT);
ds.init(rom);
if(setDebug)
{
Serial.print(F("MAC Address is "));
print_mac();
Serial.println();
}
ds.setScratchpad(scratchpad);
ds.setPower(EXTERNAL);
// ds.setResolution(9);
// value = -55;
ds.attach44h(temper);
}
void slave() {
ds.MasterResetPulseDetection();
}
void loop() {
blinking();
}
void temper() {
int16_t degree = eMX.readCelsius();
temperature[0] = degree & 0xff;
temperature[1] = (degree & 0xff00) >> 8;
ds.setTemperature(temperature);
}
void blinking() {
if(interval >= interval_cnt) {
ledState = !ledState;
digitalWrite(ledPin, ledState);
interval = 0;
if(setDebug)
{
ds.showID();
}
}
}
And the two libraries: