WaveHC and Pin7 PIND register problems

Adafruit Ethernet, Motor, Proto, Wave, Datalogger, GPS Shields - etc!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
Albey
 
Posts: 2
Joined: Tue Feb 03, 2015 7:50 pm

WaveHC and Pin7 PIND register problems

Post by Albey »

I'm trying to implement Infrared commands to Wavehc not using the well known Shirriff library, but using the listenForIR() from ladyada which didn't use any interrupt but read PIND. That lib work originally reading digital pin 2 and I also use pin 3 PWM to transmit IR codes. Because only pins 6,7,8,9 are free when using wavehc, I change mycode to use pin 7 instead of pin 2 and pin 9 (pwm) for infrared transmission instead of pin 3. All work perfectly when the wavehc is not connected, but when I mount it, also without any wavehc code, the pin 7 reading was disturbed by the board, and I get values as I get them from infrared but obviously it's not true. What can I do?

Code: Select all

#define IRpin_PIN      PIND
#define IRpin         7

int listenForIR(void) {
  currentpulse = 0;
  
  
  while (1) {
    uint16_t highpulse, lowpulse;  // temporary storage timing
    highpulse = lowpulse = 0; // start out with no pulse length
  
//  while (digitalRead(IRpin)) { // this is too slow!
    while (IRpin_PIN & (1 << IRpin)) {
       // pin is still HIGH
       // count off another few microseconds
       highpulse++;
       delayMicroseconds(RESOLUTION);

       // If the pulse is too long, we 'timed out' - either nothing
       // was received or the code is finished, so print what
       // we've grabbed so far, and then reset
       
       // KGO: Added check for end of receive buffer
       if (((highpulse >= MAXPULSE) && (currentpulse != 0))|| currentpulse == NUMPULSES) {
         return currentpulse;
       }
    }
    // we didn't time out so lets stash the reading
    pulses[currentpulse][0] = highpulse;
  
    // same as above
    while (! (IRpin_PIN & _BV(IRpin))) {
       // pin is still LOW
       lowpulse++;
       delayMicroseconds(RESOLUTION);
        // KGO: Added check for end of receive buffer
        if (((lowpulse >= MAXPULSE)  && (currentpulse != 0))|| currentpulse == NUMPULSES) {
          return currentpulse;
       }
    }
    pulses[currentpulse][1] = lowpulse;

    // we read one high-low pulse successfully, continue!
    currentpulse++;
  }
}
Last edited by adafruit_support_rick on Wed Feb 04, 2015 1:17 pm, edited 1 time in total.
Reason: please use Code tags when posting code (</> button)

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: WaveHC and Pin7 PIND register problems

Post by adafruit_support_rick »

Wow. That's a good one. I can't think of anything that the Wave Shield would do to Port D Pin 7. Are you sure you don't have any stray solder blobs or other problems that could cause a short to D7?

User avatar
Albey
 
Posts: 2
Joined: Tue Feb 03, 2015 7:50 pm

Re: WaveHC and Pin7 PIND register problems

Post by Albey »

Yes I was sure... and I look two or three times... but when I've solded again the four pins connected to 6,7,8,9 just to be sure, all works!
Thank you Rick!

Alberto

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: WaveHC and Pin7 PIND register problems

Post by adafruit_support_rick »

Great!

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino Shields from Adafruit”