How to solve Atmega 16A Serial write (println) hang with Arduino Uno firmware? For doing some experiments I bootloaded an Atmega16a with Arduino Uno. I am powering my Atmega16a from Arduino UNO. I am not using any external clock. Atmega16a is connected to a breadboard. For bootloading I refer the site http://hardwarefun.com/tutorials/use-arduino-as-an-isp-programmer-to-program-non-arduino-avr-microcontrollers I can run blink sketch on my Atmega16a using Arduino as ISP. TX and RX of Atmega16 is connected to Max485's DI and RO respectively.

Atmega16a pin 14 (RXD) -&gt; MAX485 pin 1-RO 
Atmega16a pin 15 (TXD) -&gt; MAX485 pin 4-DI  
Atmega16a pin 17 (D3)  -&gt; MAX485 pin 2 and 3. Also connects a LED to the pin


I used a boards.txt downloaded from https://github.com/sudar/arduino-extra-cores/blob/master/boards.txt

Issue: hang at Serial.println

I faced issues when I started to interface with MAX485.

The program wont run if I add a Serial.println, see my program below.

void setup() {
   Serial.begin(76800); // I tried 9600 too
   pinMode(3, OUTPUT);
}

void loop() {
  digitalWrite(3, HIGH); 
  delay(400);
  Serial.println("20"); //comment this code and could see the led blinks
  delay(2000);
  digitalWrite(3, LOW);
  delay(400); 
}


Regression

I tried Latest Arduino IDE as well as 1.0.6 version

I could do a serial communication with Raspberrypi and Arduino Uno via MAX485 without any issues. For the complete connection detail of MAX485 and other Arduino, check my blog.

Some times I receive some string to serial port of Raspberry pi like below. I run a nodejs app in RPi, using serialport npm and parser is RAW.

&lt;Buffer fa&gt;
&lt;Buffer 82&gt;
&lt;Buffer 86 ff&gt;
&lt;Buffer fe&gt;
&lt;Buffer fe&gt;


How to prevent these hangs?
Unfortunately you can't just simply upload the Arduino bootloader and expect it to work. The ATmega16 is not the same as the ATmega328. One quick look at the datasheet will already explain why this is not working. The UDR(USART data register) is at 0xC6 on the 328, while it's at 0x2B at the Atmega328. So the ATmega16 will look at the location where the 328 stores the received data and will not find it. This could explain the hang, but I expect that other things like UART setup will have gone wrong before you get to the receiving of data. 

If you want serial communication with the ATmega16, try programming it directly in C with the AVR libraries and without the Arduino extensions. That will make it harder to figure out.