Having Trouble to Upload a Sketch to Standalone 328P through FTDI

Hello all,

Recently I have been working on a personal project which involves designing my own PCB for standalone Arduino with MCP23017 I/O expander and MAX7219 LED drivers.

To give a quick rundown, MCU used is Atmega 328P (Atmega328P-AU), with MCP23017 I/O expander connected via I2C, and MAX7219 LED drivers connect via SPI. For USB communication, I am using FT231XS USB to Serial communcation IC.

Initially, I tested everything on a breadboard, then designed PCB afterwards. For reference, I have used SparkFun's Redboard, as they use same FTDI chip for USB to Serial Communcation.

After my PCB has arrived, I assembled all the parts, then connected Arduino UNO via ICSP pins to burn bootloader into standalone board. This worked with no issues so far. Problem came afterwards.

After burning a bootloader to Atmega328P-AU, I plugged in a USB cable to the computer and to the board, then tried to upload a sketch into the MCU. This is where I have the problem; after clicking upload;

avrdude: Version 6.3-20190619
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2014 Joerg Wunsch

         System wide configuration file is "C:\Users\CS\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17/etc/avrdude.conf"

         Using Port                    : COM13
         Using Programmer              : arduino
         Overriding Baud Rate          : 115200
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0xf1

And after 10th attempt, avrdude stops. So after searching through the forum and internet, I have tried following troubleshooting procedures to fix the issue;


Starting with general troubleshooting;

  1. Is USB cable bad? Is USB port bad?
  • I have tested different cables and different ports on my computer, and no issue was found.
  1. Which version of IDE am I using?
  • I am using latest stable version; 1.8.12
  1. Which settings am I using for uploading bootloader?
  • I am using Arduino UNO as board, and programmer is "Arduino as ISP"

Moving onto FTDI chip;

  1. Does FT231XS properly recognized by the computer?
  • Yes, I am using x64 Windows 10, after installing the driver, computer shows my FT231XS chip as COM13.
  1. Does FT231XS having issue with RX and TX?
  • No, I have tested this using loopback method by connecting RX and TX of FT231XS pins, opened the serial terminal, then sending a string to see if there was any loss.
  1. Are there any short circuit on the board?
  • No, after soldering the parts onto the board, I have checked for any short circuits or overlapping solder joints.

Then moving onto Atmega328P-AU;

  1. Is MCU isolated when chip is being programmed? (By programmed, meaning burning the bootloader or uploading a sketch via programmer)
  • Yes, although all the chips are soldered into one board, other components, such as MX7219 or MCP23017 are powered on a separate rail. So during programming, MCU is powered only by Programmer Arduino Uno.
    I also have small circuit to select bootloading mode to prevent any communication between Atmega328P and FT321XS(Shown below).
  1. Was there any issue during burning bootloader?
  1. Have I tried changing fuse settings from the board.txt?
  • Yes, I first burning the 0xFF 0xDE 0xFD, and it worked, but could not upload a sketch through FT231XS.
    Then I used 0xFF 0xDE 0x05, and it worked, but could not upload a sketch through FT231XS.
  1. Can I upload sketch with "Upload Using Programmer"?
  • Yes, and I also confirmed uploaded sketch works by checking on my 7-segment display soldered onto the board.
  1. Is RX and TX pins connected to TX and RX pins of FT231XS?
  • Yes, as shown in the schematic below, I have connected TX of Atmega328P to RX of FT231XS, and RX of Atmega238P to TX of FT231XS.

    Here is pin connection on Atmega328P side.
  1. Is there a RC circuit on RESET pin?
  • Yes, 0.1uF ceramic capacitor in series to DTR pin and 10k resistor to pull RESET pin high.
  1. Does Atmega238P quickly pulses RESET pin when uploading starts?
  • Yes, this was confirmed by looking at the 7-segment display quickly flashing and going back to initial loop.
    This also confirmes that DTR pin on FT231XS drives RESET pin low quickly.
  1. What happens when IDE starts uploading sequence?
  • RX indicator on FT231XS flashes 3 times initially, then each time when communication fails, RX indicator flashes once.

