[Solved] [AT32U4] Custom board design - trouble with USB

Hello all,

First of all let me preface by saying that this community has helped me tremendously by reading through old threads of other users, testimony being that I never needed to post until now!

I decided to take my Arduino journey a step further and design a custom PCB rocking the ATmega32U4 in order to learn PCB design and have a perfect little board for a personal project.

The context
I want to build a custom temperature and humidity data logger with SDcard, RTC and battery power. I thought it would be nice to make a custom board with all those ICs on there, running 3.3V as to not damage any SDcard.
Since I did want to avoid adding a USB to TTL component, I chose the ATmega32U4, also because I could help myself to the nice schematic of the SparkFun Qwiic Pro Micro - USB-C.

The board
In order to keep cost down, I tried to use through-hole components wherever possible or convenient.
I designed a two-layer PCB in EasyEDA and got it made and partially assembled by JLCPCB.
Please note this is only my second PCB design and the first was very basic, so it was definitely a challenge.
I already know that some things are bad: type and placement of decoupling capacitors, placement and rounting of the crystal, trace width, routing could be much improved in general. I already designed a better version using more SMD components and 4-layers which I'm proud of, but I want to use this bad PCB first if I can since I spent some money on it.

You can see the layout attached to this message (with the nets displayed on each trace/pad). Ground planes are hidden. Also attached is the schematic.

The components
Main items of the BOM and their part numbers at LCSC.com:

  • uC: ATMEGA32U4-MUR (C45874)
  • Temperature and humidity sensor: Texas Instruments HDC1080DMBR (C82227)
  • 3.3V regulator: Diodes Incorporated AP2112K-3.3TRG1 (C51118)
  • Amplifier for LED decoupling (not used yet): Texas Instruments LMV358IDGKR (C105242)
  • RTC (not used yet): HGSEMI DS1307N (C434596)
  • USB-C connector: XUNPU TYPEC-304S-ACP16 (C720630)
  • 16MHz crystal: Yangxing Tech X49SD16MSD2SC (C16212)
  • RTC crystal: TAE TDXLF-206 32.768KHZ (C145163)

The flashing
Please note that, although I want to use the board on 3.3V in the end, all components support 5V except any SDcard.
After assembling the main parts of the circuit (no LEDs, no OPAMP, no RTC, not RTC crystal, no battery holder and diode) I programmed an Arduino UNO with the ArduinoISP sketch, hooked up the ISP header of my board to the relevant pins on the Uno and flashed the Sparkfun Pro Micro (5V/16MHz) bootloader which succeeded (see logs, abbreviated, below):

avrdude: Version 6.3-20190619
[...]
Using Port                    : /dev/cu.usbmodem143101
Using Programmer              : stk500v1
Overriding Baud Rate          : 19200
Reading [...] 100% 0.01s
avrdude: verifying ...
avrdude: 1 bytes of lock verified
avrdude: reading input file "0xCB"
avrdude: writing efuse (1 bytes):
Writing [...] 100% 0.01s
avrdude: 1 bytes of efuse written
avrdude: verifying efuse memory against 0xCB:
avrdude: load data efuse data from input file 0xCB:
avrdude: input file 0xCB contains 1 bytes
avrdude: reading on-chip efuse data:
Reading [...] 100% 0.01s
avrdude: verifying ...
avrdude: 1 bytes of efuse verified
avrdude: reading input file "0xD8"
avrdude: writing hfuse (1 bytes):
Writing [...] 100% 0.01s
avrdude: 1 bytes of hfuse written
avrdude: verifying hfuse memory against 0xD8:
avrdude: load data hfuse data from input file 0xD8:
avrdude: input file 0xD8 contains 1 bytes
avrdude: reading on-chip hfuse data:
Reading [...] 100% 0.01s
avrdude: verifying ...
avrdude: 1 bytes of hfuse verified
avrdude: reading input file "0xFF"
avrdude: writing lfuse (1 bytes):
Writing [...] 100% 0.01s
avrdude: 1 bytes of lfuse written
avrdude: verifying lfuse memory against 0xFF:
avrdude: load data lfuse data from input file 0xFF:
avrdude: input file 0xFF contains 1 bytes
avrdude: reading on-chip lfuse data:
Reading [...] 100% 0.01s
avrdude: verifying ...
avrdude: 1 bytes of lfuse verified
avrdude done.  Thank you.
AVR Part                      : ATmega32U4
Chip Erase delay              : 9000 us
PAGEL                         : PD7
BS2                           : PA0
RESET disposition             : dedicated
RETRY pulse                   : SCK
serial program mode           : yes
parallel program mode         : yes
Timeout                       : 200
StabDelay                     : 100
CmdexeDelay                   : 25
SyncLoops                     : 32
ByteDelay                     : 0
PollIndex                     : 3
PollValue                     : 0x53
Memory Detail                 :
                        Block Poll               Page                       Polled
Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
eeprom        65    20     4    0 no       1024    4      0  9000  9000 0x00 0x00
flash         65     6   128    0 yes     32768  128    256  4500  4500 0x00 0x00
lfuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
hfuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
efuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
lock           0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
calibration    0     0     0    0 no          1    0      0     0     0 0x00 0x00
signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00

