Show Posts
Pages: 1 ... 4 5 [6]
76  Using Arduino / Programming Questions / Using cli() and sei() in a library on: September 02, 2011, 04:36:40 pm
Hi,
I have some library code in which I need to disable interrupts for a short moment.  When I try to use cli() / sei(), I get:

Code:
/Users/schwager/Documents/Arduino/libraries/AdaEncoder/AdaEncoder.cpp:290: error: 'cli' was not declared in this scope
/Users/schwager/Documents/Arduino/libraries/AdaEncoder/AdaEncoder.cpp:295: error: 'sei' was not declared in this scope

I find that I cannot include interrupt.h in my library .cpp file, either (this would be the interrupt.h from AVR library, which on Mac is in /Applications/Arduino.app/Contents/Resources/Java/hardware/tools/avr/etc/options/gcc-version/include/avr/interrupt.h).

Can anyone explain why cli() / sei() are not able to be used in my library?  Is there a way I can include an AVR .h file, or anything I can do that would be more elegant that, say, copying the macros from the interrupt.h file?

Thanks.
77  Using Arduino / Programming Questions / Re: Need to call an uninstantiated method from object method on: August 09, 2011, 07:44:40 am
Thanks, that helps.  But now I need to pass "this" as an argument to my function.

The function is specified in the PinChangeInt.h like this:
Code:
typedef void (*PCIntvoidFuncPtr)(void);
So I have tried to do this:
Code:
typedef void (*PCIntvoidFuncPtr)(void *);
So that I can do this in my Class:
Code:
PCintPort::attachInterrupt(pinA, interruptWrapper((void *) this), CHANGE);
but I get this error:
Code:
/Users/schwager/Documents/Arduino/libraries/AdaEncoder/AdaEncoder.cpp: In member function 'void AdaEncoder::attachInterrupt(int, int)':
/Users/schwager/Documents/Arduino/libraries/AdaEncoder/AdaEncoder.cpp:68: error: invalid use of void expression

if I do:
Code:
PCintPort::attachInterrupt(pinA, &interruptWrapper((void *) this), CHANGE);
I get this:
Code:
/Users/schwager/Documents/Arduino/libraries/AdaEncoder/AdaEncoder.cpp: In member function 'void AdaEncoder::attachInterrupt(int, int)':
/Users/schwager/Documents/Arduino/libraries/AdaEncoder/AdaEncoder.cpp:68: error: lvalue required as unary '&' operand

I can't figure out how to pass this through my static wrapper so as to open up the world of possibilities to me!  I need it so that I know which object the interrupt applies to.

Thanks again.
78  Using Arduino / Programming Questions / Need to call an uninstantiated method from object method on: August 09, 2011, 12:04:32 am
Hi,
I am using the PinChangeInt library to set up a number of interrupts for a (relatively) arbitrary number of rotary encoders on my Arduino Uno.

I am creating my own Encoder library, which relies on the PinChangeInt library.

I have a call in my Encoder library that looks like this:
Code:
void AdaEncoder::attachInterrupt(int pinA, int pinB) {
    PCintPort::attachInterrupt(pinA, encoderInterrupt, CHANGE);
}

Note the AdaEncoder::attachInterrupt() method, above, is not static.  But the PCintPort::attachInterrupt() method is.  I have a stub encoderInterrupt() method:

Code:
void encoderInterrupt() {}

The error I get is this:
Code:
/Users/schwager/Documents/Arduino/libraries/AdaEncoder/AdaEncoder.cpp:65: error: no matching function for call to 'PCintPort::attachInterrupt(int&, <unresolved overloaded function type>, int)'
/Users/schwager/Documents/Arduino/libraries/AdaEncoder/../PinChangeInt/PinChangeInt.h:87: note: candidates are: static void PCintPort::attachInterrupt(uint8_t, void (*)(), int)

I think what I have to do is make the
Code:
encoderInterrupt()
method static, but I'd like to avoid that.  Is there any way I can do so?  Or do I need to make encoderInterrupt() static, then solve my problem by utilizing static pointers or arrays?

Thanks.
79  Using Arduino / Project Guidance / Convert Arduino pins to AVR PORTs on: August 06, 2011, 03:49:47 pm
Hi,
I am trying to write an interrupt that uses bitSet(), bitClear(), bitRead(), etc., to manipulate the ports for speed, rather than digitalRead() and digitalWrite().  Why do I need that speed?  I don't, actually.  But I want to do it because I want to learn more about the AVR, I want to get my chops up, and because it's there (tm).