So here I am, with a board that works with ICSP but no USB connection.

My last troubleshooting would be my Atmega328P-AU MCU damaged internally, and cannot use PD0 and PD1, so I am about to desolder the old Atmega328P and re-solder new Atmega328P-AU.

BUT, before I do that, I'd like to know if there is ANY other troubleshooting I can do before I confirm current MCU being bad.

So to sum up my question...

  1. Is there any issue with my current setup?
  2. Is there any other troubleshooting I can do without physically damaging the board(that is, cutting the copper trace off)?

Thanks in advance guys, sorry for the long post. If you need any more information regarding my schematics, let me know.

Doesn’t Q1 need a pull down resistor?

6v6gt:
Doesn’t Q1 need a pull down resistor?

Well, so far I had no issue with Q1 not having a pull-down resistor, but if suggested, I can add one to it.

Q1 is a P Channel Trench MOSFET, which simply disconnects power coming from USB going to MCU if ICSP power is used for programming.

On which pin on PMV48XP are you referring to add a pull-down resistor?

In principle, the gate should not be floating. I'm assuming that on J8 you are bridging either pins 1 and 2 or 2 and 3 depending on whether the programmer is connected or not. Or what do you connect to J8 ?

The intention is to stop the be USB supply being back fed by the powers supply uC_PWR ? Clearly the mosfet body diode will allow current to flow from the USB (VBUS) to uC_PWR.

Can you attach the full schematic, say as a PDF. Maybe it will be clearer then.

6v6gt:
In principle, the gate should not be floating. I'm assuming that on J8 you are bridging either pins 1 and 2 or 2 and 3 depending on whether the programmer is connected or not. Or what do you connect to J8 ?

The intention is to stop the be USB supply being back fed by the powers supply uC_PWR ? Clearly the mosfet body diode will allow current to flow from the USB (VBUS) to uC_PWR.

Can you attach the full schematic, say as a PDF. Maybe it will be clearer then.

Yes, J8 is a 1x3 0.1" male header pins. I have a 2-pin jumper(shunt) to switch between 1-2 or 2-3.
(Now looking at it, I should have connected that D3 to pin 3 to indicate programmer is plugged in)

So when I connect pin 2 and 3 on J8, Q1(which is a P-Channel MOSFET) will block any power coming from USB to MCU, making it completely isolated from other power source except programmer (in this case, an Arduino Uno R3).

Attached PDF file is the full schematic, first three pages (page 2~4) are the ones you can look at.

Flight_Controller.pdf (297 KB)

OK. When you are attempting to load a sketch using the bootloader (i.e. not via the ICSP header), are you doing it via the USB port on your device, connected with a cable to your PC and without anything connected to the ICSP header and no power to the uC power supply ? That is, the only power source is the PC's USB port.

If so, Q1 has to be in the on state. Try putting jumper lead between J8 pin 3 (i.e. the gate of Q1) and ground (best via a 10K resistor) to see if you can then load a sketch to the device. Leave pins 1 and 2 of J8 unconnected.

Don't make any changes to the LED D3 at the moment.

6v6gt:
OK. When you are attempting to load a sketch using the bootloader (i.e. not via the ICSP header), are you doing it via the USB port on your device, connected with a cable to your PC and without anything connected to the ICSP header and no power to the uC power supply ? That is, the only power source is the PC's USB port.

Thanks for the suggestion, 6v6gt.

Yes, after burning the bootloader, I disconnect ICSP cables before I connect the USB to my board.

Can't find any spare 10k resistor around so I used 100k resistor.

But just like last time, RX LED on FT231XS blinks three times initially then blinks once per each attempt. (This was done after I burned bootloader prior to uploading sketch, making sure I have clean setup)

Now I'm suspecting maybe I have messed up on Q1's pinout; perheps I should have swap VBUS and uC_PWR? KiCAD library had different options for MOSFET pinouts (GDS, GSD, SDG, etc.)

Here is my current setup as suggested;

