Unable to burn bootloader on ATMega328PB

Hi!

I'm working on a project for my car which involves a OLED-display, CAN-controller and an ATMega-chip. Everything was programmed and tested on an Arduino MEGA2560, so the next step was to design a custom circuit board to fit all the components. Having done that, and received all components a couple of days ago, i assembled my first board, but can't get the microcontroller to wake up at all.

The microcontroller is a ATMega328PB (datasheet)

On the board i have connected a 16MHz crystal to XTAL1 & XTAL2 and the correct 22pF capacitors to GND:

I first got random device signatures when trying to burn bootloader, and it of course failed because of that. But maybe two-three tries and i started getting only 0x000000 as signature so the chip seemed dead to me. I then measured the crystal with an oscilloscope, and the only place where i could find a waveform signal was on the GND-side of both 22pF capacitors:

After that i soldered another ATMega328PB-chip on the board, but it constantly replies with 0xffffff.

I also have a TQFP32-programming socket/breakout board, so i mounted my last ATMega328PB-chip on it, and made the SPI-connections. I didn't have any spare 16MHz oscillators (well, i do but only SMD) so i didn't hook up any to it, yet. But it doesn't give any response either (0xffffff), although the processor should have built-in crystal?

I'm a little lost here now, because my goal is to use the ATMega328PB (whole circuit board is designed for it) and for some reason my project stalled here now.

I'm using Arduino MEGA2560 as ISP, and have been programming some 328p:s with it in the past, but it's been around for a while and through all kind of molesting, so i ordered a USBASP programmer now.
The circuit board itself has only a SPI-connection so i really don't need a bootloader, because i will be uploading the sketches straight through the SPI (no UART).

I'm pretty sure i have to buy more ATMega328PB:s, but i wouldn't want to break them also...

That is bit worrying since I plan to use the same chip for some projects.

Which core are you using to program and upload to it. May I suggest you try MiniCore, it has a dedicated 328PB selection.

Even if the crystal oscillator does not work, assuming the fuses settings expect one, it should switch down to 1MHz and still work.

I will watch your progress.

Willem.

I then measured the crystal with an oscilloscope, and the only place where i could find a waveform signal was on the GND-side of both 22pF capacitors

If your scope clip lead was connected to ground then the point you measured and saw a waveform could not at the same ground potential, could it?

You either have a board layout error or a measurement error so that’s where you start looking.

Post a schematic and an image file of your board layout if you want a second set of eyes sanity check.

Willem43:
That is bit worrying since I plan to use the same chip for some projects.

Which core are you using to program and upload to it. May I suggest you try MiniCore, it has a dedicated 328PB selection.

Even if the crystal oscillator does not work, assuming the fuses settings expect one, it should switch down to 1MHz and still work.

I will watch your progress.

Willem.

That's what worries me, the built-in oscillator should take care of the timing if it isn't satisfied with the signal from the external one. Feels like i have a major design flaw in my circuit layout. But then again, it doesn't work on the breadboard either...
I checked out the MiniCore extension, and it looks promising. Will surely be using it if i get this to work. :slight_smile:

WattsThat:
If your scope clip lead was connected to ground then the point you measured and saw a waveform could not at the same ground potential, could it?

You either have a board layout error or a measurement error so that’s where you start looking.

Post a schematic and an image file of your board layout if you want a second set of eyes sanity check.

True. I doublechecked and came to the conclusion that i messed something up the first time measuring. Got to measure it "correctly" now, but no use, as my scope only does about 200kHz anyways. :frowning:

Here's a pic of the schematic and PCB.

I've designed a board around the ATmega328PB, and I didn't experience any issues with it except for the missing full swing oscillator option. This means the 328PB is much more sensitive to where the crystal is placed on the board. Try to keep it as close as possible to the XTAL pins.

About your custom PCB. You should place a ground plane on both sides of the PCB instead of a thin wire snaking around. You should also add some decoupling capacitors close to the vcc and gnd pins on all your chips. I would not expect the 328PB to work without them.

