I have an ATmega644 connected to another device using the UART. After receiving a few characters on the UART the device resets and/or acts weird. Some examples of this behavior:
- Code before the main loop is executed again but MCUSR is 0 (i.e. no "real" reset)
- Code inside the main loop is executed even though the switches connected to the inputs were not pressed (pullups are configured properly).
- Sometimes the MCU just hangs
- Sometimes ports that were not configured as outputs act as outputs (e.g. LEDs connected to them light up even though the DDR for that port is 0).
The device is using an external 18.432 MHz crystal and the UART is set to 19200 baud. It is powered with 5V; the RX pin is connected to a 3V3 RPi.
Best Answer
Even if it the problem with this particular setup was something else (as pointed out by another answer), another common reason is that the controller is being operated outside the "safe operating area" with respect to Vcc VS clock speed.
With 18.432 MHz clock speed the device would require at least about 4.2V to function properly.