1
\$\begingroup\$

I feel like this is a true beginners problem, but I fail to see what I am doing wrong here:

I have a SIP switch connected to port A of an Atmega32 and I cannot read correct values from the port. Here is the relevant part of the circuit diagrm:

enter image description here

Now in code, I configure port A as input and activate the internal pullups, however I always read the data word I write to the port when configuring the pullups. Measuring the voltage at the pins with a multimeter I read the correct highs and lows according to the position of the single switches.

The rest of my circuit works, SPI communication and all. Still I reproduced the problem with a minimalist example, what could possibly go wrong here?

#include <avr/io.h>

int main(void)
{
    PORTA = 0xff;
    DDRA = 0xff;
    while(1)
    {
        char bla = PORTA;
    }
}

I cannot rule out, that I have damaged the port, through misconfiguration and the resulting short circuit. So should my next step be to exchange the controller?

\$\endgroup\$
5
\$\begingroup\$

The input available at port <x> is read from PINx. PORTx contains the latched values last set there.

char bla = PINA;
\$\endgroup\$
  • 1
    \$\begingroup\$ There is a saying here in Germany that roughly translates to he who can read has clear advantages in life :). Thanks for spotting my mistake so quickly. \$\endgroup\$ – Herr von Wurst Sep 11 '14 at 11:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.