Show Posts
Pages: [1]
1  Using Arduino / Networking, Protocols, and Devices / Re: I2C hangs on: August 09, 2011, 02:06:14 pm
I just received this in a direct message from Unaie:

Quote
Hi Garitron. Callocs are not mine, old twi.cpp asigned buffers dinamically. New twi.cpp asigns them statically, so there are not needed. But good point, in the old version they would need to be freed before calloc to avoid a memory leak. (perhaps this is the reason for the change in new twi version, any wire initialization in arduino would reallocate memory)

Regards
Unaie

That sure answers my question... Thanks Unaie...

73,
  Garitron
2  Using Arduino / Networking, Protocols, and Devices / Re: I2C hangs on: August 08, 2011, 02:51:59 pm
Kaor and all,

I am also having occasional hangs (1 or 2 per day) when using the Wire library routines.  I have used LEDs to chase the execution down to one (or more) of the wait loops in the twi.c module. I have substituted unaie's modified modules (twi.h and twi.c) that he made available in the <http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1283887406> thread, posting of <08.09.2010 at 11:34:27>.

His code implements a timeout counter in each of the (5) wait loops and calls twi_init() if a timeout occurs. I encountered a timeout this morning and the program recovered and continued.  So I will keep his modification in my project. 

However, in the modification he also changed the buffer allocation to use <calloc> calls in twi_init().  I don't understand why he did this. I think that the buffers will get re-requested every time there is a timeout with a call to twi_init() and leave unused (not free'ed) buffers, i.e. a memory leak.

I will forward this post to unaie and perhaps he can post here to explain the <calloc> calls.

73,
  Garitron

3  Development / Other Software Development / Introducing Maxim DS2482 1-wire master library (2) on: February 06, 2011, 09:31:45 pm
Sivu,

Since I can't post to the earlier thread (http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1242137666),
I've taken the liberty of creating a second follow-on thread.

Thank you for creating the DS2482 library and to Don T for his efforts to debug the wireSearch function. However, Don's mod didn't get it completely fixed.  I have a 1-wire network that includes devices with Family Codes 0xFF, 0x12, and 0x10.  Search finds only the 0x12 and 0x10 devices.  If I remove those devices, then search finds the 0xFF device.

After much head-scratching, I have determined that the following modifications will make search work properly.  (See Maxim Application Note 187.)