That schematic is unnecessarily complicated. Learn to use the ground symbol (and VDD too) rather than drawing wires all over the place that are not needed. Using the correct symbols for components would be a huge help as well.

After fix the floating reset pin of the ‘328, you may find it still will not work properly as your trace widths and paths are problematic. Consider the ugly loop in the traces connecting pin 18 of U2, R1 and the ISP connector. It may work but as hansibull mentions, it definitely needs more and properly placed bypass capacitors. You should also have more capacitance on the output of the 7805, look up its datasheet and use the recommended value for proper voltage stability.

As I keep looking... you’ll need pull up resistors on the I2C lines, unless the OLED display provides them. Also, since the MCP2515 shares the SPI pins, I would add a 10K pullup from CS/ (pin 16) since the ‘328 I/O pins are floating during ISP programming. You don’t want noise to cause the MCP2515 to assert the MISO pin, causing a conflict with the programmer. A resistor is a very cheap insurance policy.

That's what worries me, the built-in oscillator should take care of the timing if it isn't satisfied with the signal from the external one.

No, the ‘328 clock doesn’t work that way. The clock is controlled by the fuse settings, period. There is no fuzzy logic that figures out what clock source to use.

WattsThat:
Also, since the MCP2515 shares the SPI pins, I would add a 10K pullup from CS/ (pin 16) since the ‘328 I/O pins are floating during ISP programming. You don’t want noise to cause the MCP2515 to assert the MISO pin, causing a conflict with the programmer. A resistor is a very cheap insurance policy.

I have used LoRa devices, also SPI based, quite a lot on barebones ATmel boards, an ISP programmer will not work if there is no pullup on the devices CS\NSS pin.

WattsThat:
No, the ‘328 clock doesn’t work that way. The clock is controlled by the fuse settings, period. There is no fuzzy logic that figures out what clock source to use.

We are discussing the 328PB version.

From the Atmega 328PB specification under the "Special Microcontroller Features" section:

  • Clock Failure Detection Mechanism and Switch to Internal 8MHz RC Oscillator in case of Failure.

It monitors the external clock options. I presume this was added in response to the removal of the Full Swing Oscillator option, making an external cystal oscillator quite a bit more fragile.

There is an entire chapter in the documentation, Chapter 12 in my copy of the documentation, dedicated to this feature.

Willem.

That's really interesting about the ATmega28PB's CFD feature. I didn't know about that. I could see it leading to more difficult to diagnose problems (board with faulty 16 MHz crystal circuit is still running, but at half the expected speed), but it does mean no worries about "bricking" a microcontroller by accidentally setting the fuses for an external clock when none is connected. If I had a project where reliability was critical, I would enable that feature and have some code that monitors XFDCSR.XFDIF and somehow handles and logs or indicates a clock failure.

I notice that MiniCore's fuse settings have this feature turned off:

pert:
I notice that MiniCore's fuse settings have this feature turned off:

Thanks for pointing that out.

When I do my first board I definitely want that enabled. At least till I have established the crystal I am using works. Maybe I should add that as a menu option in my installation.

Willem.

Hi guys!
I recently had a little extra time to dig into this again. I ditched the 328PB-chip and redesigned the circuit with a standard 328P-chip instead. Also did the recommended changes for the circuit. Are there still further errors to be corrected before trying to design the board layout? :slight_smile:

Well. seeing that you are asking.

Firstly you need 100nf decoupling caps on the VCC, AVCC and possibly the AREF pins as close to the MCU as practical.

The recommended pull-up resistors for the I2C lines are 4.7K.

If you are using the SPI for both a slave device and programming, it is also recommended to have inline 330ohm resistors in the three SPI lines for the slave device. Others may chime in here since I have not used any SPI slave devices onboard (only for programming).

I see you have a pull-up for the slave CS line - good.

Pity you gave up on getting the 328PB working - I have 10 of them (minimum order) and you sorting it may have helped me.

Willem.