ATMEGA1284p uploading not working with MCP2221A

Hello. I have an ATMEGA1284p hooked up to a MCP2221 with UART/USART. However, when trying to upload some code I get the following errors:

avrdude warning: attempt 1 of 10: not in sync
avrdude warning: attempt 2 of 10: not in sync
avrdude warning: attempt 3 of 10: not in sync
avrdude warning: attempt 4 of 10: not in sync
avrdude warning: attempt 5 of 10: not in sync
avrdude warning: attempt 6 of 10: not in sync
avrdude warning: attempt 7 of 10: not in sync
avrdude warning: attempt 8 of 10: not in sync
avrdude warning: attempt 9 of 10: not in sync
avrdude warning: attempt 10 of 10: not in sync
avrdude warning: programmer is not responding; try -xstrict and/or vary -xdelay=100
avrdude error: unable to open programmer urclock on port COM1
Failed uploading: uploading error: exit status 1

I suspect this is due to the fact I might have burned a bootloader earlier with a 16MHZ clock instead of the 20MHZ clock I am using now, but re-burning the bootloader does not work either, and gives me the following error:

avrdude error: programmer is not responding
avrdude warning: attempt 10 of 10: not in sync: resp=0x00
avrdude error: unable to open programmer stk500v1 on port COM1
Failed chip erase: uploading error: exit status 1

I have tried everything I could find; changing the COM port number, restarting my PC, checking my wiring on my breadboard.

The 1284p is running on a 20MHZ clock, with the Tx and Rx pins on the MCP2221 connected to the Rx and Tx pins of USART0(RX0 and TX0). The RST pin is held high by a 1k resistor connected to +5V, the reset pin on the MCP2221 is connected in the same way. A 220nF capacitor is connected from VUSB to ground. The entire thing is powered by USB power.

I am using the MightyCore library, with a baud rate of 9600(matching the baud rate I found for the MCP2221 in Device Manager), Bootloader [Yes]-UART0. I have also tried disabling compiler LTO to no avail. Changing the crystal back to a 16MHZ does not fix the issue either, when I try that it gives me the following error:

avrdude error: cannot open port \\.\COM1: The system cannot find the file specified.


avrdude error: unable to open programmer stk500v1 on port COM1
Failed chip erase: uploading error: exit status 1

Help would be appreciated.

Hi @lemon14899.

Although it is possible that COM1 is the port of the MCP2221, on most computers COM1 is the port of the built-in UART of your computer's motherboard. The error you got is expected if you have the wrong port selected from the Tools > Port menu in Arduino IDE.

Please perform this experiment to verify that the port you have selected is your Arduino board:

  1. Disconnect the USB cable of the Arduino board from your computer.
  2. Select Tools > Port from the Arduino IDE menus.
  3. Take note of the ports, if any, listed in the menu.
  4. Close the Tools menu.
    :exclamation: The ports list is only updated when the Tools menu is re-opened, so this step is essential.
  5. Connect the Arduino board to your computer with a USB cable.
  6. Select Tools > Port from the Arduino IDE menus. - If a new port is listed in the menu, that is the port of your Arduino board.

Select that port from the menu and try uploading again.

If the upload still fails, or if no new port appeared after you plugged the Arduino board into your computer, add a reply here to let us know and we'll investigate the problem further.

I tried changing the COM port to COM5 instead of COM1, still got the same error below.

avrdude warning: attempt 1 of 10: not in sync
avrdude warning: attempt 2 of 10: not in sync
avrdude warning: attempt 3 of 10: not in sync
avrdude warning: attempt 4 of 10: not in sync
avrdude warning: attempt 5 of 10: not in sync
avrdude warning: attempt 6 of 10: not in sync
avrdude warning: attempt 7 of 10: not in sync
avrdude warning: attempt 8 of 10: not in sync
avrdude warning: attempt 9 of 10: not in sync
avrdude warning: attempt 10 of 10: not in sync
avrdude warning: programmer is not responding; try -xstrict and/or vary -xdelay=100
avrdude error: unable to open programmer urclock on port COM5
Failed uploading: uploading error: exit status 1

This output was received with an attempted upload.

Did you verify that COM5 was the port of the board by performing the procedure I provided above, or did you just select it by random?

The bootloader has to be compiled for specific MCU, clock frequency, baud rate, serial port (on MCU) etc., otherwise it will not work.

I checked it using the IDE(dropdown indicating which COM port the MCU is connected to) and the Device Manager dropdown menu labelled COM and LPT ports.

You don't mention anything about an auto-reset circuit. The ATmega1284P must be reset at the start of the upload process in order to activate the bootloader. We often use a special circuit that causes this reset to be done automatically. If you don't have one then you must manually reset the ATmega1284P at the right point during the upload sequence (after the compilation finishes).

Do you have an auto-reset circuit, as is shown in the reference schematics from the MightyCore readme (note C1):

https://github.com/MCUdude/MightyCore#minimal-setup

If not, are you manually resetting the ATmega1284P?

Have you tested your ATmega1284P separately? If you disconnect the MCP2221A from the ATmega1284P, can you upload a code to it? Please check.

Looking at the schematic, I see what you mean by an auto-reset circuit(100nF capacitor on the DTR pin of the USART). On my breadboarded circuit, this is just connected to +5V by a 1k resistor, which I think should be the source of the programming sync error. However, the MCP2221 lacks a DTR pin(unless it is the !RST pin, which is highly unlikely).

must be reset at the start of the upload process in order to activate the bootloader

Since this requires a DTR pin(which the MCP2221 does not have), and a manual reset seems somewhat cumbersome to use(you mention timing is crucial), could this be implemented in hardware instead?(i.e. with one of the GPIO pins on the MCP2221).

I have verified the 1284p does indeed work, however I used an USBasp programmer with Zadig. While I could upload code to it, the USBasp device does not enumerate as a COM port(needed for Serial Monitor), rather it enumerates as a USB device.

If you don't have an auto-reset circuit, you'll need to manually reset your Arduino during the upload. When you don't have that auto-reset, and are resetting manually, you need to get the timing right. If you do the reset too early, the bootloader will have already timed out by the time the upload starts. The tricky thing is that when you press the "Upload" button in Arduino IDE, it first compiles your sketch before starting the actual upload. So you need to wait until after the compilation finishes before doing the reset.

The way to get the timing right is to watch the black console window at the bottom of the Arduino IDE window. As soon as you see something like this:

Sketch uses 444 bytes (1%) of program storage space. Maximum is 30720 bytes.
Global variables use 9 bytes (0%) of dynamic memory, leaving 2039 bytes for local variables. Maximum is 2048 bytes.

momentarily ground the reset pin on the ATmega1284P.

The upload should now finish successfully.

It is a bit inconvenient and you do need to get the timing right, but there is a reasonably large time window during which the reset can occur so it isn't as if you have to have a reaction time in the milliseconds.

Unfortunately I don't have any experience with the MCP2221. Hopefully one of the other forum helpers will have an answer for that.

Note that if you do an upload using the USBasp (i.e., "Upload Using Programmer"), the bootloader will be erased from the ATmega1284P. If you do that, you must perform a "Burn Bootloader" operation once again before you can go back to uploading via UART.