An arduino library to communicate using the Dallas one-wire protocol, where the Arduino takes the role of a slave.
Implementation of a DS2413 on Arduino UNO and ATTINY85
You can not select more than 25 topicsTopics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
// This is the pin that will be used for one-wire data (depending on your arduino model, you are limited to a few choices, because some pins don't have complete interrupt support)
// This sample implements a simple protocol : sending match ROM, then the ROM, then 0x01 will turn the arduino light on. Sending 0x02 will turn it off. In each case, the byte 0x42 is sent as acknowledgement.
constbyteCMD_TurnOn=0x01;
constbyteCMD_TurnOff=0x02;
// This function will be called each time the OneWire library has an event to notify (reset, error, byte received)
// You can do anything you want here, the OneWire library works entirely in background, using interrupts.
cli();//disable interrupts
// Be sure to not block interrupts for too long, OneWire timing is very tight for some operations. 1 or 2 microseconds (yes, microseconds, not milliseconds) can be too much depending on your master controller, but then it's equally unlikely that you block exactly at the moment where it matters.
// This can be mitigated by using error checking and retry in your high-level communication protocol. A good thing to do anyway.
// in this simple example we just reply with one byte to say we've processed the command
// a real application should have a CRC system to ensure messages are not corrupt, for both directions
// you can use the static OneWireSlave::crc8 method to add CRC checks in your communication protocol (it conforms to standard one-wire CRC checks, that is used to compute the ROM last byte for example)
OneWire.write(&acknowledge,1,NULL);
break;
default:
;// we could also react to reset and error notifications, but not in this sample