Programmer Type : STK500
Description     : Atmel STK500 Version 1.x firmware
Hardware Version: 2
Firmware Version: 1.18
Topcard         : Unknown
Vtarget         : 0.0 V
Varef           : 0.0 V
Oscillator      : Off
SCK period      : 0.1 us
avrdude: AVR device initialized and ready to accept instructions
Reading [...] 100% 0.03s
avrdude: Device signature = 0x1e9587 (probably m32u4)
avrdude: NOTE: "flash" memory has been specified, an erase cycle will be performed
         To disable this feature, specify the -D option.
avrdude: erasing chip
avrdude: reading input file "...Arduino15/packages/SparkFun/hardware/avr/1.1.13/bootloaders/caterina/Caterina-promicro16.hex"
avrdude: writing flash (32762 bytes):
Writing [...] 100% 0.00s
avrdude: 32762 bytes of flash written
avrdude: verifying flash memory against ...Arduino15/packages/SparkFun/hardware/avr/1.1.13/bootloaders/caterina/Caterina-promicro16.hex:
avrdude: load data flash data from input file ...Arduino15/packages/SparkFun/hardware/avr/1.1.13/bootloaders/caterina/Caterina-promicro16.hex:
avrdude: input file ...Arduino15/packages/SparkFun/hardware/avr/1.1.13/bootloaders/caterina/Caterina-promicro16.hex contains 32762 bytes
avrdude: reading on-chip flash data:
Reading [...] 100% 0.00s
avrdude: verifying ...
avrdude: 32762 bytes of flash verified
avrdude: reading input file "0x2F"
avrdude: writing lock (1 bytes):
Writing [...] 100% 0.02s
avrdude: 1 bytes of lock written
avrdude: verifying lock memory against 0x2F:
avrdude: load data lock data from input file 0x2F:
avrdude: input file 0x2F contains 1 bytes
avrdude: reading on-chip lock data:
Reading [...] 100% 0.01s
avrdude: verifying ...
avrdude: 1 bytes of lock verified
avrdude done.  Thank you.

USB connection

Now here's my problem. When I connect the device with the USB-C port to either my MacBook Pro or my Windows desktop computer, the device is not recognized. On macOS, I just don't see the COM port listed. On Windows, the OS warns me that the "USB device is not recognized" and is malfunctioning.

I initially put my finger on the crystal because avrdude reports it "OFF", so I checked it with my cheap BitScope and, although the sampling rate is not high enough by the looks of it, it has a periodicity of 4MHz which could just be what I see with my sampling rate, the real rate being 16MHz supposedly (I captured every 4th point in the signal I think).

Also, since I was able to flash the bootloader, I think it would indicate that the crystal is working as intended.

I would love some help to troubleshoot this, as I really don't have enough experience to do it on my own.

THANKS! :slight_smile:

Here's a picture of the assembled board. Please also note I tried the Arduino Leonardo bootloader but the result was the same.

That is a lot of work, nice job. Try this link: How to Fix USB Device Not Recognized in Windows . I use a Linux computer and normally do not have problems like you are mentioning. You can get a copy of Linux Mint Cinnamon 20.1 for the downloading. You can boot it from a USB stick and run it, you do not have to install it. It can also be installed along with windows and will ask what system at boot and if you do not respond it will boot Linux. A bit of caution Linux can read window files but windows cannot read Linux files. When I ran both I just keep my stuff in the windows folders and all went fine.

Awesome project!

USB data line series resistance (R2, R3) is too high...
5.1K ohm is placed, but it should be between 22 to 47 ohm.
Also, ATmega32U4 is not guaranteed to operate at 16MHz at 3.3V VCC.
It works with a good at many case, but it can cause unexpected glitches.
Well, Pro Micro also operates at 16MHz is only at 5V version, and 3.3V version at 8MHz only.

Please check attached the excerpt of the datasheet.

