0
\$\begingroup\$

I'm a complete beginner in microprocessor programming. I managed to program my ATtiny25-20PU with AtmelStudio 7 and an AVR-ISP-MkII. However, I don't get any output on my output pins!

The ATtiny is new and never used before. I'm pretty sure that the programming worked, since device signature could be read and the programmer could verify the program. So I think the problem is in my simple program or in my even simpler circuit. I've never done this before and maybe missed something obvious?

The entire circuit (when testing, after programming) was:

  • Connect VCC to 5V.
  • Connect GND to ground.
  • Connect RESET to ground for a while, then connect it to VCC. I also tried doing this using a button but observed no difference.

But PB3 and PB4 are low all the time! This is the program:

#define F_CPU 1000000UL
#include <avr/io.h>
#include <util/delay.h>    

int main(void) {
    DDRB |= 1<<PB4;
    while (1) 
    {
        DDRB |= 1<<PB3;
        _delay_ms(200);
        DDRB &= ~(1<<PB3);
        _delay_ms(200);
    }
}

So I'm expecting PB3 to go high and PB4 to give a square wave. What can I do to keep troubleshooting? Or verify that I actually managed to program the ATtiny? I'm completely stuck.

\$\endgroup\$
  • \$\begingroup\$ When you program your uC using AtmelStudio, it should tell you the outcome on the screen. \$\endgroup\$ – Nazar Nov 11 '16 at 19:42
  • \$\begingroup\$ @Naz What do you mean by outcome? \$\endgroup\$ – Anna Nov 11 '16 at 19:44
  • \$\begingroup\$ Don't you have a window like this, that tells you the results of the programming process in the left bottom corner? \$\endgroup\$ – Nazar Nov 11 '16 at 20:04
  • \$\begingroup\$ @Naz I understand, yes, that's what I meant by "the programmer could verify the program". I don't know the right words. This is why I thought the problem was in my circuit or code, and not in the programming. And it was! \$\endgroup\$ – Anna Nov 11 '16 at 20:07
3
\$\begingroup\$

DDRx sets the direction. PORTx determines the output level and presence of the input pull-up resistor.

int main(void)
{
    DDRB |= _BV(PB4);
    while (1) 
    {
        PORTB |= _BV(PB3);
        _delay_ms(200);
        PORTB &= ~_BV(PB3);
        _delay_ms(200);
    }
}
\$\endgroup\$
  • \$\begingroup\$ Wow, I spent so much time double-checking everything. It's working now. Thank you so much! \$\endgroup\$ – Anna Nov 11 '16 at 19:42

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.