Show Posts
Pages: [1]
1  Products / Arduino Due / Re: OneWire in Due on: February 13, 2013, 09:03:07 am

So the problem must be somewhere behind the micros the function delayMicroseconds is realy open so the problem musst be somewhere there


Right, micros() must have a problem with noInterrupts().

I tried to change delayMicroseconds() to make it independent from micros(). Here is the code:
Code:
#define CYCLES_PER_USEC 84 // Arduino Due has 84 MHz clock
#define CYCLES_PER_LOOP 6  // one iteration of the loop takes 6 cycles
#define OVERHEAD_CONST 18  // could someone with an osci please verify this constant?
void delayMicroseconds( uint32_t us )
{
  if(us==1) return;
  int j;
  //one iteration of this loop takes 6 cycles on Arduino Due compiled with IDE 1.5.2
  for(j=0;j<us*(CYCLES_PER_USEC/CYCLES_PER_LOOP)-OVERHEAD_CONST;j++)
  {
    asm volatile("mov r0, r0"); // just NOP
    asm volatile("mov r0, r0"); 
  }
}

This change worked with the original version of OneWire (OneWire_preview22_17jan13.zip)

This patch is not pretty but it proves that the problem is in the micros().

Tomorrow I'll try to understand, why micros() has a problem with noIterrupts().
2  Products / Arduino Due / Re: OneWire in Due on: February 13, 2013, 04:13:30 am
Interrupts are disabled for a very good reason.  There's absolutely no way OneWire will return to the buggy pre-2.0 days where interrupts could lengthen the timing and cause random communication errors.
Ok, I understand that (I do know what are interrupts for and why they are disabled in time critical sections). I do not understand why delayMicroseconds acts differently depending on interrupts being disabled or enabled. Declaration of delayMicrosections for SAM is quite simple (from wiring.c):
Code:
void delayMicroseconds( uint32_t us )
{
    uint32_t start = micros();
    while ((micros() - start) < us)
        ;
}
It did not change since 1.5.1r2.

Do you have an idea, what the solution could be?

Leo

PS if I can contribute in any way, let me know.
3  Products / Arduino Due / Re: OneWire in Due on: February 12, 2013, 09:26:52 am
Hi Paul,

I just finished diff-and-try session with the library version OneWire_preview22_17jan13.zip and the version from this thread (with changes by alvesjc and mantoui).
The critical point seems to be the write_bit() function and the interrupt handling combined with delayMicroseconds() calls in this function (both have been mentioned in this thread already).
As soon as I excluded delayMicroseconds calls from noInterrupts()/interrupts() sections in the write_bit() function, the library worked.

Here is the changed version of write_bit():
Code:
void OneWire::write_bit(uint8_t v)
{
IO_REG_TYPE mask=bitmask;
volatile IO_REG_TYPE *reg IO_REG_ASM = baseReg;

if (v & 1) {
noInterrupts();
DIRECT_WRITE_LOW(reg, mask);
DIRECT_MODE_OUTPUT(reg, mask); // drive output low
interrupts();
delayMicroseconds(10);
noInterrupts();
DIRECT_WRITE_HIGH(reg, mask); // drive output high
interrupts();
delayMicroseconds(55);
} else {
noInterrupts();
DIRECT_WRITE_LOW(reg, mask);
DIRECT_MODE_OUTPUT(reg, mask); // drive output low
interrupts();
delayMicroseconds(65);
noInterrupts();
DIRECT_WRITE_HIGH(reg, mask); // drive output high
interrupts();
delayMicroseconds(5);
}
}

It's the only change I made on the library.

I'm running a test with all the sensors installed in my house heating control, I have 9 DS1820 for temperature sensing and some DS2408 and DS2413 for relay switching.
All of them are working (so far) as they usually do with my old Arduino Mega. I'll post test results tomorrow.

Leo
4  Products / Arduino Due / Re: OneWire in Due on: February 11, 2013, 07:50:50 am
Hi all,

I tried the the OneWire 2.2 with IDE 1.5.1r2. Two of four DS1820 sensors give me no readings ("No more addresses" in the DS18x20 Example sketch), the other two produce no valid temperature readings:

ROM = 10 D1 A2 54 2 8 0 57
  Chip = DS18S20
  Data = 1 FF FF FF FF FF FF FF FF FF  CRC=C9
  Temperature = -0.50 Celsius, 31.10 Fahrenheit

It is probably the delayMicroseconds problem Paul mentioned in his post.

With the new IDE 1.5.2 (http://arduino.cc/forum/index.php?topic=147531.0) all four sensors are unable to be read ("No more addresses").
It's kind of weird...

Have someone else tried 1.5.2 with OneWire yet?

Leo

Update: the OneWire Library with changes by alvesjc and mantoui works with both 1.5.1r2 and 1.5.2. I'm able to read all 4 sensors.
Pages: [1]