I am using the ATMEGA644P with a 7.3728 crystal. The microcontroller starts over every time it executes a call to rpirntf followed by a delay. It doesn't even matter if I use delay.h or use my own looping delay, there is no difference. Please look at this code:
#include <avr/io.h>
#include <util/delay.h>
#include "uart2.h"
#include "rprintf.h"
void configurePorts(void);
int main (void) {
configurePorts();
uartInit();
rprintfInit(uart0SendByte); // UART0 = DDD1
rprintf("ABC\n\r");
_delay_ms(1000);
rprintf("DEF\n\r");
_delay_ms(1000);
rprintf("GHI\n\r");
return 0;
}
void configurePorts(void) {
// Port B: Only used to scope pins for delay
DDRB = 0xFF; // All Outputs
PORTB = 0xFF; // All High
// Port D: UART0 is DDD1
DDRD = (1 << DDD1);
}
When run, this code prints the ABC, delays for a second, then starts over. I figured delay.h and the UART are having a conflict so I replaced the delay with a loop of my own:
void sec(void) {
unsigned long int x;
for (x = 0; x < 780000; x++) {
PORTB ^= (1 << PB0);
}
}
And called "sec" instead of _delay_ms(1000). Same exact thing happened. If I comment out the 1st rprintf call it will do the 1st delay, 2nd rprintf call, 2nd delay, then start over. So basically, a rprintf call followed by any kind of delay causes the uC to reset. Anyone know what I'm doing wrong?