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:
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?
Best Answer
The input available at port <x> is read from
PINx
.PORTx
contains the latched values last set there.