Put an Arduino Uno in programming mode

Hello,

I have two Arduinos, one Atmega2560 and one Atmega328p (16MHz with optiboot from Nick Gammon Atmega_Board_Programmer).
I try to upload a sketch from Atmega2560 (RX1/TX1) to Atmega328p (in TX/RX), but Atmega328p fail to enter in programming mode.

Atmega2560 → Atmega328p
D38 → RST
TX1 → RX
RX1 → TX

I use the following code to reset Atmega328p:

digitalWrite (38, LOW);
delay (100);  
digitalWrite(38, HIGH);
delay(100)

After this, try to get in sync with Atmega328p:

 for (int i = 0; i < 16; i++) {
    Serial1.write((char)0x30);
    Serial1.write((char)0x20);
    delay(50);
  }

But nothing happens. Atmega328p responds with 0x00 0xFF instead of 0x14 0x10.
When I try the same code with Atmega2560 and Arduino Mini Pro (from SparkFun - I don’t know what bootloader have) is working like a charm.

I suspect it is a problem with the reset time. I have tried many versions, but I have’t found the right values.

Sorry for my English, but is not my first language. Thank you.

Is the board actually running at 16mhz? Is the external crystal connected correctly?

Running on 16MHz. I can upload using FTDI with no problem.

Pro Mini usually uses a 57600 baud bootloader. Optiboot usually is compiled to run at 115200. Have a look the Arduino IDE’s boards.txt file to see the baud rates. Can you please post the results of your work when you get this going so we can see how to accomplish this type of programming from one board to another?

I try at different bound rate (all of them). Indeed, with Pro Mini work only at 57600 bound rate.

Rebootload the Promini as an Uno, then it will upload at 115200. I bootload all my 328P designs as Uno, easy to keep track that way. (unless I need to use A6/A7 with SMD parts, then I'll do things a little different).

CrossRoads: Rebootload the Promini as an Uno, then it will upload at 115200. I bootload all my 328P designs as Uno, easy to keep track that way. (unless I need to use A6/A7 with SMD parts, then I'll do things a little different).

Not Pro Mini is my problem. It is work. As I said, I have a 328P with optiboot (as an Uno) who fail to enter in programming mode.

Can you please share your sketch which you use to send a program from Mega to the Pro Mini bootloader, so we can see how it is done? I would like to learn about this.

AdrianZa: Not Pro Mini is my problem. It is work. As I said, I have a 328P with optiboot (as an Uno) who fail to enter in programming mode.

Do as Crossroads says. This is to confirm that the problem may be the bootloader and not the hardware.

mart256:
Do as Crossroads says. This is to confirm that the problem may be the bootloader and not the hardware.

When try to upload in 328p (with optiboot as UNO) thru FTDI, from computer, work whit not problem. When try to upload in 328p (with optiboot as UNO) from Atmega2560 it is not working.

If is there a problem with the bootloader, I would be able to upload sketch thru FTDI from computer?

dmjlambert: Can you please share your sketch which you use to send a program from Mega to the Pro Mini bootloader, so we can see how it is done? I would like to learn about this.

I will try to explain when I get in front of a PC. I write from phone now.

It is possible you are doing commands which are not compatible with all bootloaders, such as Uno's bootloader. Are you able to upload to the Pro Mini from the Mega?

dmjlambert: It is possible you are doing commands which are not compatible with all bootloaders, such as Uno's bootloader. Are you able to upload to the Pro Mini from the Mega?

Yes. From the Atmega2560 to the pro Mini I can upload with no problem and it is working perfect.

I didnt mean that the bootloader is corrupt, I mean the bootloader may be in conflict with the uploader sketch. But its up to you if you want to check what its suggested. Good luck.

AdrianZa: Yes. From the Atmega2560 to the pro Mini I can upload with no problem and it is working perfect.

Ok if you can post the Mega code which works for uploading to the Pro Mini that will probably help.

I started from well done work of YouTube user George Caley and add some minor improvements to make it work for me.
This is the sketch for Atmega2560 that work with Mini Pro.
I use Arduino IDE 1.0.6
I attached the sketch archive

syncUpdate_Serial_1.zip (3.29 KB)

SOLVED

I attached the new version.

syncUpdate_Serial_1_solved.zip (3.38 KB)

That is really nice. It is a shorter sketch than I thought it would be. How did you get the program hex file formatted into the PROGMEM array like that?

With a script write in python. I use version 2.7
I attached the script file. Please change the .h extension to .py
In shell command line (or cmd.exe) use:

C:\Python27\python.exe C:\Python27\embed-arduino.py C:<Path to hex file><file>.hex

where .hex is the file created by your IDE compiler.

embed-arduino.h (759 Bytes)

This is really cool, thanks. I got it to work the first time. I put my own custom sketch in the PROGMEM array and uploaded from Mega to Uno. I did this in Arduino 1.0.6. I have some trouble in 1.6.5 because during compile it says "prog_uchar does not name a type" so I have some learning about that to do...