Go Down

Topic: AttachInterrupt won't work on Pin 26 (Read 1 time) previous topic - next topic

decrux

Dec 25, 2012, 12:53 am Last Edit: Dec 25, 2012, 12:54 am by decrux Reason: 1
Hello,
Pins 22,23,24 do recognize Interrupts. Pin 26 doesn't. Is this a bug?
Greetings
decrux

Code: [Select]
  pinMode(26, INPUT);
  digitalWrite(26, HIGH);
attachInterrupt(26, increment, FALLING);

decrux

Problem 2:
The following code isn't switching the LED on. Suggestions?

Code: [Select]

void setup() {
  pinMode(13, OUTPUT);
  pinMode(11, OUTPUT);
  digitalWrite(11, HIGH);
  digitalWrite(13, LOW); // LED off
  digitalWrite(13, digitalRead(11)); // LED on?
}

void loop() {

}

Graynomad

Have you researched what a digitalRead() of and output pin it supposed to return? There's a good chance it does not return the state of the output but I haven't checked.

_____
Rob
Rob Gray aka the GRAYnomad www.robgray.com

decrux

#3
Dec 25, 2012, 02:56 pm Last Edit: Dec 25, 2012, 03:25 pm by decrux Reason: 1
Arduino Reference only speaks of reading Input state, but digitalRead() is working on another pin quite well. With an atmega32 the "pin status register" was read but here I found another approach.
Code: [Select]

extern int digitalRead( uint32_t ulPin )
{
if ( g_APinDescription[ulPin].ulPinType == PIO_NOT_A_PIN )
   {
       return LOW ;
   }

if ( PIO_Get( g_APinDescription[ulPin].pPort, PIO_INPUT, g_APinDescription[ulPin].ulPin ) == 1 )
   {
       return HIGH ;
   }

return LOW ;
}

If instead of using digitalRead(13) I use
Code: [Select]
PIO_Get( g_APinDescription[13].pPort, PIO_OUTPUT_0, g_APinDescription[13].ulPin ) it works. Funny that digitalRead works on some pins(Output) and on others not. Could someone try to verify the attachInterrupt function for pin 26?

It has something to do with PIO_PDSR and PIO_ODSR but I still don't know why the PIO_PDSR doesn't return the state value of the pin, when configured as OUTPUT.

Have a look at PIO_GET() in pio.c:

Code: [Select]

extern uint32_t PIO_Get( Pio* pPio, const EPioType dwType, const uint32_t dwMask )
{
    uint32_t dwReg ;

    if ( (dwType == PIO_OUTPUT_0) || (dwType == PIO_OUTPUT_1) )
    {
        dwReg = pPio->PIO_ODSR ;
    }
    else
    {
        dwReg = pPio->PIO_PDSR ;
    }

    if ( (dwReg & dwMask) == 0 )
    {
        return 0 ;
    }
    else
    {
        return 1 ;
    }
}

stimmer

I don't know if using digitalWrite to set the pullup resistor works on the Due. Try using pinMode with INPUT_PULLUP instead.

Someone else posted something here before about digitalRead on an output pin not returning the current state the pin (unlike the Uno, which does) It isn't really a bug, just a difference between the way AVR and SAM works, but I think if it is possible then digitalRead should be modified just so it is consistent with the Uno.
Due VGA library - http://arduino.cc/forum/index.php/topic,150517.0.html

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy