1-Wire Slave

I am targetting overdrive mode speeds.

pwillard:
Prefer tiny45, mega48, mega88, tiny26, tiny2313 in order of precedence (tiny45 being most preferred)

Clock speed?

Crystal or oscillator?

robtillaart:
Would be nice to make counters for RoundsPerMinute counters,

you config pulses per rotation PPR in a register and you have

PPR 16 bit?
ROTATIONS register 32 bit
POSITION register 16 bit (counter from 0..PPR)

A tachometer / encoder device?

MGeo:
I am targetting overdrive mode speeds.

Bad news. Overdrive will be later. The response to a master-read has to be within 1.0 microseconds. That's about 16 machine instructions (a small overrun would probably be OK). I suspect it will work but I want to pin down the other "high risk" implementation details before tackling the complexity of an assembly language interrupt service routine.

OK thanks.

This got me wondering how Arduino OneWire lib based master could be prepared for a 1 microsecond slave response to master-read without any hardware assist. It appears that OneWire Master lib OneWire::read_bit() code has a 3 microsecond delay for driving pin low, followed by a 9 microsecond delay at float before reading pin value. So maybe Arduino OneWire Master lib allows more response time than the minimum listed in Dallas spec, and 1 uS is taking excess margin?

Arduino OneWire Master Lib Source --> OneWire Arduino Library, connecting 1-wire devices (DS18S20, etc) to Teensy

Anyway, thanks for on-going consideration.

George

MGeo:
I am targetting overdrive mode speeds.

Do you have an Overdrive master?

This got me wondering how Arduino OneWire lib based master could be prepared for a 1 microsecond slave response to master-read without any hardware assist.

It should work fairly well on the Master. Interrupts have to be disabled in advance. But 1 microsecond is 16 simple machine instructions (worst case 8 machine instructions) which I believe is enough to pulse the line low and then listen for the slave's response.

It appears that OneWire Master lib OneWire::read_bit() code has a 3 microsecond delay for driving pin low, followed by a 9 microsecond delay at float before reading pin value.

The timing in the OneWire library seems a bit odd to me. It's definitely a different than the timing Maxim documents. At first I thought the times were tweaked to compensate for the code before and after but that does not seem to be the case.

So maybe Arduino OneWire Master lib allows more response time than the minimum listed in Dallas spec, and 1 uS is taking excess margin?

I don't follow.

Arduino OneWire Master Lib Source --> OneWire Arduino Library, connecting 1-wire devices (DS18S20, etc) to Teensy

That's the Master I've been working against.

Anyway, thanks for on-going consideration.

You are welcome. But don't hold your breath. The day job will not stop interfering!

Quote from: robtillaart on July 16, 2011, 03:38:44 PM
Would be nice to make counters for RoundsPerMinute counters,

you config pulses per rotation PPR in a register and you have

PPR 16 bit?
ROTATIONS register 32 bit
POSITION register 16 bit (counter from 0..PPR)

A tachometer / encoder device?

Yep, it is a recurring problem on the forum and developing a "smart encoder sensor" could be very interesting. The 1-wire slave Arduino connects the HW encoder to an IRQ line, the software on the 1-wire slave is configurable for the HW encoder details, like

  • control register: start, stop, reset
  • pulses per rotations (PPR)
  • set IRQ edge (RISING/FALLING/CHANGE)
  • rotations done since reset.
  • position within current rotation.
  • current direction of rotation [if supported in HW]
  • angular velocity [include array with last 10 pulse timestamps]

I just started coding similar project, just for fun (the goal is to send serial as slave to another arduino as a master). I can not seem to get the timing right though.

Do you have any ideas for testing?

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

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

Thanks for doing this!

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"! :wink:

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. :slight_smile:

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-(AVR)-td28214218.html

Did you take a look at this?

Google will help you to translate.

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

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 – 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