2

i wan't to get Inputs to my Atmega16L from a Button. Ideally i can use the internal Pull-up's, so i don't have to attach them externally.

I've boiled down the code to the minimum:

void main(void) {

// SFIOR &= ~(1<<PUD);  // Turn off Pull-up disable
DDRD = 0xFF;    // Output PORT D
DDRA = 0x00;    // Input PORT A
PORTA = 0xFF;   // Pull-up on PORT A
_delay_ms(100); 
while (1) 
{
    if (PINA & (1<<PA1))    // Check if PA0 is High
        PORTD |= (1<<PD5);  // Set PD5 to High
    else
        PORTD &= ~(1<<PD5); // Set PD5 to Low
}

return;}

I would expect, the Pin PD5 should be high, because the PA1 is pulled up by the internal pull-up, set on line 6. But no, when i run the code, the Pin PD5 is low, and i have to connect the Pin PA1 to 5V, in order to get a High Signal on PD5.

Short things Short, it looks like the pull-up isn't active...

If tried working with the SFIOR, but the PUD is disabled by default, as far as i know.

kind regards, Felix

EDIT: the requested Images:

The wiring (it's a mess)

Felix Kunz
  • 354
  • 2
  • 15
  • Comments are not for extended discussion; this conversation has been [moved to chat](https://chat.stackoverflow.com/rooms/209815/discussion-on-question-by-felix-kunz-atmega16l-pull-up-isnt-active). – Samuel Liew Mar 18 '20 at 01:08
  • Make sure the project is configured and compiled with all definitions related to the selected CPU. Can you also provide the disassemble of the compiled binary? (usually it is in a `.lss` file) – AterLux Mar 18 '20 at 13:09

1 Answers1

2

On the photo you have AVCC power supply not connected (pin 30, against number 11 on the board). AVCC supplies power to ADC and port A. It should be always connected to VCC directly or via a noise filter, but should never be left floating.

Difference between VCC and AVCC should never exceed 0.3 V

Please read the pin descripton at page 5 of the datasheet

AterLux
  • 4,566
  • 2
  • 10
  • 13