Difficulty uploading a sketch to a standalone ATMEGA2560 over FTDI

It's my first standalone project on a board I designed and fabricated using one of those desktop CNC routing machines. :slight_smile:

Now I'm trying to upload the sketch to the ATMEGA2560-16AU using FTDI. And not having much joy :frowning:

When I say standalone, it also has some L298 motor controllers, some opto-isolated inputs and a buck power supply, but nothing too complicated.

There should be a photo link here:
If you can view the photo you might notice I totally forgot to add the ICSP header, and had to add it in afterwards. :blush:

I used Nick Gammon's Atmega_Board_Programmer on an Arduino Mega2560 to flash the bootloader.
To do this I cut the 5v power supply trace from the board, so that the target chip was powered from the Arduino Mega. The programmer reports that it was successful.

I have an LED connected to pin 26 on the MCU (Arduino pin D13) which repeatedly flashes twice. I guess that means it is waiting for a a sketch to be loaded?

Now the next step, uploading the sketch (using a FTDI adaptor) times out. :frowning:

I have tested that my FTDI adaptor is working using another board I had lying around, iBoard Pro by Itead Studio. No problems there.

I have checked the fuses are set correctly using Nick Gammon's Fuse Calculator (see attached)

I have the reset pin connected with a series cap (100nF) and a 10k pullup. I have checked with with a scope, and it definitely pulls to zero, and then rises to about 4.9v after 2.5ms.
Could this be too fast? i.e. not long enough to cause a full reset?

I have enabled the clock output on pin PE7 (set low fuse to BF) to make sure my crystal is working correctly... looks like a pretty solid 16MHz signal.

The only hint I have is that pin2 (RX0) is permanently pulled low. It pulls the TX of the FTDI low as soon as it is connected. I have tested with a multimeter, it is not shorting on any other pins and I have 1.8 MOhms to ground (this is similar to the iBoard Pro I successfully uploaded to earlier).

Is there some fuse or enable bit I am missing that enables serial port 0?

I reflowed the chip using solder paste and a hot air pencil. I was careful not to use too much heat for too long... could I have cooked the chip and only affected Serial 0?
Surely the other functions (flashing pin 26, clock output on PE7) would also be affected if that was the case?

Any help (from anyone who has actually built a standalone AVR) would be greatly appreciated.

Atmega Fuse Calculator.txt (886 Bytes)

How are you trying to upload to the custom board? From the IDE? If so, which board type do you have selected in the IDE?

Hi Fred
Thanks for your reply

I'm uploading using the Arduino IDE.
I have selected "Arduino/Genuino Mega or Mega2560" selected and ATmega2560 selected under Processor Selection. See attached screen shots (apologies for the poor quality)

The FTDI adaptor comes up as com3.

This setup works well on the iBoard (3rd party ATmega2560 board with no USB etc)
However when I connect it to my custom board it fails (keeping all other settings the same)

This is what leads me to believe there is nothing wrong with the IDE settings or the FTDI adaptor.

When I put a scope on pin 2 of the iBoard (which uploads successfully) it sits high just before upload
i.e. it is not pulled low, as is the case on my custom board.

Board Selection.jpg

Re-attaching some attachments that got lost in previous post.

Board Selection.jpg

Processor Selection.jpg

Well, I'm stumped. The low pin 2 is definitely a factor as the 2560 is never going to see the incoming data stream.

The only thing running should be the bootloader and that shouldn't have pulled it low. If you jumper the 2560 reset low, do all the pins, in particular pin 2, float high?

Do you have a schematic? Can't tell much from that low resolution picture.
Something readable like this
https://forum.arduino.cc/index.php?action=dlattach;topic=455570.0;attach=205394

Sorry for the late reply... for some reason I did not receive any notifications on this thread :frowning:
I assure you I have been working on this every day since my last post, and have made some limited progress. Unfortunately I attempted to lift the mega chip, and destroyed both the chip and the board in the process. :frowning: Sorry Fred, I wont be able to test the pin states with the reset pulled low.

What I have now done is to simplify the board, stripping the peripherals down to just 4 LEDs, and adding in the things I forgot in the last one. See attached schematic and layout:

  • ICSP header
  • 100nF caps on each 5v/gnd pair of the mega.
  • 10k pullup resistor on reset pin (I forgot this on the previous board, but added it by hand)

I routed the board and loaded the bootloader no problem. Then it took a few attempts but, I was able to get a sketch to upload using the arduino IDE! :slight_smile:
But only once. Subsequent attempts failed.

I have a feeling my combination of reset cap (100nF) and pullup resistor (10k) is too fast. i.e. either the reset pin is not pulled down long enough to reset the chip properly, or its just too fast for what the IDE is expecting.

