0
\$\begingroup\$

I'm new in microcontrollers and I wrote simple program that set HIGH state at PB0 and PB1.

#include <avr/io.h>
#include <util/delay.h>

#define F_CPU 8000000L

int main(void){
    DDRB |= (1<<PB0) | (1<<PB1);
    PORTB |= (1<<PB1);
    PORTB |= (1<<PB0);

    while(1){}
}

The problem is that my avr can't hold on HIGH state and connected leds are blinking. Where is the problem ?

\$\endgroup\$
2
  • 1
    \$\begingroup\$ What does your circuit look like? How do you know the MCU isn't just constantly resetting? How are the LEDs connected, and are you sure they aren't blinking LEDs? \$\endgroup\$ – DigitalNinja May 24 '17 at 22:24
  • 2
    \$\begingroup\$ Can you describe how the LEDs blink? Do you have a scope and can you probe the power and LED pins? Oh, and please add a schematic. \$\endgroup\$ – uint128_t May 25 '17 at 1:09
1
\$\begingroup\$

Which ATmega exactly? What is your fuse configuration?

You can try calling wdt_disable() at the beginning (it is defined in <avr/wdt.h>), as the watchdog can be enabled for example by previous firmware (watchdog is not disabled after a reset) or can be by always enabled at reset.

There is also a fuse setting that does not allow disabling of the watchdog - you have to call wdt_reset() somewhere in the main loop.

\$\endgroup\$
4
  • \$\begingroup\$ This is Atmega8. I didn't set any fuse bits. \$\endgroup\$ – mattsky May 24 '17 at 21:34
  • \$\begingroup\$ which atmega8 specifically? come on, try to be as verbose as possible if asked for details; make sure the fuses are what you expect them to be. \$\endgroup\$ – Marcus Müller May 24 '17 at 21:58
  • \$\begingroup\$ @MarcusMüller ATMega8 is a specific Atmel part. \$\endgroup\$ – Tom Carpenter May 24 '17 at 22:06
  • \$\begingroup\$ @TomCarpenter my understanding was that fuses were specific to case variant, but it seems I was mistaken. My apologies, Mattsky! \$\endgroup\$ – Marcus Müller May 24 '17 at 22:15

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.