Pages: [1]   Go Down
Author Topic: AttachInterrupt won't work on Pin 26  (Read 865 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 15
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello,
Pins 22,23,24 do recognize Interrupts. Pin 26 doesn't. Is this a bug?
Greetings
decrux

Code:
  pinMode(26, INPUT);
  digitalWrite(26, HIGH);
attachInterrupt(26, increment, FALLING);
« Last Edit: December 24, 2012, 06:54:50 pm by decrux » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 15
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

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

void loop() {

}
Logged

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 126
Posts: 8472
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Rob Gray aka the GRAYnomad www.robgray.com

Offline Offline
Newbie
*
Karma: 0
Posts: 15
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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:
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:
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 ;
    }
}
« Last Edit: December 25, 2012, 09:25:38 am by decrux » Logged

Offline Offline
God Member
*****
Karma: 32
Posts: 507
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged


Pages: [1]   Go Up
Jump to: