ATMega328P

I need to program a bare ATMega328P and I have a Tiny USB programmer. I’m building a radio and have never used Arduino. Can someone explain to me how to do this? I work on circuits and radios, and don’t want to spend hours getting nowhere on programming. I would greatly appreciate it. :smiley:

A “bare” ATmega328P needs several other parts to run. Here is one tutorial on getting started with it: https://www.gammon.com.au/breadboard

Perfect. Will wire up. Thank you!!!

Ok, now I’m getting an error message (after solving a gazillion other error messages) when I try to Upload Using Programer from Arduino IDE 2.3.0.

The error is:

avrdude: initialization failed, rc=-1

My wiring looks ok and I have attached a pic.

It verify/compiles fine.

I’m using Board: Atmel atmega328p Xplained mini

I confirmed I have that chip and not 328

Programmer is USBTinyISP

Where is the required 10K pullup resistor on /RESET?

Go over the Gammon tutorial again and triple check all the wiring.

I’m using Board: Atmel atmega328p Xplained mini

Why did you choose that? It has a programmer built in, and other hardware options that could lead to problems.

Connections between the programmer and chip are incorrect, double check those.

Don’t power the chip externally, let the programmer do that.

Get a 16MHz crystal and capacitors connected, you might not need them the first time you program the chip (maybe) but you’re going to need them soon or if you accidentally enable the external clock.

Uno is a safe, tested board type, pick that as your board in the ide.

The 10k pull up is there beneath wire.

The connections between programmer and chip seemed right except the ground and the CS which I couldnt find on my programmer. Any thoughts?

I have a 14MHz crystal that I will add, though I set internal to 8MHz in ide.

I will pick Uno in the Ide.

I will pull ext power.

Then I will report back my results. Lmk about programmer connections. Otherwise many thanks to you.

Progress made. Circuit is wired correctly. I got a success for the board_detector program upload and board_programmer upload, but I couldn’t figure out how to turn on the serial monitor. Once I did, I tried running the board detector and programmer again so that I could watch. I get the following error:

Timeout: The IDE has not received the ;success’ message blah blah. I saw the need to set the baud rate at 115200 but it wouldn’t let me change it. Close everything and started over and now I don’t see the drop down for the baud rate.

Also my LED on the programmer is on all the time now.

Ultimately, I want to load this code:

avrdude -c usbtiny -p m328p -U lfuse:w:0xe2:m -U hfuse:w:0xd1:m -U efuse:w:0xff:m

Can you guys help?

The Baud rate setting for the Arduino IDE serial monitor is on the serial monitor window. Lower right corner in IDE 1.8.19

I am using Arduino 2.3.0 with Win 11. Sometimes that dropdown box is there. Sometimes it isn’t. When it is there, it won’t let me select anything other than 9600. I looked at the sketches and both the Board_Detector and Board_Programmer set the baud rate at 115200. Maybe this isn’t even the problem. But I still get the error:

Timeout: The IDE has not received the ‘success’ message from the monitor after successfully connecting to it. Could not connect to COM6 serial port.

I recommend Arduino IDE 1.8.19, which over many years has almost all of the bugs worked out.

I just uninstalled and reinstalled 1.8.19. Ran Board_Detector sketch. Uploads fine with Serial Monitor closed. When I click to open Serial Monitor, I get the following error:

Error opening serial port ‘COM6’. (Port busy)

This is after a full reboot of PC too.

Is an Arduino connected to COM6? If so, which Arduino and how is it connected?

Yes, via USB. It is the Tiny AVR Programmer. YellowDog above indicated I should select Uno for a Board in the IDE.

Why do you think the serial monitor is needed?

To use the Tiny AVR programmer, follow the relevants part of these instructions: https://learn.sparkfun.com/tutorials/ti … -guide/all

Ok, I have no idea why I need the Serial Monitor other than I don’t know what I’m doing and am following those steps:

I tested sending commands via the cmd prompt. I need to send the following code but a couple things appear to have failed. See below:

C:\Users\adamf>avrdude -c usbtiny -p m328p -U lfuse:w:0xe2:m -U hfuse:w:0xd1:m -U efuse:w:0xff:m

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.03s

avrdude: Device signature = 0x1e950f

avrdude: reading input file “0xe2”

avrdude: writing lfuse (1 bytes):

Writing | ################################################## | 100% 0.03s

avrdude: 1 bytes of lfuse written

avrdude: verifying lfuse memory against 0xe2:

avrdude: load data lfuse data from input file 0xe2:

avrdude: input file 0xe2 contains 1 bytes

avrdude: reading on-chip lfuse data:

Reading | ################################################## | 100% 0.02s

avrdude: verifying …

avrdude: 1 bytes of lfuse verified

avrdude: reading input file “0xd1”

avrdude: writing hfuse (1 bytes):

Writing | ################################################## | 100% 0.02s

avrdude: 1 bytes of hfuse written

avrdude: verifying hfuse memory against 0xd1:

avrdude: load data hfuse data from input file 0xd1:

avrdude: input file 0xd1 contains 1 bytes

avrdude: reading on-chip hfuse data:

Reading | ################################################## | 100% 0.00s

avrdude: verifying …

avrdude: 1 bytes of hfuse verified

avrdude: reading input file “0xff”

avrdude: writing efuse (1 bytes):

Writing | | 0% 0.00s ***failed;

Writing | ################################################## | 100% 0.11s

avrdude: 1 bytes of efuse written

avrdude: verifying efuse memory against 0xff:

avrdude: load data efuse data from input file 0xff:

avrdude: input file 0xff contains 1 bytes

avrdude: reading on-chip efuse data:

Reading | ################################################## | 100% 0.02s

avrdude: verifying …

avrdude: verification error, first mismatch at byte 0x0000

0xff != 0x07

avrdude: verification error; content mismatch

avrdude: safemode: efuse changed! Was ff, and is now 7

Would you like this fuse to be changed back? [y/n]

I don’t know what you are trying to do with those commands, but you appear to have communication errors. Could be intermittent wiring, bad chip, unstable power supply, etc. Are all connections soldered, or made with reliable jumpers between properly soldered header pins?

The serial monitor has nothing to do with device programming. It is intended only for debugging or programmatic serial communications with an Arduino, connected via a serial port separate from the programmer.

Yes, everything is with fresh wire on a breadboard. It was a bare MCU and I successfully loaded the board_detector and board_programmer sketches.

These are the instructions:

"Test and check

Do not insert a microcontroller yet, first check when applying 12V to the “12+ V perm.” connector used for the LO test, if there are 5V present at pin 8 of the ATmega328P.

Then check if the MCU can communicate with a PC via a programming interface (e. g. the “USB-Tiny AVR programmer“).

For example you can transmit the command

avrdude -c usbtiny -p m328p -U lfuse:w:0xe2:m -U hfuse:w:0xd1:m -U efuse:w:0xff:m

via the interface (in my case I use the “USB tiny”-programmer) to the controller which sets the device to 8MHz clock and prevents EEPROM to be erased after programming."

The MCU is part of the VFO of my 14 MHz radio I’m building.

Tiny programmer has no com port.

The COM reference is my PC, not the programmer.