Problems to program a PCB based on Arduino Mega rev3 schematics

Thread Starter

Tesla86

Joined Oct 25, 2016
34
I've developed a project that basically consists of reproducing the Arduino Mega schematics and export it to an ECAD tool to test my PCB design skills after a technical course.

After recieving the PCB and soldering the components everything worked fine from an electrical point of wiev. The problem came up in the very last step when I tried to program the PCB from the Arduino IDE using the USB. The IDE tries to upload the sketch but this never happens, giving the following error:

avrdude: Version 6.0.1, compiled on Apr 15 2015 at 19:59:58 Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/ Copyright (c) 2007-2009 Joerg Wunsch

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

Using Port : COM7 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 ocurred while uploading the sketch

Until now I've tried (successfully) the following steps:

  • I've programmed ATMEGA2560-16AU using an Arduino USB-to-Serial module, which is basically the same circuit included in the Arduino Mega, and it works fine. Before programming, I bootloaded the micro following information offered in Arduino official web page.
https://store.arduino.cc/product/A000059

I've to point out that to program the PCB from outside I had to remove C7 cap (100nF) to cancel ATMEGA16U2 DTR line reset effects on ATMEGA2560-16AU. After programming, I resoldered it to allow ATMEGA16U2 to communicate with ATMEGA2560-16AU (ARDUINO MEGA Schematics attached).

  • I've followed a tutorial to flash ATMEGA16U2 using ATMEL's FLIP software. After put the microcontroller in DFU mode and install the proper Arduino driver, the computer and Arduino IDE both recognize it as a COM port, so everything looks to be fine.
So I think after a full revision the problem may be focused on some king of communication problem between the two microcontrolers, but I'm not sure...

I'll be very grateful if anyone can give me some feedback to fix this issue.

Thanks in advance
 

LesJones

Joined Jan 8, 2017
4,174
shteii01,
I think the OP it trying to program the MEGA256 with the bootstrap loader. This is done using the reset, MISO, MOSI and SCK pins on the mega 256. (Not via the serial port from the Arduino IDE as you would load a sketch. The bootstrap loader is used to load via the serial port.)

Les.
 

Thread Starter

Tesla86

Joined Oct 25, 2016
34
shteii01,
I think the OP it trying to program the MEGA256 with the bootstrap loader. This is done using the reset, MISO, MOSI and SCK pins on the mega 256. (Not via the serial port from the Arduino IDE as you would load a sketch. The bootstrap loader is used to load via the serial port.)

Les.
Thank you Les. If I've understood right, the OPA is trying to program the micro in an undesirable way? If I'm right, how can I avoid this effect?
 

bug13

Joined Feb 13, 2012
2,002
Do you have bootloader on your AVR? To program Arduino over serial, your AVR needs to be programmed with a bootloader first if not already.
 

LesJones

Joined Jan 8, 2017
4,174
Hi Tesla86,
I don't understand post #5 (what is the OPA ?) I have programmed blank ATmega328P-PU chips with the bootloader in the past using avrdude or eXtreme Burner AVR software. (I can't remember which one I used) I did this with the chip removed from the Arduino uno board. Make sure that nothing is loading any of the programming signals. Are you using an STK500 or some type of clone to load the bootloader code ?

Les.
 

LesJones

Joined Jan 8, 2017
4,174
I have found a schematic for the Arduino MEGA 2560 and the programming signals (Reset, MISO, MOSI and SCK) only seem to go to the ICSP header so nothing should load them. I have found this web page that may help. There is lots of information if yoy Google "loading bootloader into atmega 2560"

Les.
 

shteii01

Joined Feb 19, 2010
4,644
Like others said there are two ways to load a program into ATmel chip:
1) Use programmer to program the chip. Programmer is specialized device, and expansive.
2) Use chip that has bootloader. Bootloader is software that is placed into the chip memory. It then receives the user program (to blink led or whatever the user wants) and places it into chip memory. The difference is that bootloader lets you use simple (reach cheap) hardware to connect to pc.

So you stuck in the "chicken and egg" paradox.

My advice is to get a cheap Arduino Uno clone, use it to program your ATmel chip.

And next time do more research. You could have avoided the whole thing if you bought chip with bootloader already on it.
 

shteii01

Joined Feb 19, 2010
4,644
Which, of course, is still a possible solution.
True. However, then they would have two chips, and only one would be usable.
To make long story short, I would still buy cheap Chinese Uno board, use it as programmer, and afterward I would still have it available for other projects, tests, prototyping, or just trying out some ideas.

I recently found out that I can use Uno to build USB-to-GPIB adapter. GPIB is used to communicate with various electronic test equipment, particularly older HP oscilloscopes, and other lab gear. Also recently found out that I can use Uno for USB-to-TTL adapter (by bypassing onboard ATmega 328), which makes 8 dollar Uno do job of 20-30 dollar USB-to-RS232 cable and I don't need to build additional circuitry to talk to my uC. So. Yeah. I am going to buy something like 3 or 4 Chinese Uno clones the next payday.
 

Thread Starter

Tesla86

Joined Oct 25, 2016
34
True. However, then they would have two chips, and only one would be usable.
To make long story short, I would still buy cheap Chinese Uno board, use it as programmer, and afterward I would still have it available for other projects, tests, prototyping, or just trying out some ideas.

