1-Wire Slave

jooray: I started with master library and changing it with the PIC code as an example.

Don't do that. You can find a ready to use well documented master library here... http://pjrc.com/teensy/td_libs_OneWire.html

I just started coding similar project, just for fun

You have a perverse sense of "fun"! ;)

Do you have any ideas for testing?

Work in very tiny increments. Create code that can reliably detect a Reset. Add code that reliably detects the Device Present pulse. Add code that reliably determines the end of the Reset. Et cetera.

(the goal is to send serial as slave to another arduino as a master). I can not seem to get the timing right though.

The slave timing is definitely tricky. I've identified three potential problems...

  1. Interrupt latency.

  2. Master variations.

  3. Loose protocol.

I played with some iButtons and this is my first Arduino project besides lighting LEDs. :)

An eclectic set.

Thanks for doing this!

Don't thank me yet! At the rate I'm going we all may expire before I finish.

This is not very Arduino friendly but I suspect that it works well... http://old.nabble.com/1wire-slave-codebase-%28AVR%29-td28214218.html https://github.com/smurfix/owslave

Did you take a look at this?

http://robocraft.ru/blog/arduino/302.html

Google will help you to translate.

I had not seen that. Thank you for the tip.

[quote author=Coding Badly link=topic=65706.msg869589#msg869589 date=1343062972]

I had not seen that. Thank you for the tip. [/quote]

Not for that i've seen that few days ago, i'am looking too, to get an emulation of an 1-Wire Slave, this looks like the most simple projekt, for other typs of devices the libary must expand in my opinion, bevor i've seen that i was thinking about an interrupt driven lib, in combination with an final state maschine but this would be to complex. But this modified lib looks nice maybe with some extra code for different typs of devices and "jump marks" it can be an solution for 1-Wire Slaves. So that you tell the lib what it is and only the conf or informations would be set in the Sketches.

B.R.

Markus

It’s about time to move some dust.

Moving from this Arduino и 1-Wire - эмуляция ведомого устройства с помощью библиотеки OneWireSlave / Arduino / RoboCraft. Роботы? Это просто! way there to this https://digistump.com/board/index.php/topic,887.0.html. Thanks to all that Guys what they did.

I was able to start this. Files in the Attachment.

DS18B20_Slave.ino → the Slave in Arduinostyle
OneWireSlave.cpp/.h → the library for it
(did not work on Due or Teensy 3)

DS18x20_Temperature_edited.ino → an little edited Version of Paul Stoffregen’s File from the last OneWirelib (2.2)

The Arduino pretend on with the DS18B20_Slave to be an DS18B20 with an temp of 155°C (clearly above the capabilities of the DS18B20 (125)) parasite powered. But under heavy duty.

What didn’t work is the DallasTemperature Library from Miles Burton there are some problems with reset_search and the reset at the end of some parts.

// reads the device's power requirements
bool DallasTemperature::readPowerSupply(uint8_t* deviceAddress)
{
  bool ret = false;
  _wire->reset();
  _wire->select(deviceAddress);
  _wire->write(READPOWERSUPPLY);
  if (_wire->read_bit() == 0) ret = true;
  _wire->reset();     --> this line is not good fore the cloned DS18B20 without it works
  return ret;
}

May someone can help drive this forward to getting an working and universal library. Perhaps an interrpt driven Initiaization Timing can bring success but I’m not an expert for that.

This is really experimental. Nothing is convenient on this.

Pictures below:

DS18B20_Slave.ino (1.11 KB)

OneWireSlave.h (1.88 KB)

OneWireSlave.cpp (18 KB)

DS18x20_Temperature_edited.ino (3.12 KB)

1st the Hardware
Black-Board an Vinciduino, Powered by an supply
Blue-One an Arduino Nano Powered by USB
And 3 real DS18B20 Powered from the Nano external.

2nd the Serial from the Nano
4 DS18B20
The last is the Arduino-Slave what you can see parasite Powered and burning@155°C

Onewire Slave.JPG

Surprise to my self.

Now an expedition into interrupts.

Quick an dirty with interruptsroutine for recognizing the Master Tx Reset Pulse…

But now the DallasTemperature Library from Miles Burton works too, for it on the other side, and recognize it as well.

DS18B20_Slave_Interrupt.ino (1.39 KB)

OneWireSlave.cpp (19.2 KB)

OneWireSlave.h (1.93 KB)

Some improvement with support for the 44h command and set the “power supply” from the outsite the library.

ds.attach44h(temper);

-----------------------------------------

void temper() {
  scratchpad[1] = scratchpad[1] + 1;
  ds.setScratchpad(scratchpad);
}

Sometimes the "Slave did something wrong think he didn’t get the Master reset.

ROM = 28 AD DA CE 0F 00 11 5B
  Chip = DS18B20
  Data = FF FF FF FF FF FF FF FF FF  CRC=C9
  Powersupply = Parasite Powered
  Temperature = -0.06 Celsius, 31.89 Fahrenheit

All FF so there is some miss.

New added:

OneWireSlave.cpp (19.4 KB)

OneWireSlave.h (2.06 KB)

DS18B20_Slave_Interrupt.ino (1.52 KB)

Now support for Teensy 3.0 and Arduino Due added.

For proper work with the T3 some changes must be done:

Add this on the void setup()

pinMode(12, INPUT);

And this on the void DS18B20() change this line

if (difference >= 380 && difference <= 800) {

to

if (difference >= 325 && difference <= 500) {

Thanks to Paul.

For the Due the Sample must be changed read this page about the interrupts.

http://arduino.cc/en/Reference/AttachInterrupt

Update:

Allowing to set resolution from Master or per command from slave side

OneWireSlave.cpp (19.1 KB)

OneWireSlave.h (5.17 KB)

DS18B20_Slave_Interrupt.ino (1.71 KB)

Some new Sketches to play with for the 1-Wire-Slave:

1nd Analogread for temper

2st Serial in for temper

DS18B20_Slave_Interrupt_T3_analogread.ino (2.47 KB)

DS18B20_Slave_Interrupt_T3_Serial.ino (3 KB)

I have been playing around with your libraries for programming an ATTiny85 at 8Mhz but find that it is failing to detect the 0x44 - Convert Temperature when sent. The 0xBE - Read Scratchpad works only from your sample master and not from my program with nearly identical code that works with DS18B20 temperature sensors.

My master program detects, converts DS18B20 temperature sensors without any problem.

Not having an oscilloscope I am at a loss as to where the problem may be. I am assuming a timing issue but am not sure where to look next.

Any ideas would be most welcome.

Ian

ilevans:
I have been playing around with your libraries for programming an ATTiny85 at 8Mhz but find that it is failing to detect the 0x44 - Convert Temperature when sent. The 0xBE - Read Scratchpad works only from your sample master and not from my program with nearly identical code that works with DS18B20 temperature sensors.

My master program detects, converts DS18B20 temperature sensors without any problem.

Not having an oscilloscope I am at a loss as to where the problem may be. I am assuming a timing issue but am not sure where to look next.

Any ideas would be most welcome.

Ian

I have there some newer version may that will help…, let me know

OneWireSlave.cpp (21.8 KB)

OneWireSlave.h (9.07 KB)

keywords.txt (869 Bytes)

Thank you. I will give them a try.

I am receiving the following errors when compiling

. . ./OneWireSlave.h:133:4: error: #error "Not an Interrupt Pin" . . ./OneWireSlave.h:134:4: error: #error "Use 2 or 3"

Any ideas?

Ian

ilevans: I am receiving the following errors when compiling

. . ./OneWireSlave.h:133:4: error: #error "Not an Interrupt Pin" . . ./OneWireSlave.h:134:4: error: #error "Use 2 or 3"

Any ideas?

Ian

Oh I know, the ATTiny85 is not part in the lib can you give me the pins in the IDE where the ATTiny85 has interrupts so I can adopt it for somethink like this.

#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) //Arduino Mega
  #if dsslavepin == 2
  #define dsslaveassignedint 0
  #elif dsslavepin == 3
  #define dsslaveassignedint 1
  #elif dsslavepin == 18
  #define dsslaveassignedint 5
  #elif dsslavepin == 19
  #define dsslaveassignedint 4
  #elif dsslavepin == 20
  #define dsslaveassignedint 3
  #elif dsslavepin == 21
  #define dsslaveassignedint 2
  #else
  #error "Not an Interrupt Pin"
  #error "Use 2, 3, 18, 19, 20 or 21"
  #define dsslaveassignedint -1
  #endif

so your uC can be supported.

Any ideas?

Use pin 2 or pin 3.

Hi Again

Interrupts are available on pins 0, 1, 2, 3, 4 and 5.
The micro-controller details and datasheet are available at the following link http://www.atmel.com/devices/ATTINY85.aspx.

I have attached the pins_arduino.h for the ATTiny

Thank you for your assistance.

Ian

pins_arduino.h (2.69 KB)

I added the following to OneWireSlave.h and removed a reference to "Serial" in OneWireSlave.cpp that was not commented out.

#elif defined(__AVR__)  //ATTiny
  #if dsslavepin == 0
  #define dsslaveassignedint 0
  #elif dsslavepin == 1
  #define dsslaveassignedint 1
  #elif dsslavepin == 2
  #define dsslaveassignedint 2
  #elif dsslavepin == 3
  #define dsslaveassignedint 3
  #elif dsslavepin == 4
  #define dsslaveassignedint 5
  #elif dsslavepin == 5
  #else
  #error "Not an Interrupt Pin"
  #error "Use 0, 1, 2, 3, 4 or 5"
  #define dsslaveassignedint -1
  #endif

The 0x44 is working. The 0xBE is not. After a short while running it no longer is detected by the master does not detect the 0x44.

My program that uses the library does not use any interrupts. Another chip does all the work and communicates using an interruptable shiftIn style communications to pass data to the OWSlave chip. An LED on the second chip informs me that the 0x44 was received and the userdefined function executed. Only 0xFFFF's are reported as being read from the scratchpad.

Ian

More testing today and the library is working as expected. Yeah!!

I still have a problem that it stops responding after awhile, That is a strange one but I have a starting point with working communications.

thanks

ilevans: More testing today and the library is working as expected. Yeah!!

I still have a problem that it stops responding after awhile, That is a strange one but I have a starting point with working communications.

thanks

How often did you poll your uC to get the informations? The Problem is if the uC is too often called he would get out of sync and can't responce anymore, at the moment I have no idea for it. How fast is the ATTiny?