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 ;
}
}