In DS2482.h:
106c106         (Reverse Don's mod)
<    int8_t searchLastDisrepancy;
---
>    uint8_t searchLastDisrepancy;

In DS2482.ccp:
233,234c233   (Reverse remainder of Don's mod)
<    // Initialize to negative value
<    searchLastDisrepancy = -1;
---
>    searchLastDisrepancy = 0;
255c254
<    for(i=0;i<64;i++)
---
>    for(i=1;i<65;i++)
257,258c256,257
<       int romByte = i/8;
<       int romBit = 1<<(i&7);
---
>       int romByte = (i-1)>>3;
>       int romBit = 1<<((i-1)&7);

Don's mod didn't succeed since the loop index "i" is used by searchLastDisrepancy AND last_zero.

Perhaps you'd like to add these modifications to your source at (https://github.com/paeaetech/paeae/tree/master/Libraries/ds2482/).

Could you also take that opportunity to add the modification from Mike Jackson at (http://arduino.cc/forum/index.php?topic=37647.0) and correct the spelling of "discrepancy".

Thanks!

73,
  Garitron
4  Forum 2005-2010 (read only) / Syntax & Programs / Re: Saving pointer to class instance in another class? on: November 14, 2010, 07:28:58 pm
That did it, AlphaBeta!  Errors are gone... now to make it work!

You guys are GOOD, and FAST too!  15 minutes, question to answer!

73,
  Gary
5  Forum 2005-2010 (read only) / Syntax & Programs / Re: Saving pointer to class instance in another class? on: November 14, 2010, 06:49:10 pm
Oh, and the "get()" function can't have any parameters because it needs to be given to the Time routines so Time can get sync occasionally and Time can't supply parameters.

73,
  Gary
6  Forum 2005-2010 (read only) / Syntax & Programs / Saving pointer to class instance in another class? on: November 14, 2010, 06:46:14 pm
OK, I'm stumped...  I've got a sketch that uses OneWire devices.  I'm making a library that will support a real-time clock chip (DS2417) on the OneWire net.  So the library class needs to know and remember the user's OneWire  instance so it can talk to the clock chip.  I've stripped the code to its essentials below:

Code:
// DS2417RTC.h - library for DS2417 RTC  -------------------------
#include <Time.h>
#include <OneWire.h>

class DS2417RTC {
  static OneWire* dsx;         // Private variable
  
  public:
    DS2417RTC(OneWire*);       // Constructor
    static time_t get();       // Member function
};


// Here's the DS2417RTC.ccp file-----------------------------------
#include <Time.h>
#include <OneWire.h>
#include "DS2417RTC.h"

DS2417RTC::DS2417RTC(OneWire* dsp) {
  dsx = dsp;          // Save pointer to main's OneWire instance
}

time_t DS2417RTC::get() {
  uint8_t rom[8] = {0x27, 0xAB, 0x5B, 0x22, 0, 0, 0, 0x6A}; // Clock chip addr
  
  dsx->select(rom);  // Represents several OneWire function calls
  return 123;
}

// Here's the Arduino sketch file (xxx.pde)------------------------
#include <Time.h>
#include "DS2417RTC.h"
#include <OneWire.h>

OneWire ds(10);       // One-Wire net on pin 10

DS2417RTC RTC(&ds);   // Use DS2417 Real-Time Clock

void setup() {
}

void loop() {
  time_t t = RTC.get();
}


// Here's the error output:
//
DS2417RTC.cpp.o: In function `DS2417RTC':
(file path removed) /DS2417RTC.cpp:7: undefined reference to `DS2417RTC::dsx'
(file path removed) /DS2417RTC.cpp:7: undefined reference to `DS2417RTC::dsx'

DS2417RTC.cpp.o: In function `DS2417RTC::get()':
(file path removed) /DS2417RTC.cpp:13: undefined reference to `DS2417RTC::dsx'
(file path removed) /DS2417RTC.cpp:13: undefined reference to `DS2417RTC::dsx'

What's he complaining about?

Thanks in advance for your attention!

73,
  Gary
7  Forum 2005-2010 (read only) / Syntax & Programs / Re: Metro class creator won't do constant arithmetic. on: March 03, 2010, 10:37:59 pm
PaulS.

That fixed it... Thanks!

73,
  Gary
8  Forum 2005-2010 (read only) / Syntax & Programs / Metro class creator won't do constant arithmetic. on: March 03, 2010, 04:18:03 pm
I'm having some difficulty being explicit when creating a Metro class. Here's a distillation of the problem:

Code:
#include "Metro.h"

// This works:
  //   Metro chgGrpMetro = Metro(60000, true);
  
// This does not work (.check never goes true):
Metro chgGrpMetro = Metro(60*1000, true);

void setup() {
    Serial.begin(9600);
    Serial.println("Starting test");
};

void loop(){    
  if ( chgGrpMetro.check() ) {
    Serial.println("check = true");
  }
}


Can you help?

73,
  Gary
9  Forum 2005-2010 (read only) / Interfacing / Re: 24LC256 overwrite and read all sketches on: November 07, 2010, 01:39:25 pm
Hello Volkemon...

I have implemented your overwrite sketch.  It was a good mechanism for learning how to work with the 24LC256.  You had a couple of problems:

1) Can't get "chipAdress" to compile using "byte", need "char"...
    Mine works fine with "byte", I don't know why... (uint8_t would
    probably be better.)

2) Your off-by-one problem:
    a) Change "int startAddress = 0" to "uint16_t startAddress = 0"
        (Signed integer changed to unsigned.)

    b) Change (3) tests to "if (startAddress > 0x7FFF) {"
        (address 0x7FFF didn't get written until next pass using -1,
         I think. This is probably the root of the problem.)

    c) Change (3) reset stmts to "startAddress = 0;"

    Anyhow, it works now...

Hope you sleep better tonight!

73,
  Gary (Garitron)
10  Forum 2005-2010 (read only) / Interfacing / Re: External power + USB safe? on: November 30, 2009, 08:19:12 pm
TchnclFl: I was not powering through the power jack, even 'tho that was my intent.  I forgot to connect the 12vdc.  So does the USB power go backwards through the on-board regulator to VIN?

73,
  Garitron
11  Forum 2005-2010 (read only) / Interfacing / Re: External power + USB safe? on: November 30, 2009, 07:59:39 pm
Slightly off-topic, but this thread is as close as I could find:

I've built a custom shield board for my Duemilanove. It has a 7805 regulator using the VIN pin for input.  My intent is to power both boards with 12vdc plugged into the power jack.

However, the other day I forgot to connect the 12vdc to the power jack, but the boards ran anyway! The USB 5vdc was running the Duemilanove and I think that some power was feeding backwards through the Duemilanove's on-board regulator (MC33269D) to the VIN pin.

There was 4.3vdc on the VIN pin and after going through my 7805 it was 3.0vdc.  It appears that was enough to run the PCA9540B on my shield board.  

Will power REALLY flow backwards through the on-board regulator, or should I look for some other explanation?

73,
  Garitron
Pages: [1]