Arduino mega2560 atmega2560

hii all , there is something that i don't understand

i want to buy the

ARDUINO MEGA2560 ATMEGA2560 , and i want to load a firmware to the ATMEGA2560 at the board using the arduino ide how can i do that?? , cause from the board schematic i can see that the usb connector is connected to ATMEGA16U2-MU on the board and not to ATMEGA2560 .

i am a little confused and i am newbee to arduino i be glad for help

you select Arduino Mega as the target board, you select the right Serial port and you click the upload button.

let the ATMEGA16U2 deal with getting the data to the µC

The ATmega2560 isn't able to communicate over USB directly. It needs the help of the 16u2.

Your topic has been moved to a more suitable location on the forum. Introductory Tutorials is not for questions but for tutorials that are written.

hii

thanks for your help , so from what i understand the ATMEGA16U2-MU loads the ATmega2560 serially?? i see in the board schematic that the connection between the ATmega2560 and ATMEGA16U2 is through serial port .so the job of the ATMEGA16U2 is to load the firmware serially to ATmega2560 ??

Yes, but the ATmega2560 writes the sketch to its own Flash memory (the bootloader does that).

The ATmega16U2 has firmware to present itself to the computer as a serial port over USB.
The ATmega2560 has a bootloader, and the computer can communicate with the bootloader (with the ATmega16U2 in the middle).

When you upload a sketch, the sketch is written in the Flash memory of the ATmega2560, next to the bootloader. The actual writing to Flash memory is done by the bootloader.

If you do a Serial.println() to the Serial Monitor on the computer, then the TX pin is used, via the ATmega16U2 and to the computer.

Now you also know that you should not use pin 0 and 1, because those are the RX and TX pins that are used to get the sketch in the ATmega2560.

hii
thanks for your reply , now i understand how it works , but i have one more question :slight_smile:

lets say i am developing my own custom board using ATMEGA16U2 and ATmega2560 and my board will be exactly like the atmega2560 dev board with additional peripherals, where i can get the firmware to ATmega16U2 and the bootloader for ATmega2560 in order to sketch the ATmega2560 ??

or is it a default firmware's supplied with the chips once i buy them.
i just connect the chips according to the ATmega2560 schematic and i suppose to see my custom board in arduino IDE ?

No, you need to program the firmware using a programmer.

The needed files are on your PC; I currently can't check where; look for files with the extension hex.

hardware/arduino/avr/firmwares/atmegaxxu2/Arduino-COMBINED-dfu-usbserial-atmega16u2-Mega2560-Rev3.hex

packages/arduino/hardware/avr/1.8.6/bootloaders/stk500v2/Mega2560-prod-firmware-2011-06-29.hex
or maybe
packages/arduino/hardware/avr/1.8.6/bootloaders/stk500v2/stk500boot_v2_mega2560.hex

hii
thanks :slight_smile:

as i understand those are files that located in the arduino installation folder ?

The first one is. The other two are in the "packages" directory where the IDE saves downloaded content, like newer versions of the AVR support.

hii thanks for help

lets say i located the firmware that i need to download to the ATmega16U2 in order to be able to program the ATmega2560 like in the Arduino mega board

and my question is how can i program the ATmega16U2 with this firmware

If the firmware currently loaded includes DFU (Direct Firmware Update) mode you should be able to use the Atmel FLIP program to upload new firmware. Here are instructions:

If the DFU firmware has been overwritten you will need to use an In-System Programmer (ISP) like the USBasp or USBtinyISP to burn fresh firmware. On my Mac the firmware you want appears to be this file: /Applications/Arduino.app/Contents/Java/hardware/arduino/avr/firmwares/atmegaxxu2/Arduino-COMBINED-dfu-usbserial-atmega16u2-Uno-Rev3.hex

The commands on my Mac would be something like:

cd /Applications/Arduino.app/Contents/Java/hardware

tools/avr/bin/avrdude -C tools/avr/etc/avrdude.conf  -p at90usb162 -P usb -c usbtiny -v -F -e -u -U efuse:w:0xF4:m -U hfuse:w:0xDF:m -U lfuse:w:0xFF:m -U flash:w:arduino/avr/firmwares/atmegaxxu2/Arduino-COMBINED-dfu-usbserial-atmega16u2-Uno-Rev3.hex -U lock:w:0x2b:m

hii thanks for help :slight_smile:

i have a windows pc , is there any application for windows that i can use with USBtinyISP to program the atmega16u2 ??

avrdude? It's installed when you install the IDE.

It's the same command. You just have to find the 'hardware' directory on your machine and use that in the 'cd' (change directory) command.

thanks i will try it out :slight_smile: thanks for help

‫בתאריך יום ה׳, 2 בפבר׳ 2023 ב-0:41 מאת ‪johnwasser via Arduino Forum‬‏ <‪notifications@arduino.discoursemail.com‬‏>:‬

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.