Hello,
Pins 22,23,24 do recognize Interrupts. Pin 26 doesn't. Is this a bug?
Greetings
decrux
pinMode(26, INPUT);
digitalWrite(26, HIGH);
attachInterrupt(26, increment, FALLING);
Hello,
Pins 22,23,24 do recognize Interrupts. Pin 26 doesn't. Is this a bug?
Greetings
decrux
pinMode(26, INPUT);
digitalWrite(26, HIGH);
attachInterrupt(26, increment, FALLING);
Problem 2:
The following code isn't switching the LED on. Suggestions?
void setup() {
pinMode(13, OUTPUT);
pinMode(11, OUTPUT);
digitalWrite(11, HIGH);
digitalWrite(13, LOW); // LED off
digitalWrite(13, digitalRead(11)); // LED on?
}
void loop() {
}
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
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.
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 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:
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 ;
}
}
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.