ATMEGA328P keeps resetting

Thread Starter

Pouwertronics

Joined Mar 13, 2022
8
Hello everyone,

Lately, I've been working on designing a PCB (Printed Circuit Board) for an e-paper display. I've written the firmware for the microcontroller and successfully tested it on an Arduino Nano; with that, I got the e-paper screen working without any issues.

However, on my own custom PCB, I'm encountering a strange problem: as soon as the firmware tries to initialize the SPI communication, the microcontroller keeps continuously resetting itself. In the serial monitor, I repeatedly see the same debug texts that are called in the setup() function, which indicates a constant reset loop.

What if have done so far:
  1. Changed the pull-up resistor on the reset pin from 1K to 10K.
  2. Added two extra 22pF capacitors to the 16MHz crystal (although this shouldn't normally be necessary, as the crystal itself already has an internal capacitive load of 20pF.
  3. The power supply is provided by an external 5V source.

I have included the schematic and pcb screenshots.

Can somebody help me out? Thank you in advance.
 

Attachments

Thread Starter

Pouwertronics

Joined Mar 13, 2022
8
Welcome to AAC.

Have you monitored the 5V supply at the board to see if it sags or behave strangely?
Thank you :)

I have a scope on the 5v lines, but i see no strange sags or something like that.

Its strange that when i comment out the code for the display the proccesor runs without anny problem.

main code:
#include <avr/wdt.h>
#include "Adafruit_ThinkInk.h"

#define EPD_DC 10
#define EPD_CS 5
#define EPD_BUSY 4
#define EPD_RESET 6
#define EPD_SPI &SPI

ThinkInk_290_Tricolor_Z94 display(EPD_DC, EPD_RESET, EPD_CS, -1, EPD_BUSY, EPD_SPI);

void setup() {
  Serial.begin(115200);

  while (!Serial) {
    delay(10);
  }

  wdt_disable();
  delay(3000);

  Serial.println("Adafruit EPD full update test in red/black/white");
  display.begin(THINKINK_TRICOLOR);

  Serial.println("Banner demo");
  display.clearBuffer();
  display.setTextSize(3);
  display.setCursor((display.width() - 144) / 2, (display.height() - 24) / 2);
  display.setTextColor(EPD_BLACK);
  display.print("Tri");
  display.setTextColor(EPD_RED);
  display.print("Color");
  display.display();
}

int i;
void loop() {
  Serial.println(i++);
}
 

MrChips

Joined Oct 2, 2009
34,627
Try placing a 100 nF ceramic disk capacitor between Vcc and GND close to the MCU.
Then add a 10 - 100 μF electrolytic capacitor across Vcc and GND where power enters the board.
 

Ya’akov

Joined Jan 27, 2019
10,226
Thank you :)

I have a scope on the 5v lines, but i see no strange sags or something like that.

Its strange that when i comment out the code for the display the proccesor runs without anny problem.

main code:
#include <avr/wdt.h>
#include "Adafruit_ThinkInk.h"

#define EPD_DC 10
#define EPD_CS 5
#define EPD_BUSY 4
#define EPD_RESET 6
#define EPD_SPI &SPI

ThinkInk_290_Tricolor_Z94 display(EPD_DC, EPD_RESET, EPD_CS, -1, EPD_BUSY, EPD_SPI);

void setup() {
  Serial.begin(115200);

  while (!Serial) {
    delay(10);
  }

  wdt_disable();
  delay(3000);

  Serial.println("Adafruit EPD full update test in red/black/white");
  display.begin(THINKINK_TRICOLOR);

  Serial.println("Banner demo");
  display.clearBuffer();
  display.setTextSize(3);
  display.setCursor((display.width() - 144) / 2, (display.height() - 24) / 2);
  display.setTextColor(EPD_BLACK);
  display.print("Tri");
  display.setTextColor(EPD_RED);
  display.print("Color");
  display.display();
}

int i;
void loop() {
  Serial.println(i++);
}
It could be a software problem, but if you didn't find any examples of this happening with a web search I would suspect hardware first, and particularly power related things.

Have you tried running the code with the display disconnected?
 
Top