I was using ATmega32A before and now I am migrating to ATmega324PA just to enhance power management. Now I am testing the new controller in every aspect. This is a simple code to check the watchdog timer but it keeps resetting the controller.
Code:
int main(void)
{
uart_init();
PORTA|=(1<<PORTA1);
_delay_ms(1500);
PORTA&=~(1<<PORTA1);
_delay_ms(2000);
uart_array("FFFFFFFFFFFFFFFFFF");
wdt_enable(WDTO_2S);
_delay_ms(5000);
}
void uart_init()
{
/*set PinA1 as output for LED*/
DDRA|=(1<<1);
/*set PinD3 as output for UART*/
DDRD|=(1<<3);
/*set pinD2 as input for UART*/
DDRD&=~(1<<2);
/*enabling TX and RX*/
UCSR1B |=(1<<TXEN1) | (1<<RXEN1);
/*asynchronous mode selection*/
UCSR1C&=~(1<<UMSEL11);
UCSR1C&=~(1<<UMSEL10);
/*setting data format to 8 bit*/
UCSR1B &=~(1<<UCSZ12);
UCSR1C|=(1<<UCSZ11)|(1<<UCSZ10);
/* setting one bit as stop bit*/
UCSR1C &=~(1<<USBS1);
/*Disabling parity*/
UCSR1C &= ~((1<<UPM11) | (1<<UPM10));
/* loading 8 LSB to UBRRL*/
UBRR1L = UBRRL_VALUE;
/* loading 4 MSB to UBRRH*/
UBRR1H = UBRRH_VALUE;
}
The code works well for the first time, but after that, LED keeps blinking.
Note: watchdog (WDTON) fuse bit is disabled.