Amazing, thanks for the help chrisknightley and gilschultz.
I now have a plan of attack:

  • switch the data lines resistors to 22-47R (shouldn't have blindly followed the sparkfun schematic)
  • if that doesn't solve it, source a 8MHz crystal and corresponding caps (note the sparkfun USB-C model has a jumper to switch from 5V to 3.3V and only has a 16MHz crystal)
  • if that fails, check what linux has to say about it.

Will report when I have tried some of these :slight_smile:

krizzli:
(note the sparkfun USB-C model has a jumper to switch from 5V to 3.3V and only has a 16MHz crystal)

Of course! You have the right to "run 32U4 at 8MHz using internal oscillator".
In that case, 16MHz crystal is useless component. It's wasted... :stuck_out_tongue:
Well...!
In addition, an 8MHz system clock can be obtained from a 16MHz crystal using a prescaler.
Yes! The crystal is still alive! :wink:

chrisknightley:
You have the right to "run 32U4 at 8MHz using internal oscillator"

Ah that's very interesting! I did not understand the datasheet properly and thought I needed the ATmega32U4RC variant to have an internal oscillator. This application note however hints that you need the "RC" variant, but the datasheet has the footnote on page 422 applying to ATmega32U4-MU as well.. unclear
If I can indeed use the internal RC, that will make it easier since I don't have to order another crystal.
I'm totally fine with low speed USB as it will only be used to program the device which I should only do during development.

Dear krizzli
Sorry, I modified my post just before your post.
Because I forgot the existence of the prescaler...

Crystal was alive!

Ah no problem! Excited to try this tonight when I come home! I found some 27 Ohm resistors so I'll be able to try this. I noticed the Leonardo schematic uses 22R so probably the Sparkfun schematic is out of date or wrong.

The schematic of the new model is incorrect.
Take a look at the old SparkFun Pro Micro schematic, which is not USB type-C.
Perhaps they copied the resistor symbol of the CC terminal...

"RC" of order-code can select factory default fuse option.
The diagram of the microcontroller is the same.
The reason is that with the default configured to crystal oscillator, can't even program without an external clock.


I noticed by looking at the your circuit diagram again.
It's different from SparkFun, but I think it's better to add separate 5.1K ohm pull-down resistors to CC1 and CC2.
For more sophisticated circuits... :wink:

SUCCESS! Massive thanks to chrisknightley, you spotted the correct mistake of mine. I switched the resistors on the USB data lines and everything works as expected! I'm gonna keep an eye out from problems relating to 16MHz but for now my blink program works :smiley:

1 Like

GOOD WORK!
I'm glad to that's solved. :smiley:

I've been following this thread. Learned a few things here so thanks for the info. If you go with RC clock source, as you already know you can only do low speed. I don't know if arduino Leonardo bootloader and USB facility both support low speed. It's worth checking it out.

Happy you have noticed that sparkfun isn't always correct, neither is some free eagle designs floating around. Some are garbage. You have a good habit of checking the spec sheet. Good luck!

Thanks @liuzengqiang!

I tried to flash the 8MHz/3.3V bootloader from Sparkfun but it did not connect through USB, maybe some other changes are needed. But most of it works with 16MHz, I was able to read/write to SD card, read the temperature and humidity through I2C, control the LED with the OPAMP.

Only things left to troubleshoot:

  • RTC refuses to work even though it shares the same I2C tracks as the sensor, I'll try on the second PCB I have assembled soon (EDIT: I realized I'm dumb. The IC only work off of 5V, I'll need to step up the battery voltage and use the direct USB voltage to power it in the next version, for now I'll just solder a wire to the raw pad)
  • Coin cell battery with 3.2V voltage at rest drops to 2.9V when powered on and the sketch doesn't run properly. Maybe it's too low for the uC to be stable at 16MHz

3.3V 8MHz Pro Micro implements 8MHz crystal and operates without prescale.
To work at 8MHz with a 16MHz crystal, you need to change the bootloader settings and compile it yourself.
It may be a little difficult, it needs to be discussed on another topic if necessary.

What about the idea of using Microchip's MCP7940 for RTC?
It has exactly the same pin assignments as the DS1307 and works the same.
And! The operating voltage is 1.8V to 5.5V! :wink:
But this device does not have internal load capacitors for crystal oscillation.
Must be included on the PCB... :confused:

There is also a dedicated library.

chrisknightley:
you need to change the bootloader settings and compile it yourself.

[...]

What about the idea of using Microchip's MCP7940 for RTC?

Yet again very helpful! I will definitely try to recompile the bootloader but I could also swap the crystal and flash the default 8MHz bootloader I guess.
For the MCP7940, that's actually a perfectly suitable replacement! I'll see if I can order some.
Thanks!

krizzli:
Yet again very helpful! I will definitely try to recompile the bootloader but I could also swap the crystal and flash the default 8MHz bootloader I guess.
For the MCP7940, that's actually a perfectly suitable replacement! I'll see if I can order some.
Thanks!

Don't forget two additional capacitors from the crystal pins to GND.

I think it would be good if it could be replaced with an 8MHz crystal.
It can be easily use as a Pro Micro of 8MHz 3.3V.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.