ICSP - can upload "blink" but not my own code

Hi, I'm new here - please forgive me and redirect me if I'm broken any protocols! I'm reasonably familiar with Arduino, but am new to ICSP programming an ATmega328P in my own circuit.

The short version of my problem is that I can use ICSP, using an Arduino as an ISP to burn the bootloader, and then upload "blink" to my ATmega328P, but when I try to load more complex code, such as "Hello World" from the "Liquid Crystal I2C" library, the upload doesn't work. I get "avrdude error: cannot open port \.\COM3: Access is denied". I've tried all the usual stuff like restarting the IDE, disconnecting and reconnecting the Arduino from my computer, using a different USB port etc.

Details:
My circuit is as follows:
Schematic_Magnetic-Field-Sensor-I2C-Sensor_2023-08-27.pdf (91.9 KB)

I connect it as follows to a CH340 Arduino Uno, set up as an ISP:
Arduino D10 to ATMega328P Pin 1 (reset)
Arduino D11 to ATMega328P Pin 17 (MOSI)
Arduino D12 to ATMega328P Pin 18 (MISO)
Arduino D13 to ATMega328P Pin 19 (SCK)
Arduino 5v to 5v rail of ATMega328P circuit
Arduino GND to GND rail of ATMega328P circuit

I won't go into all the details and steps (unless someone says that would be useful), but essentially, I am able to upload the Arduino as ISP code onto my UNO, then, using "MiniCore" , I am able to burn the bootloader onto my ATmega328, and I can also upload the stock-standard "blink" example code. But when I try to upload the following code (or my own code, which I haven't listed here because it is longer) I get the "avrdude error: cannot open port \.\COM3: Access is denied" error.

Any help would be greatly appreciated!

//YWROBOT
//Compatible with the Arduino IDE 1.0
//Library version:1.1
#include <Wire.h> 
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27,20,4);  // set the LCD address to 0x27 for a 16 chars and 2 line display

void setup()
{
  lcd.init();                      // initialize the lcd 
  lcd.init();
  // Print a message to the LCD.
  lcd.backlight();
  lcd.setCursor(3,0);
  lcd.print("Hello, world!");
  lcd.setCursor(2,1);
  lcd.print("Ywrobot Arduino!");
   lcd.setCursor(0,2);
  lcd.print("Arduino LCM IIC 2004");
   lcd.setCursor(2,3);
  lcd.print("Power By Ec-yuan!");
}


void loop()
{
}

You are aware that if you first burn the boot loader and next load blink via ICSP, the boot loader is no longer there.

So your sequence should be

  1. Burn boot loader via ICSP
  2. Upload blink via serial (USB).
1 Like

Looking at your schematic, I think the RESET circuitry is wrong. In order to load code using the bootloader over the serial link, your board should use the USB-Serial DTR signal to reset the micro. The DTR signal is usually fed through a 100n capacitor - likely C3 in your schematic - which you have connected to GND.

Here's a schematic of a Pro Mini design from Sparkfun:

1 Like

Thanks! Actually, I'm not aware of much at all yet... still finding my way!
I was under the impression that the bootloader is like a "stub" of code that allows the microcontroller to be programmed via serial port. So thought I probably don't even need it given I intend to program via ICSP, using Arduino as ISP. But the fact that it worked seemd to tell me that my circuit and connections are ok.

Anyway, I think I'm on to something... I've discovered some more:

  1. I disconnected my I2C connection to the LCD, and then the upload worked. I could even upload the full version of my code. So that's promising! But I don't understand why it works now but it didn't before.
  2. I suspect I'm also having problems with my Windows USB drivers, as this 'access to COM3' type problem seems to occcur intermittently even when I'm uploading to a UNO directly from the Arduino IDE.

I'll keep trying things. But any advice is still very welcome and appreciated!

Thanks for your advice! It's working now. Turns what I needed to do was discconnect devices from my ATmega328 circuit's I2C bus. Then it worked. When the I2C LCD panel is disconnected, I can upload successfully. If anyone has any theories about why this would have caused a conflict, I'd be interested to know. Perhaps the I2C device (a backlit LCD panel) drew too much power?
Anyway, thanks again.

Although I'm not sure of the exact error message, IDE 2.1 prevents upload via serial if you're using a FTDI adapter AND serial monitor is open; this is a known bug.

That is correct.

Indeed, in that case it's not needed.

I also don't understand. This seems to indicate a power problem.

I've copied your schematic into a post so those more knowledgeable in hardware can have a look without having to open a PDF.

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