But bitSet() has two arguments: The PORT, and the pin in the PORT.  However, I would like my library that includes this interrupt to take the Arduino pin as its argument; I don't want the programmer to have to figure the PORT and pin.

Can anyone explain to me why this works:
Code:
uint8_t sPort = digitalPinToPort(13);
bitSet(sPort, 5);

But this does not?
Code:
bitSet(digitalPinToPort(13), 5);
...This one says, "error: lvalue required as left operand of assignment".

Thanks.

80  Using Arduino / Networking, Protocols, and Devices / Re: DS3231.h --- Library for DS3231 (or DS3232) real-time clock on: May 29, 2011, 02:19:33 pm
Thanks, Eric.  This is cool, I'll be needing that chip in the future and I am glad to have your work!
 smiley-grin
81  Using Arduino / Networking, Protocols, and Devices / Re: I2C trouble with the MPR084 on: May 18, 2011, 08:54:51 pm
Well, here it is, a couple of months later and a few Wiki pages.  Finally, I got my MPR084 to squawk!  I just got it working an hour ago, and now on my second celebratory beer I am posting my results.

One thing I determined, I wasn't going to get this to work properly without a deep understanding of the whole catastrophe.  I'm not there yet, but I'm on my way.  I've created two Wiki pages, one to log my deep dive into the whole thing:  http://arduino.cc/playground/Code/ATMELTWI  and the other because I found the Wire library documentation lacking, so I expanded upon it:  http://arduino.cc/playground/Main/WireLibraryDetailedReference

I hope those are found useful one day by someone.  If I was able to see at all, it was only by standing on the shoulders of giants.  I am very grateful to all who have created this interesting platform.

Without further ado, here is the code that got the MPR084 to talk to me:

#include <Wire.h>
// For reference. These are the ANALOG pins:
const int i2cSCLPin =  5; // the number of the I2C interface, SCL pin
const int i2cSDAPin = 4;  // SDA pin

#define MPR084_ADDR 0x5C  // assumes the MPR084 AD0 pin is low
#define regINFO 0x14      // Sensor Information Register

char c;
void setup() {
  delay (1000);
  Serial.begin(19200); // For reporting
  Serial.print("MPR084 test.\n");
  Wire.begin();
}

void loop() {
  Wire.beginTransmission(MPR084_ADDR);
  Wire.send(regINFO); // This would be my command byte
  Wire.endTransmission();
  Wire.requestFrom(MPR084_ADDR, 32); // Not sure how much data there is, let's try this.
  Wire.endTransmission();
  while (Wire.available()) {
    c = Wire.receive();
    if (c != 0) {
      Serial.print(c);
    }
  }
  Serial.print('\n');
  delay(1000);
}


And here is an example of my glorious output:

VER:1_0_0Freescale,PN:MPR084,QUAL:EXTERNAL,

And that's it...!
- GreyGnome
82  Using Arduino / Networking, Protocols, and Devices / Detailed Wire Library Reference for I2C Communication on: May 04, 2011, 05:18:25 pm
Hello,
I have been trying to use the Wire library and have found the documentation lacking.  So I am putting up a detailed reference here:

http://arduino.cc/playground/Main/WireLibraryDetailedReference

It is a work in progress.  Release early and often, as they say.  Let me know if you see any issues, problems, or joys.
-GreyGnome
83  Using Arduino / Networking, Protocols, and Devices / Re: I2C trouble with the MPR084 on: March 08, 2011, 11:59:35 pm
Another thing to keep in mind, because it's a Freescale device, is that it may require the use of a repeated start, instead of a stop bit, after sending the command....

This is true!  Page 5 of the Datasheet shows the repeated start!  Oh boy, now I have a bit of work to do... thanks for the information!
84  Using Arduino / Networking, Protocols, and Devices / Re: I2C trouble with the MPR084 on: March 08, 2011, 11:50:47 pm
Can you post the code you are using?  Make sure the address you are using matches the address of the IC with address line.  Can you post a schematic also so we can see if you have it wired up correctly?  

Here is a picture of my schematic.
http://flic.kr/p/9oYkDp

