PlatformIO Community

ATmega328 Internal clock


#1

I have been using PlatformIO for a while, and with great success. However I have hit my first stumble.
I wish to use the ATmega328p with the internal clock.

Normally I would Download a file, “breadboard-1-6-x.zip” open it into a ARDUINO sketchbook folder marked “hardware”. After doing this there is a new board in the menu of the arduino IDE marked BREADBOARD.

Lastly I select “arduinoISP” and use an arduino UNO to load sketches up to the arduino chip. Is there a way of doing this in PIO? If so anyone got an Idea as to how?
I am includeing a video of how I do this in a link Incase I am not clear as I need to be.

Video Here.

:roll_eyes::tired_face:


#2

For uploading with arduino ISP see https://docs.platformio.org/en/latest/platforms/atmelavr.html#id8, section “Upload using Programmer”.

The easiest way to use your breadboard Arduino would be to find the closest board in the list of ATMega328P boards listed at https://platformio.org/boards (type in “ATMega328P” for MCU) and then just use board = xyz in your platformio.ini.

If your unique configuration is not found within these boards, you have the following options:

For clock configuration, see e.g. https://docs.platformio.org/en/latest/boards/atmelavr/uno.html#board-atmelavr-uno, board_build.f_cpu = ....

To reproduce the “Breadboad, internal 8MHz” version (with 3.3V or 5V?), you might want to create a new board definition. See e.g. https://github.com/platformio/platform-atmelavr/blob/develop/boards/uno.json. But first I’d see if your configuration already exists.

The boards.txt in your breadboard-1-6-x.zip states

##############################################################

atmega328bb.name=ATmega328 on a breadboard (8 MHz internal clock)

atmega328bb.upload.protocol=arduino
atmega328bb.upload.maximum_size=30720
atmega328bb.upload.speed=57600

atmega328bb.bootloader.low_fuses=0xE2
atmega328bb.bootloader.high_fuses=0xDA
atmega328bb.bootloader.extended_fuses=0x05

atmega328bb.bootloader.file=atmega/ATmegaBOOT_168_atmega328_pro_8MHz.hex
atmega328bb.bootloader.unlock_bits=0x3F
atmega328bb.bootloader.lock_bits=0x0F

atmega328bb.build.mcu=atmega328p
atmega328bb.build.f_cpu=8000000L
atmega328bb.build.core=arduino:arduino
atmega328bb.build.variant=arduino:standard


atmega328bb.bootloader.tool=arduino:avrdude
atmega328bb.upload.tool=arduino:avrdude

So you should be able to reproduce these settings (fuses, cock speed) with the links I gave you above. Also see https://docs.platformio.org/en/latest/platforms/creating_board.html.


#3

A build environment of …

[env:Breadboard ATMega328]
platform = atmelavr
board = 328p8m
framework = arduino

… will work with a Atmega328 that is running on a 8Mhz crystal, or a 8Mhz internal clock. It looks like one of the supported upload methods is an Arduino programmed as a ISP (ArduinoISP), so you can add…

upload_protocol = arduinoisp

… to the above platformio.ini config, making the only thing left to do is set the fuses on the Atmega328 correctly. Don’t know if that is readily doable in platformio - probably, since you can also pass parameters to avrdude via upload_flags, but I’m not sure what to set there as I usually use avrdudess on Windows to do my fuse settings and first upload of a compiled arduino sketch (which includes the serial bootloader).


#4

Do you use pio run -t program?


#5

Er, no, I didn’t… doing that makes the verification error go away nicely! Thanks! :wink: I’ve also since found the extra_scripts notation about custom fuses, so have also done that. Final step will be to try uploading to a fresh atmega328p and see if the fuses are correctly changed when code is loaded onto it…


#6

See docs => https://docs.platformio.org/en/latest/platforms/atmelavr.html#upload-using-programmer

Happy coding with PlatformIO! :wink: