Atmega32u4 Based Project - Serial Connection Issues

Hello all,

Short version: Custom atmega32u4 board has intermittent issues with connecting via serial after a day of working properly with multiple sketch uploads. Issue persists regardless of sketch onboard.

Long version: I have an Atmega32u4 based board that I designed to function as a Joystick. I had the board produced and SMT assembled (PTH components were not assembled - rotary switches, push button switches, and connectors) and I received them a few days ago, at which point I began testing them.

For testing, I uploaded a number of different small sketches to test each of the functions of the board individually before I develop the complete sketch for the project. This included things like: reading shift registers and interpreting them as button presses via Joystick library (GitHub - MHeironimus/ArduinoJoystickLibrary: An Arduino library that adds one or more joysticks to the list of HID devices an Arduino Leonardo or Arduino Micro can support.), doing analog readings of the voltage at the resistor ladder circuits, and testing the LEDs and their communication with a program called SimHub (https://www.simhubdash.com/). This testing was happening off and on over the course of a day.

Everything was going great until the board began having trouble connecting via serial. At first it was disconnecting and reconnecting randomly and eventually got to the point where it wouldn't connect at all. I tried a tons of things to get it back working over the course of another day and a half and eventually got a basic sketch uploaded by holding RESET, starting the sketch upload via USBasp programmer (AVRISP mkII did not work with the same procedure), and then releasing RESET when the compile finished.

At this point I thought all was well and I left it alone for a little bit. Then I came back to it tonight, uploaded the latest version of my project sketch (combining those elements mentioned before) and the connection issues returned. I followed the same procedure to get a basic sketch back on it and it was successful, only now the board with that basic sketch is exhibiting the same connection issues.

So now I am convinced that I either damaged the board during testing or there is an inherent hardware issue that is causing the problem.

Also, I tested my latest project code on a Pro Micro with an 8 LED WS2812B strip and it both appeared as a Joystick and the LEDs worked appropriately with SimHub (bare in mind the other components that the code reference were not connected). So between that and the fact that the issue is persisting regardless of what sketch is uploaded, I am pretty confident my code is not the issue.

Can anyone offer some advise on what may be happening here? I have 4 more of these boards available to me, but I am scared to start messing with them before I know if I killed it or if it is actually a hardware problem. At the end of the day, I need at least 2 fully functioning boards as I am building one for myself and one for my brother - and of course backups would be nice.

I have attached the schematic for the board as well as some other images of the layout/routing. A couple things to note:

  1. The board has a 5V input which comes from an external power supply. This is for powering the LEDs only. The microcontroller as well as the other components are all powered via 5V from USB instead.
  2. The board is 4 layers with the internal layers being GND and 5V from the external supply (not USB 5V - USB 5V and external 5V are not connected).
  3. There are actually two boards attached. One has the microcontroller and a number of other components. The other is just a breakout with additional components, but no controller. They were split this way to aid assembly of the Joystick. Much of the debugging since the issue started has been done without the breakout attached and without 5V external power supply connected. I did verify that the breakout worked prior to the issues starting though.
  4. There is an SL2.1 USB hub onboard the mainboard. I have tried bypassing this to see if it is interfering and the microcontroller behaves the same as through the hub. I have also demonstrated that the hub works via a separate port with a different USB device.

One last thing, the board says, "Marsh Motorsport" on it. This is not a real company. This is the made up name I put on my DIY sim racing projects for fun. I am in no way planning to sell this or develop it as I consumer product. Just wanted to mention that in case someone feels weird about helping me because of it.

Any help would be greatly appreciated.

UPDATE 1: added schematic images to the main post for better visibility.

breakout.pdf (560.9 KB)
mainboard.pdf (665.6 KB)






If it’s intermittent, posting your code in code tags would be a helpful start.

The schematic might be necessary too, but most likely a code issue.

This issue is happening regardless of what code is uploaded to the board. Right now it has a sketch onboard that serial prints “Hello World” and nothing else with the problem persisting. So I am fairly confident the code is not a problem.

I can try to post the project code if you all think it’s necessary though… I’m hesitant because it’s a mess and has a bunch of things from the simhub base sketch that I’m not even using, so I think it’s going to cause unnecessary confusion.

That’s a good start.
If you’ve got some tiny code that shows the problem - let us see that.

Same for the circuit - esp around the tx/rx pins and power supply.

Do you have lots of decoupling/bypass capacitors around the active parts of the circuits?

I added images of the schematics to the original post. Also, the pdf files in the original post show the layout of each copper layer. Please take a look regarding the decoupling capacitors.

Here is the simple Hello World code that is currently onboard the device while it is having the connection issues.

void setup() {
  // put your setup code here, to run once:
    Serial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:
  Serial.println("Hello World");
}

you didn’t mention the 2+1 port USB hub on the board,
Is there a way you can discount that from interfering in the problem ?

Yes, good point. Earlier during my troubleshooting, I bypassed the hub by connecting D-/D+ from the microcontroller directly and there was no change. Also, I have connected a USB Vocore screen to the other input on the hub and that worked as well. It seems isolated to the controller.

Quick update: Last night the board had gone back to being totally unable to communicate over serial with the Hello World sketch onboard. I came back to it tonight, followed the procedure mentioned in the original post to get a new sketch uploaded (Hello World again), and it appeared to be working correctly - it was outputting "Hello World" to the serial monitor as expected.

I was suspicious that it was going to fail at some point, so I turned on a timer and sure enough, 3 minutes and 15 seconds later it first disconnected and then started connecting and disconnecting randomly.

I'm at a loss. Does anyone have any ideas or things I could try to troubleshoot?

A few more things that I've tried:

  1. Switched from IDE 1.8.16 to 2.0.1, reuploaded the ArduinoISP sketch to my Uno (programmer), burned the bootloader on the custom board, and reuploaded the HelloWorld sketch - worked initially and then COM dropped about 15 seconds later, then started connecting and disconnecting randomly (same as before).
  2. Tried both the Micro and the Leonardo bootloaders - same as before
  3. Tried connecting the USB to the custom board via a powered hub - same as before
  4. Made a new USB cable with the USB JST connector properly soldered in place - same as before
  5. Cleaned the board thoroughly with isopropyl and a toothbrush - same as before
  6. Bypassed the onboard USB hub and connected directly to the 32u4 - same as before

Any other ideas?

Another update: I finally broke down and got a new board out to test. I soldered the bare minimum PTH components needed, then burned the bootloader, and uploaded the HelloWorld sketch. It’s been running for 20 minutes so far with no issues.

So I am guessing something I did previously killed the board, but I have no idea what that might be.

If anyone has any suggestions for things to try to revive the old board, I’d be interested in trying them.

One thought that occurred to me is that the larger JST connector (5V ext in) near the USB in took a while to solder (longer heat exposure), and that connector is quite close to the fuse for the USB in. Maybe the fuse is damaged and causing the random drop outs? I don’t know, I’m grasping at straws here.

Any guidance or advice would be appreciated.