Issue Uploading: Custom PCB with ATmega328P CH340C

Hello everyone,

I’m having trouble uploading sketches to my custom PCB and I’m hoping someone here can help me troubleshoot the issue.

Background:

  • PCB Purpose: The board is designed to trigger a relay and handle dry contact inputs.
  • Microcontroller: I’m using an ATmega328P-AU.
  • Bootloader: I’ve successfully burned the Optiboot bootloader.
  • USB-to-Serial: I’m using a CH340C chip.
  • Connection: I can open the Arduino IDE and establish a connection with the board, but uploading a sketch fails.

What I’ve Tried So Far:

  • RX/TX LEDs: I removed the RX and TX LEDs as I suspected they might interfere with the serial communication.
  • Oscillator Resistor: I removed the 1MΩ resistor from the oscillator crystal.

My Questions:

  • Could there be any design issues in my schematic that might prevent sketch uploads?
  • Might the issue be related to a missing component in that area?
  • Is there any other issues that you might have fixed to get the sketch to upload?

IDE Settings:

Board: Arduino Nano
Processor: ATmega328P

Actual Processor part Number: ATMEGA328P-AU

I’ve attached images of the schematic for reference (please see below). Any insights or suggestions would be greatly appreciated!

Thanks in advance for your help.


I can not see how this relates to an Arduino Opta and hence have moved your topic to a more suitable location on the forum.

1 Like

If you push the reset button does LED1 blink a few times?
If yes that would indicate the bootloader is OK and the processor is running.

Try downloading the blink sketch via the ICSP, see if it runs.

You need an earlier version of the driver. Search this forum for CH340C

1 Like

The LED does not blink when I press the reset button :confused:

I also tried to "upload using programmer" it did not work either - would this indicate that bootloader actually failed to flash to the chip?

The bootloader doesn't upload anything but IS uploaded, the bootloader is the first code executed in the MCU.

1 Like

What Xtal (X2) is installed?

1 Like

This is from the serial monitor for the bootloader nano that I am using (I am using another nano to flash to the bootloader onto the chip)

Then the bootloader is not there or the processor is not running

I also tried to "upload using programmer" it did not work either

Then it's more that likely a crystal/resonator problem.

I am using this one:

Murata Electronics CSTNE16M0V530000R0

At this point, a photo of your board, or CAD layout, might help us help you.

Ok "No external capacitors needed" explains the lack there of. But the datasheet doesn't mention a 1 MOhm resistor.

I'm no expert in the fuses and values of those, I've mostly done bootloaders from the IDE, but you said the bootloader programming went well? Are you sure you got the values for the fuses right?

Thanks for coming back to me.

Yes - the bootloader programming went well (see attached image of a screen grab from the serial)

I am thinking if it is worthwhile swapping the RX/TX pins and giving it a go

So you are not using the standard ArduinoISP program.
Which program are you using?

I am using the following:

// optiLoader.pde

//

// this sketch allows an Arduino to program Optiboot onto any other

// Arduino-like device containing ATmega8, ATmega168, or ATmega328

// microcontroller chips.

//

// Copyright (c) 2011, 2015 by Bill Westfield ("WestfW")

//-------------------------------------------------------------------------------------

// "MIT Open Source Software License":

// Permission is hereby granted, free of charge, to any person obtaining a copy of

// this software and associated documentation files (the "Software"), to deal in the

// Software without restriction, including without limitation the rights to use, copy,

// modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,

// and to permit persons to whom the Software is furnished to do so, subject to

// the following conditions:

//

// The above copyright notice and this permission notice shall be included in all

// copies or substantial portions of the Software.

//

// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR

// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS

// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR

// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER

// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION

// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

//-------------------------------------------------------------------------------------

//

// this sketch allows an Arduino to program Optiboot onto any other

// Arduino-like device containing ATmega8, ATmega168, or ATmega328

// microcontroller chips.

//

// It is based on AVRISP

//

// Designed to connect to a generic programming cable,

// using the following pins:

// 10: slave reset

// 11: MOSI

// 12: MISO

// 13: SCK

// 9: Power to external chip.

// This is a little questionable, since the power it is legal to draw

// from a AVR pin is pretty close to the power consumption of an AVR

// chip being programmed. But it permits the target to be entirely

// powered down for safe reconnection of the programmer to additional

// targets, and it seems to work for most Arduinos. If the target board

// contains additional circuitry and is expected to draw more than 40mA,

// connect the target power to a stronger source of +5V. Do not use pin

// 9 to power more complex Arduino boards that draw more than 40mA, such

// as the Arduino Uno Ethernet !

//

// If the aim is to reprogram the bootloader in one Arduino using another

// Arudino as the programmer, you can just use jumpers between the connectors

// on the Arduino board. In this case, connect:

// Pin 13 to Pin 13

// Pin 12 to Pin 12

// Pin 11 to Pin 11

// Pin 10 (of "programmer") to RESET (of "target" (on the "power" connector))

// +5V to +5V and GND to GND. Only the "programmer" board should be powered

// by USB or external power.

//

// ----------------------------------------------------------------------

// The following credits are from AVRISP. It turns out that there isn't

// a lot of AVRISP left in this sketch, but probably if AVRISP had never

// existed, this sketch would not have been written.

//

// October 2009 by David A. Mellis

// - Added support for the read signature command

//

// February 2009 by Randall Bohn

// - Added support for writing to EEPROM (what took so long?)

// Windows users should consider WinAVR's avrdude instead of the

// avrdude included with Arduino software.

//

// January 2008 by Randall Bohn

// - Thanks to Amplificar for helping me with the STK500 protocol

// - The AVRISP/STK500 (mk I) protocol is used in the arduino bootloader

// - The SPI functions herein were developed for the AVR910_ARD programmer

// - More information at http://code.google.com/p/mega-isp

Maybe not since you are not using the standard ArduinoISP program.

So it went well that it was programmed, but did it went well when it comes to having the right fuses? Uploading a bootloader is one thing, upload it with the right fuses is another thing.

I'm leaning towards Jim-P now...

That's some old script.

Download MegaTinyCore instead, that takes care of all that guesswork.

I've never used that program
Are you sure it actually works?
The ArduinoISP in the IDE examples has been proven to work by many.
Why don't you try it first before you start hacking your PCB.

Yes I use them for loading the flashing new boot loaders to my other nanos and it works - I do this because then the watchdog works and doesn't go into a freeze state (as it does with the older boot loader)

I will give it a go and see how that goes - do you have any links that have been best for you?