I recently found out that I can use Uno to build USB-to-GPIB adapter. GPIB is used to communicate with various electronic test equipment, particularly older HP oscilloscopes, and other lab gear. Also recently found out that I can use Uno for USB-to-TTL adapter (by bypassing onboard ATmega 328), which makes 8 dollar Uno do job of 20-30 dollar USB-to-RS232 cable and I don't need to build additional circuitry to talk to my uC. So. Yeah. I am going to buy something like 3 or 4 Chinese Uno clones the next payday.
Yes, I have the correct bootloader installed in both microcontrollers but the problem may be in the communication between them. Now I'm programming the ATMEGA2560 with this:

https://www.arduino.cc/en/Main/USBSerial
 

Thread Starter

Tesla86

Joined Oct 25, 2016
34
Hi Tesla86,
I don't understand post #5 (what is the OPA ?) I have programmed blank ATmega328P-PU chips with the bootloader in the past using avrdude or eXtreme Burner AVR software. (I can't remember which one I used) I did this with the chip removed from the Arduino uno board. Make sure that nothing is loading any of the programming signals. Are you using an STK500 or some type of clone to load the bootloader code ?

Les.
Hil LesJOnes,

I used an Arduino Uno (original) to upload the bootloader code, following a tutorial about this issue by Arduino... Yes, I use AVRDUDE. The thing is that I can program main ATMEGA 2560 using this:

https://www.arduino.cc/en/Main/USBSerial

Which means ATMEGA 2560 has the correct bootloader installed on it and, separatelly, after upload the proper bootloader to ATMEGA 328 I did a loopback test and everything was OK. So I think the problem must be between the communication between both microcontrollers...
 

LesJones

Joined Jan 8, 2017
4,174
Hi Tesla86,
I totally misinterpreted your first post. My understanding now is the you have programmes the ATMEGA 256 with the boot loader and you have programmed the ATMEGA16U2 with the firmware to do the USB to serial conversion. You have proved that the ATMEGA16U2 is working as a USB to serial converter with your loopback test. But the serial link between the two ATMEGAs does not seem to work. Are you sure that you have not got Tx and Rx mixed up so the Tx is conected to Tx and Rx is connected to Rx. Do the Rx and Tx LEDs on the ATMEGA16U2 both flash when you try to upload a sketch ? Is it possible that there are different versions of the firmware and you may have the wrong version ? I don't know very much about the Arduino. I mostly just load assembled code into the ATtiny range.

Les.
 

Thread Starter

Tesla86

Joined Oct 25, 2016
34
Hi Tesla86,
I totally misinterpreted your first post. My understanding now is the you have programmes the ATMEGA 256 with the boot loader and you have programmed the ATMEGA16U2 with the firmware to do the USB to serial conversion. You have proved that the ATMEGA16U2 is working as a USB to serial converter with your loopback test. But the serial link between the two ATMEGAs does not seem to work. Are you sure that you have not got Tx and Rx mixed up so the Tx is conected to Tx and Rx is connected to Rx. Do the Rx and Tx LEDs on the ATMEGA16U2 both flash when you try to upload a sketch ? Is it possible that there are different versions of the firmware and you may have the wrong version ? I don't know very much about the Arduino. I mostly just load assembled code into the ATtiny range.

Les.

Dear Les,

Now you've explained my problem in a perfect way. This is exactly my problem.

I've double checked RX and TX and they're not mixed up, but they do not flash when I try to upload my skecth. I'm going to try with other bootloaders...

Thank you very much for your advice!
 

bug13

Joined Feb 13, 2012
2,002
If you have an arduino UNO, you can take out the mega328 and use it as a USB to TTL programmer. And by pass the USB to TTL part of the circuit of your board.

If it works, something wrong with the USB to TTL circuit.

If it doesn't work, it's your mega2560 part of the circuit.
 

LesJones

Joined Jan 8, 2017
4,174
you could try patching the serial signals from ATMEGA16U on the Uno to the ATMEG256 chip and see if you you can program the 256 that way. You would need to break the serial link on the 2560 board by removing the 1 K resistors. On the uno board you could just remove the ATMEGA 328P from its socket. You could also try tis the other way round. That would require removing the 1 K resistors from both boards. Talking about the 1K resistors has just made me think of another possibility. Could you have fitted the wrong value resistors in place of the 1Ks. I have used the ATMEGA16U on a Uno board as a USB to serial converter for configuring Bluetooth modules.

Les.
 

Thread Starter

Tesla86

Joined Oct 25, 2016
34
If you have an arduino UNO, you can take out the mega328 and use it as a USB to TTL programmer. And by pass the USB to TTL part of the circuit of your board.

If it works, something wrong with the USB to TTL circuit.

If it doesn't work, it's your mega2560 part of the circuit.

It seems to be some stuff related to USB to TTL circuit, your second option
 

Thread Starter

Tesla86

Joined Oct 25, 2016
34
you could try patching the serial signals from ATMEGA16U on the Uno to the ATMEG256 chip and see if you you can program the 256 that way. You would need to break the serial link on the 2560 board by removing the 1 K resistors. On the uno board you could just remove the ATMEGA 328P from its socket. You could also try tis the other way round. That would require removing the 1 K resistors from both boards. Talking about the 1K resistors has just made me think of another possibility. Could you have fitted the wrong value resistors in place of the 1Ks. I have used the ATMEGA16U on a Uno board as a USB to serial converter for configuring Bluetooth modules.

Les.
You're right, I can program 2560 using serial signals from another ATMEGA16U. I've removed the capacitor included in the DTR line, so I've killed the USB-to-serial part of the circuit in my board.

I've double checked 1K values of TX and RX resistors and they have the proper value, but It was a good point.

Thank you very much for your help!
 
Top