Barebones Mega.PDF (293 KB)

0.1uF and 10K should work just fine, I use that in all my designs.

Aref should only have a cap to Gnd, not be connected to 5V.
33pC on the crystal is too much, that may affect the crystal starting up.
What is the reset diode? That is not a diode symbol.

Hi Crossroads
Good spotting on the AREF... will implement that immediately.

I found diodes a bit of a hurdle when moving from through hole to SMD. My favorite 1N4007 doesn't seem to have a direct equivalent. As I understand they mainly come in SOT23 packages even though the 3rd pin is unused. I guess this is to eliminate incorrect assembly.
The one Im using is BAS16LT1G (Diode Standard 75V 200mA (DC) Surface Mount SOT-23-3)
The symbol is from the altium vault... it guess it looks funny because they show the unused pin on the SOT23.

I have attached the datasheet for the crystal. It states a loading capacitance of 16pF.
I thought I had calculated the caps correctly using the following formula:
CL = (C1 * C2) / (C1 + C2) + Cstray
I used the microstrip model on this website to calculate my Cstray with the following parameters:

  • w=0.3
  • t=0.035
  • h=1.6

This gave me a Cstray of 42.43 pF/m
multiplying by 14mm I calculated Cstray = 0.59pF

I used the closest available option of 33pF to achieve Cl=17.09pF
22pF would have given me Cl=11.59pF

Did I go wrong somewhere in my calculations?

Perhaps I selected a rubbish crystal to begin with?

SMD49S-16M1630F.pdf (58.9 KB)

I use digikey to search for components. I try to use 0805 size components so hand assembly is reasonable.
Diodes:

Crystal, I think I've been using this one

as seen here on a 2560 board

with 22pF caps. No problems. The Atmel datasheet also recommends caps from 12-22pF. 33pF might work. Try a lower value if not.

Thanks Crossroads.
I have ordered those crystals from Digi-key.
I also ordered a couple TCXO oscillators... just for experimentation purposes.
The project needs to read the frequency of a water flow meter so stable timing is pretty important.

Should arrive here in South Africa in about 6 days...
I'm going to try some 22pF caps in the morning.
Will let you know how I get on

Update...
I have replaced the crystal caps with 22pF as suggested.

The atmel-ice I purchased a last week finally arrived, so I've been playing with it using Atmel Studio 7 (AS7).
I am able to upload sketch after sketch to my barebones board in AS7 using the ISP connector, and it runs nicely, so that feels like a small victory :slight_smile:

Then just for academic purposes I reloaded the arduino mega factory bootloader, and was able to upload a sketch over FTDI using the Arduino IDE :slight_smile:
But again only once >:(
All further upload attempts failed.

I then tried to retrace my steps...

  • I erased the chip, and reloaded a blinky type sketch successfully (using AS7)
  • then reloaded the Arduino bootloader,
  • unplugged and replugged everything (including the FTDI adaptor)
  • shutdown and restarted Arduino IDE
  • but was unable to load a sketch using the Arduino IDE

I have attached a copy of the IDE output...

It fails at the same place every time, then the IDE hangs and I have to kill it in Task Manager (Im using win7)
Seems like it sends the first block, and then fails to get a verification.
However before that, it does read the device signature, so the return comms must be working.
Could it be the MCU fails to receive the first block?

I'm interested in the line

avrdude: stk500v2_getsync(): timeout communicating with programmer

This makes me think I think I have a dodgy FTDI adaptor?
Poor connections does not explain why it fails at the same place every time

While writing here I have realized I should write a sketch to test the comms...
Will do that now

Arduino ISP degub output - barebones mega.txt (4.14 KB)

A simple echo sketch confirms that the serial0 can send and receive without difficulty
I tested it at 9600 and 115200 baud.

I still have not managed a second upload using the Arduino IDE.
The only hint I have is that pin 13 flashes differently than a standard Arduino when i load the standard bootloader named:
Mega2560-prod-firmware-2011-06-29.hex
Here is a video: of the LED on pin 13 alongside a standard arduino mega with the same bootloader.

Remove 22pF C8 from the Reset lead on your FTDI circuit and see what happens.

Try using stk500boot_v2_mega2560.hex.

"stk500boot_v2_mega2560.hex is the newer one that fixes the WDT and the !!! problems

Mega2560-prod-firmware-2011-06-29.hex is the original bootloader that has both those problems"

My fuse settings:

avrdude: safemode: hfuse reads as D8
avrdude: safemode: efuse reads as FD
avrdude: safemode: Fuses OK (E:FD, H:D8, L:FF)