AfterEarthLTD / Solder-Reflow-Plate

PCB based SMD reflow plates
MIT License
1.36k stars 235 forks source link

Using a AtMega328p from another Arduino device #20

Open Rudis1261 opened 2 years ago

Rudis1261 commented 2 years ago

So after some research, I found how to set the 328p fuse to use the internal clock in case you want to repurpose an Arduino with a suitable chip like a lilypad, or nano or something similar. You need to set this fuse back to factory because Arduinos by default get switched to an external clock instead of it's internal one.

You will need to hook up the Arduino on the ICSP headers, and use another Arduino programmed as an Arduino as ISP to program the target 328p board.

And you need to set the fuse prior to de-soldering the chip from the Arduino to use in the solder reflow plate. Otherwise you will not be able to program it from the ICSP headers once on the solder reflow plate.

Using this command you can set the fuse to tell the Arduino to use the internal clock:

~/AppData/Local/Arduino15/packages/arduino/tools/avrdude/6.3.0-arduino18/bin/avrdude.exe \
-PCOM8 \
-v \
-patmega328p \
-cstk500v1 \
-PCOM8 \
-b19200 \
-C avrdude.conf \
-U lfuse:w:0xF2:m

The command broken down:

# The path of your avrdude.exe file 
~/AppData/Local/Arduino15/packages/arduino/tools/avrdude/6.3.0-arduino18/bin/avrdude.exe
# The COM port where the Arduino as ISP can be found
-PCOM8
# Verbose output
-v
# The target chip
-patmega328p
# The programmer avr should use
-cstk500v1
# The baud rate as set in the Arduino as ISP sketch uploaded to the programming Arduino
-b19200
# The avrdude.conf, this may not be in the same directory as the command.
-C avrdude.conf
# The action to perform, in this case we are setting the LFUSE to `0xF2` by writing the value to configure the 328p to use the internal clock.
-U lfuse:w:0xF2:m

Hope this helps someone.

A great video explaining this, and what got me to an answer: https://www.youtube.com/watch?v=Q2DakPocvfs

doskoi commented 2 years ago

Thanks for the useful material, this doc do the same thing in another approach https://docs.arduino.cc/built-in-examples/arduino-isp/ArduinoToBreadboard/

doskoi commented 2 years ago

Or from the comments inside the source code

To program
 *  1) Select the following settings under (Tools)
 *      Board->Minicore->Atmega328 
 *      Clock->Internal 8MHz
 *      BOD->BOD 2.7V
 *      EEPROM->EEPROM retained
 *      Compiler LTO->LTO Disabled
 *      Variant->328P / 328PA
 *      Bootloader->No bootloader
 *  2) Set programmer of choice, e.g.'Arduino as ISP (MiniCore)', 'USB ASP', etc, and set correct port.
 *  3) Burn bootloader (to set fuses correctly)
 *  4) Compile and upload
doskoi commented 2 years ago

I was upload without set fuse nor use minicore to set internal clock but just sodering chip on this board, Then I'm using breadboard with DIP 16M external clock attach to XTAL1 and XTAL2 (PIN7, 8), after this I can comminucate with 328p by programmer again.

simonstrachan commented 10 months ago

I had my boards assembled with the Atmega already on them. Is there a way to do what GreatScott did in his video with a function generator? I can not seem to be able to get the bootloader to sync. Is it only possible to do it with an external clock or taking one from an existing Arduino?

doskoi commented 10 months ago

You need to follow the setup at above to enable built-in clock.

Clock->Internal 8MHz

For your circumstance, you need a external clock to do this setup work. after that, you won't need external clock.