Programing PCB based on arduino mega 2560 with FTDI

I did a PCB based on arduino mega but without USB and ATMEGA8U2. I am burning the bootloader with an arduino as ISP. Burning process is okay.

I am trying to use an FTDI to upload my sketchs and here is the problem. I can upload a sketch just once and then next time I try to upload I get the message:

Arduino: 1.8.5 (Windows 10), Board: "Arduino/Genuino Mega or Mega 2560, ATmega2560 (Mega 2560)"

Sketch uses 1470 bytes (0%) of program storage space. Maximum is 253952 bytes.
Global variables use 9 bytes (0%) of dynamic memory, leaving 8183 bytes for local variables. Maximum is 8192 bytes.
C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avrdude -CC:\Program Files (x86)\Arduino\hardware\tools\avr/etc/avrdude.conf -v -patmega2560 -cwiring -PCOM13 -b115200 -D -Uflash:w:C:\Users\H4D3E~1.GOE\AppData\Local\Temp\arduino_build_886616/Blink_deteste.ino.hex:i

avrdude: Version 6.3, compiled on Jan 17 2017 at 12:00:53
Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
Copyright (c) 2007-2014 Joerg Wunsch

System wide configuration file is "C:\Program Files (x86)\Arduino\hardware\tools\avr/etc/avrdude.conf"

Using Port : COM13
Using Programmer : wiring
Overriding Baud Rate : 115200
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_getsync(): timeout communicating with programmer

avrdude done. Thank you.

An error occurred while uploading the sketch

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.


FTDI connections are:

FTDI pcb

Pin 1 (ground) -> Ground
Pin 2 (CTS) -> not connected
Pin 3 (Vcc) -> 5V
Pin 4 (TxD) -> Rx (Mega pin D0)
Pin 5 (RxD) -> Tx (Mega pin D1)
Pin 6 (DTR) -> not connected

It seems the bootloader is being overwritten when I upload the sketch.

Any ideas what the problem is ?

many thanks

Normally, after the microcontroller is reset, the bootloader runs for a couple seconds, during which time you can do an upload. However, right after you have done a Burn Bootloader the bootloader is running constantly so there is no need for a reset. The problem is you aren't resetting the ATmega2560 when the upload starts. On a regular Arduino board this is done automatically by connecting the DTR pin on the USB-TTL serial adapter to the reset pin of the microcontroller via a 0.1 uF capacitor. If you don't have the auto-reset circuit then you will need to manually reset the microcontroller at just the right time, after compiliation finishes and just when the upload starts.

Hi pert,

I did your recommendation and adjusted RC time constant of my board to be similar of arduino mega2560 and just worked fine!

Just one more question. I need to upload sketchs in my final version of the board on serial1 (unfortunatly I end up using serial0 for other purpouse. My mistake).

When I try to upload using serial1 I get the error message:

"
....

avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_getsync(): timeout communicating with programmer

...

"

Is it possible to upload on serial1 ?

Many thanks for your support pert

best regards

rick

Yes, but you'd need to recompile adjust the makefile and recompile the bootloader. IIRC I wasn't able to make it build on windows, period - I had to use the linux box.

MegaCore comes with pre-compiled bootloaders for all the UARTs. There isn't a custom Tools menu for that option but it's easy enough to make the necessary change to boards.txt:

2560.menu.clock.16MHz_external.upload.port=UART0

to:

2560.menu.clock.16MHz_external.upload.port=UART1
  • Save the file
  • Restart the Arduino IDE (this is necessary to pick up the changes to boards.txt).
  • Connect an ISP programmer to your ATmega2560.
  • Tools > Programmer > Select the appropriate programmer
  • Tools > Burn Bootloader

Note the above instructions assume you have Tools > Clock > 16 MHz external selected. If you are using a different clock selection, you only need to change the upload.port property in boards.txt associated with that configuration.

Hello again pert,

It worked very well. I will have to validate my design with this new bootloader to check if all functionalities of my board will behave the same way as the original bootloader, isn't it ? (I have sensors and ethernet shield etc..)

many thanks for your help

best regards

Bootloader is mostly only used for uploads so it shouldn't make any difference. This bootloader does have a special feature that allows you to write to flash memory from your application:

MegaCore does have its own core library, bundled libraries, and variant files. I believe there is a small difference in the compiler flags in that MegaCore does not use -fpermissive as Arduino AVR Boards does, which upgrades some things to compilation errors that would only be warnings when compiling for the Arduino Mega. But overall MegaCore is intended to work the same as the standard Arduino board definitions.

If you wanted, you could use only the bootloader file from MegaCore and go back to using the Tools > Board > Arduino Mega menu selection with your board. The only disadvantage of that is the optiboot bootloader used by MegaCore fits in the ATmega2560's minimum 1 kB boot section, which the outdated STK500 bootloader used by Arduino AVR Boards for the Arduino Mega requires an 8 kB boot section! So the Arduino Mega board selection will tell you you're out of program memory when you actually still have 7 kB free. The ATmega2560 has so much flash memory that's not likely to be a problem. Of course fixing that only requires changing one line in boards.txt.