So I may have located the issue, and I think its on the schematics.

I have RX and TX pin of Atmega328P broken out to male header pins, so I wrote a quick Serial communication test sketch and uploaded to the Atmega328P using a programmer.

Then I connected my standalone board to an Arduino Mega, which will relay any message coming from my board to send it over to COM port via hardware Serial.

All connected, and I see my Atmega328P sending set of strings over the UART pins. This confirms that my Atmega328P has working UART pins.

Now, looking at the schematics, I see I have my PD0 labelled as UART_TX and PD1 as UART_RX.
Looking at the Atmega328P datasheet, PD0 should have been RX and PD1 as TX, which I may have connected FT231XS's RX to RX, and TX to TX of Atmega328P.

I will have to re-design the board and send it back to fab. Hopefully this will have some significant change.

Good that you have found that error.
Can you test that with track cutting and fine soldering?
Using the ICSP header to upload the boot loader is a one-off activity so I’m not sure that a circuit to prevent possible conflict between the usb and icsp pin 2 power sources is justified. If you do retain something though, then just a jumper. Another alternative is simply to omit the 5v power wire from the programmer to icsp header during this programming and power the circuit through one of the other two sources (usb or what you have called uC)

6v6gt:
Good that you have found that error.
Can you test that with track cutting and fine soldering?
Using the ICSP header to upload the boot loader is a one-off activity so I’m not sure that a circuit to prevent possible conflict between the usb and icsp pin 2 power sources is justified. If you do retain something though, then just a jumper. Another alternative is simply to omit the 5v power wire from the programmer to icsp header during this programming and power the circuit through one of the other two sources (usb or what you have called uC)

I will try my best to cut the trace and solder wire around, perhaps I'll cut trace off between FTDI and Atmega and solder single copper wire. Gonna be difficult though, since those traces are really, really tiny in my eyes!

And I agree, I may have overdone on the programming mode now that I look at it.

In my head originally, I was worried about burning bootloader with both ICSP power and USB power in, it may cause issue with possible data leakage through FTDI. But now to think of it, since I'll be burning bootloader only one time (unless I have to re-burn the bootloader for other reasons), it would have been a common sense to just follow the proper procedure to burn the bootloader, that is, unplug USB, and plug in the ICSP pins.

Well for the time being, guess I'll go back to my workstation and debug the wiring.

Thanks for the help, 6v6gt. I'll post my result as soon as I get it work.

...And I just cut UART traces and soldered copper wires, and confirmed, indeed, it WAS my mistake to connect PD0 (RX pin of Atmega328P) to RX pin of FT231XS and PD1 (TX pin of Atmega328P) to TX pin of FT231XS!

Well this has been the most expensive mistake I have made, fact that I had to send new design to a fab.

Many thanks to 6v6gt for helping out, also thank you for giving me insight on my bootload mode selector. I will either remove/simplify the circuit for later design.

I pay 5$ for 5 boards with A_L_L_P_C_B .com , up to 10cm x 10 cm, but delivery can around 20$ so I tend to send in a few orders at once.

With chips I know, I don't even normally breadboard a design. I assume I am going to have to makes some hacks to the boards, so I usually design in jumpers to isolate parts of the circuit, and break out pins that could be useful.

Are you using a firm which also mounts the components on the board ?

6v6gt:
I pay 5$ for 5 boards with A_L_L_P_C_B .com , up to 10cm x 10 cm, but delivery can around 20$ so I tend to send in a few orders at once.

With chips I know, I don't even normally breadboard a design. I assume I am going to have to makes some hacks to the boards, so I usually design in jumpers to isolate parts of the circuit, and break out pins that could be useful.

Are you using a firm which also mounts the components on the board ?

No, I only have boards made from JLCPCB. They do have offer 4$ for 5 boards up to 10cm x 10cm as well, but since I'm making a control panel for flight simulator, my board design ended up 460mm x 112mm, which I paid about $40.

So I ended up splitting the control part and input part for later design, so I can at least have controller part made at cheaper price.