1

i am new to Atmel, so maybe the question is quite simple.

I have the following situation: I have an ATMega2560 and want to get Interrupts on the Pins PK0-PK7. I am interested in the PIN Change from Low to HIGH. (I have connected one photocell to every PIN) I have read that the interrupt for PCINT[0-2] are fired everytime (pin high and pin low) so i defined an array to ignore the PIN DOWN Interrupt.

So i have the following code:

Note: I do not understand, why i need to set DDRC as input and not DDRK ?

#define HIGH 1
#define LOW 0

volatile uint8_t portbhistory = 0xFF;
uint8_t pinState[8];
void initSystem()
{
    int i;
    for(i = 0; i < sizeof(pinState) / sizeof(*pinState); i++)
    {
        pinState[8] = 0;
    }   
    DDRB = 0xff; // set Port B as output
    DDRC = 0; // WHY DDRC ?? PCINT == PK0-7, so DDRK ? // all Pins input
    PORTC = 0xff; // same question ... // turn on pullup for every pin  
    PCICR |= _BV(PCIE2); // enable interrupt for PCIE2
    PCMSK2 = 0xff; // Interrupt at all pins
    sei(); // turn on interrupts
}

int main(void)
{
    initSystem();
    while(1)
    {
    }
}
ISR(PCINT2_vect)
{
    int i;
    uint8_t changedbits;

    changedbits = PINC ^ portbhistory;
    portbhistory = PINC;
/*  
    if(pinState[changedbits] == HIGH)
    {
        pinState[changedbits] = LOW;
        return;
    } else
    {
        pinState[changedbits] = HIGH;
    }
*/
    setDebugLED(1);
    _delay_ms(30);
    setDebugLED(0);
}

If i connect 5V to one of the PINS (PK0-7) the LED flashes instantly. But if i disconnect the 5V it takes ~2seconds for the LED to flash again. In this time the one pin i connected 5V before does not let the LED flash again if i connect the 5 V again.

Other Ports work in this time.

So you could say, that the PIN HIGH interrupt for all pins work fine and get fired instantly but the PIN LOW interrupts need some time (~2sec.) In this time the port is "disabled" or somethig.

Can anyone help me with that?

EDIT Just some wrong edit ...

EDIT 2 So, i totally forgot to post my solution here. sorry for that!

The solution is: My external circuit pulls the PIN to Ground or to 5V.

Thank you!

Sinic
  • 348
  • 3
  • 10
  • Do you have pullup/pulldown resistors? (You can enable internal pullups via software). – Mitch Oct 10 '15 at 16:26
  • I just have the code described above. How do i check, if the internal resistors are enabled ? I think i overread that in the doku ... – Sinic Oct 10 '15 at 16:30
  • You enable pull up by setting the output register high when the direction register is set to input. If you have a pull up, the pins should be internally driven high, so you would be signaling by pulling them to ground - not 5v. See also arduino se and the ee se. – Mitch Oct 10 '15 at 17:43

0 Answers0