As I'm a working/family man, I have yet to check some of the other suggestions in these replies. I have yet to procure a USB<->Serial cable to read the output of my Arduino.

Thanks, I appreciate the attention to this problem.  I will certainly post my code when I get this figured out.
85  Using Arduino / Networking, Protocols, and Devices / Re: I2C trouble with the MPR084 on: March 06, 2011, 11:25:37 pm
I notice that the Wire.requestFrom() function actually requires the address as one of its arguments, but I don't think I want to do that again because it's not part of the data flow as specified by the MPR084. 

Look at page 8 of their spec. The address is part of reading, that's normal for I2C. You send the slave address with the read bit set, then the requestFrom clocks out the data bytes, as required.

You're right, but the question is:  How does it work with Arduino's Wire library?  That's what I don't know.  The example that I have shows the sequence as:  Slave Address, Command, Slave Address, Data (see http://www2.neufeld.newton.ks.us/images/electronics/2008/05/26/PCA9535-figure-8.png).  And that's what the receive code that I have found does.  But I don't want to do that, p.8 of the data sheet says that reading the MPR084 proceeds like this, in a nutshell:  Slave Address, Command, Data.

...In your example at www.gammon.com.au, say under "Request Response" about 3/4 through the page, I see that you do your sendCommand() this way:
Code:
Wire.beginTransmission (SLAVE_ADDRESS);
  Wire.send (cmd);
  Wire.endTransmission ();
 
  Wire.requestFrom (SLAVE_ADDRESS, responseSize); 

...my interpretation is that the beginTransmission / send / endTransmission will actually send the Slave Address and the Command onto the wire.  Now the MPR084 will send data.  But the requestFrom requires the Slave Address, which would also fit into the scheme shown at http://www2.neufeld.newton.ks.us/images/electronics/2008/05/26/PCA9535-figure-8.png - It appears to me that the Slave Address will then be sent out onto the wire. But I don't want to send it again, because the MPR084 should be sending at this point, so what would I do?  How to just receive the data at this point, without addressing further?

Well I have been out all day today and I have to go to bed so I will send the schematic and my code asap.  Thanks for your attention.
86  Using Arduino / Networking, Protocols, and Devices / Re: I2C trouble with the MPR084 on: March 06, 2011, 08:16:38 am
Thanks, Nick!  I'll look into it.  It sounds like exactly what I need!
- the Gnome
87  Using Arduino / Networking, Protocols, and Devices / I2C trouble with the MPR084 on: March 06, 2011, 12:57:06 am
Hello,
I'm trying to talk to the MPR084 using my Arduino Duemilanove.  I've got the level shifting figured out (I believe), but I'm not getting any response from the MPR084.  I have tried 2 of the chips with the same results.

Part of my problem is that I don't really understand exactly what the TWI subroutines do.  That is, where is the 1:1 correspondence between the TWI commands and the i2c communication?  When does the data start flowing during a write?  How about during a read?  The abstraction (Wire library) of the physical underlying process (i2c data stream) is not well documented, and I am having trouble gluing them together.

For example, one of the first Google hits for examples is http://www.neufeld.newton.ks.us/electronics/?p=241.  When reading i2c data, he recommends doing
Code:
  //  Send input register address
  Wire.beginTransmission(address); Wire.send(REGISTER_INPUT); Wire.endTransmission();
  //  Connect to device and request two bytes
  Wire.beginTransmission(address); Wire.requestFrom(address, 2); // 2 bytes.
  if (Wire.available()) { data = Wire.receive(); } ; Wire.endTransmission();

...Because the documentation for his device shows that in order to read his chip, it requires:  Slave Address, then Command Byte, then Slave Address again, then the Arduino receives the data bytes as specified.

But for the MPR084, to read it you do:  Slave Address, then Command Byte, then receive the n data bytes.

I notice that the Wire.requestFrom() function actually requires the address as one of its arguments, but I don't think I want to do that again because it's not part of the data flow as specified by the MPR084.  What I think I need to do is something roughly like:
Code:
beginTransmission(address); endTransmission(address); //without sending any data...
receiveFrom(REGISTER_INPUT, 1); // to receive 1 byte from the register I'm interested in
store=receive();

...but I've tried it and it didn't work.  Any suggestions would be appreciated.  Thanks for any help.
-Mike Schwager
Pages: 1 ... 4 5 [6]