I'm currently trying to make a board featuring a Mega2560, however due to very strict size requirements, I don't want to include the 16u2 and USB for ease of programming or I also don't want to include a ISP header and use the upload via programmer option in the IDE.
My thinking was I could basically just separate the two pages of the official 2560 found here into two separate circuit boards. I see that they are really only connected to each other via PE0 and PE1. This leads me to the following assumptions:
The DFU that is loaded on the 16/8u2 shows up on the computer's com ports as a "Arduino Mega 2560"
Arduino chips 2560 & 328 are able to be programmed via their RX0 and TX0 pins.
I don't actually have a 16u2 but I do have a lot of 32u4s proto boards laying around. So far I've been able to flash them with this 32u4 DFU firmware, or so they claim, but none of them work. I'm ordering a 16u2 and a 8u2 to try this method.
So how exactly does the 16u2 program the Mega2560? Think about it from a new design standpoint, I'm going to order a 16u2 and a 2560 from Digikey. What exactly needs to be done? (They will both be put on boards with all the supporting hardware). Do I just load the DFU onto the 16u2, and upon plugging it into the USB it'll show up as a Arduino Mega 2560? Then do I just connect RX1 and TX1 from the 16u2 to TX0 and RX0 on the Mega, and it'll just work? Or does the Mega2560 need the mega bootloader installed on it prior to it being able to be programed via RX/TX?
If someone could explain this process to me in a little bit more detail it would be greatly appreciated!
P.S. Does anyone know if they have a bootloader/DFU/code to put on the 32u4 to have it program another chip via RX/TX just like the 16u2?
The FTDI chip, or the 16U2 programmed to act as one, translates/buffers the USB high speed serial data into 0/5V levels at slower speeds to talk to a Bootloaded 2560 for programming.
The 2560 must be bootloaded first tho.
If you don't want a bootloader, then you need the ICSP connections to upload code using a Programmer.
While my space requirements are very tiny, it's not so much that it's more I'd like to learn how this all works. I'm tired of the base level of knowledge and it's time I learned more.
CrossRoads:
The FTDI chip, or the 16U2 programmed to act as one, translates/buffers the USB high speed serial data into 0/5V levels at slower speeds to talk to a Bootloaded 2560 for programming.
Interesting, so what you are saying is that the DFU that gets loaded onto the 16u2 accomplishes the same thing as an FTDI chip? Neat! So I'm sure I should be able to find something similar to that for a 32u4.
CrossRoads:
The 2560 must be bootloaded first tho.
So basically I need the Arduino bootloader on there before I can even program with an FTDI like device. That means if I get these boards made with the chip on them and no ISP connections then I will need to get the bootloaders pre-loaded from Digikey.
The 16u2 is programmed to act as a usb serial adapter. Nothing more (though additional functionality could be added with different firmware on the 16u2). That's how many "clones" with a ch340g (a very cheap Chinese serial adapter chip) can exist. It's RX and TX are connected to atmega2560's TX and RX, and its DTR is capacitively coupled to the reset pin to reset the chip when DTR goes low as serial port is opened, allowing the bootloader on the 2560 to run to upload the sketch.
Imo, always make it possible to use the ISP pins on the board, especially for prototypes. Whenever I have omitted them, I've always regretted it. They dont even need to be through holes (or have a connector on them) - I usually bootload chips using pogo pin adapter.
Arduino chips 2560 & 328 are able to be programmed via their RX0 and TX0 pins.
This is only a consequence of having a bootloader already programmed into the 2560 or 328. "Burning" the bootloader requires access to MOSI, MISO, SCK, RESET, and GND. You could theoretically get by with a programming connector smaller than the 6pin ISP connector, or just bare pads on your board and a fancy programming fixture, but somehow you're going to need to connect those pins to a programmer at some point.
As long as the RESET, SCK, MOSI and MISO pins are accessible on your PCB, then you can burn the bootloader yourself. They don't have to be in the classic 3x2 or 5x2 connector, they can be anywhere you like, and you can temporarily connect them with Dupont cables when burning the bootloader, which you only have to do once per board. After that, you can use SCK, MISO, MOSI as ordinary digital pins as needed by your project if you want. As suggested earlier, get a USBAsp for this, they are cheap and convenient.
Once the bootloader is burned, you can of course upload sketches via serial. If space is at a premium I would suggest not putting a dedicated USB-serial chip or a 16Ux on your board, just put a 6-pin header in which to plug one of these:
Warning: to trigger the Arduino to reset and accept a new sketch upload via serial, you need to connect DTR on the adaptor to the atmega's RESET pin via a 0.1uF cap. But for burning the bootloader, you need the RESET pin from the USBAsp connected directly to the atmega's RESET pin, with no capacitor. So you can't easily use the same pin/socket for both purposes.
DrAzzy:
DFU is for usb update of the code on the 16u2.
The 16u2 is programmed to act as a usb serial adapter. Nothing more (though additional functionality could be added with different firmware on the 16u2). That's how many "clones" with a ch340g (a very cheap Chinese serial adapter chip) can exist. It's RX and TX are connected to atmega2560's TX and RX, and its DTR is capacitively coupled to the reset pin to reset the chip when DTR goes low as serial port is opened, allowing the bootloader on the 2560 to run to upload the sketch.
Imo, always make it possible to use the ISP pins on the board, especially for prototypes. Whenever I have omitted them, I've always regretted it. They dont even need to be through holes (or have a connector on them) - I usually bootload chips using pogo pin adapter.
Drazzy thank you for this! This is pretty much exactly the in depth information I was looking for. Do you know where this serial adapter code exists? I'd like to load it up on my 32u4 and see if I can't make it a serial adapater.
HAv0C_RC:
I already tried those and they didn't work. The 32u4 won't show up as anything when I flash them with those.
Probably because the 16u2 and 32u4 are different parts from different series (u2 vs u4) and the code would at minimum need to be built for the selected parts - Unsure whether there are other differences between the two that would require more substantial modifications.
DrAzzy:
Probably because the 16u2 and 32u4 are different parts from different series (u2 vs u4) and the code would at minimum need to be built for the selected parts - Unsure whether there are other differences between the two that would require more substantial modifications.
I had no hopes those .hex files would work as they are for the u2 series.
You were saying they loaded something very similar onto the CH340, so there must be pre-compiled code somewhere?
I think you may have missed an important point. The first answer from CrossRoads is really what you need to read. The best bet is to use an FTDI adapter. Just buy one and use it, and concentrate your custom board design on the board that holds the ATmega2560.
You could buy a chip that is not designed to be a USB to serial adapter, and program it to be one, like Arduino did with the ATmega16U2. Nobody knows why they did that, and it is really not the best choice (my opinion). It adds complexity. The ATmega16U2 is not a USB to serial adapter chip, although you can make it be one if you like to put in extra effort. To program an ATmega2560 via a serial bootloader, you need a USB to serial adapter. A CH340G or FT232RL or other USB to serial chip that requires no programming and it just ready to go is better in my opinion. If you are making your own design, you don't need to include a suboptimal choice for the USB to serial adapter part of it.
I recommend check out this design, Pro Mini Protosnap designed by Sparkfun.
Board description:
Schematic:
It is a retired product at Sparkfun, but there are clones available. Study the design and use it as a reference. It is a board that you can plug in and just use, complete with USB to serial adapter and the main ATmega328P MCU. Then when you are ready, you can snap it apart, which breaks the connections between the FTDI section and the main MCU section. Install headers that will allow you to connect the 2 sections together again, and there you go, you have a complete working board again. After programming, you can operate the Pro Mini section without the USB to serial adapter section (unless you want to communicate via USB).
When you are ready to get a USB to serial adapter, I recommend this one that is ready to plug directly into a Pro Mini, Lilypad, or other standard Arduino with an FTDI header.
The pinout of an "FTDI Basic" board as originally designed by SparkFun is the reference design for all Arduino boards that use an FTDI adapter. SparkFun designed the original or official Arduino Pro Mini, and they intended it to be used with their FTDI Basic. Just like CrossRoads is showing on his ATmega2560 board, the male 6 pin header is on the main board, and the FTDI Basic has the 6-pin female header installed.
For anyone wondering the same questions or wanting to design their own Arduino-based PCB, here is what I've gathered from this thread subtracting all the design suggestions to interface with ISP programmers....
The Mega2560 or 328P can be programmed via serial thanks to the Arduino bootloader. Clearly however this requires the Arduino bootloader to be loaded beforehand.
Once you have the bootloader on the chip, you can program is via serial connection with a USB to serial adapter. This can either be a 16/8u2 loaded serial adapter firmware, or you can get USB to serial adapter chips like the CH340G or FT232RL that don't require programming/configuration.
There probably isn't code for a 32u4 to act as a serial adapter. It would make no sense to as there are chips that are specific for that purpose (above).
This being the most important information:
DrAzzy:
The 16u2 is programmed to act as a usb serial adapter. Nothing more (though additional functionality could be added with different firmware on the 16u2). That's how many "clones" with a ch340g (a very cheap Chinese serial adapter chip) can exist. It's RX and TX are connected to atmega2560's TX and RX, and its DTR is capacitively coupled to the reset pin to reset the chip when DTR goes low as serial port is opened, allowing the bootloader on the 2560 to run to upload the sketch.
Imo, always make it possible to use the ISP pins on the board, especially for prototypes. Whenever I have omitted them, I've always regretted it. They dont even need to be through holes (or have a connector on them) - I usually bootload chips using pogo pin adapter.