1

I've got a project where I need to program an ATmega328P on an Arduino Uno board, then transplant it into a custom PCB - however, this board does not have an oscillator installed, and so I need to run the microcontroller off its internal clock.

My goal here is to be able to code my software with the Arduino IDE, insert a factory-fresh ATmega328P straight from the tube into the socket on the Arduino Uno board, then move the device from the board to the PCB without any changes along the way. What's the best way to go about this?

  • don't recall where, but i've seen a board def for a bare 328 set to run at 8mhz w/o xtal; maybe it will allow 1mhz as well... – dandavis Mar 13 '18 at 19:59
2

That will not work. To change the clock source, you'd need to change the fuses. I don't know of any way to do this while the chip is inside the UNO.

Secondly, a factory fresh 328P won't work in an UNO board, because it doesn't have the correct fuses, and doesn't have the bootloader programmed.

I'd suggest placing the 328P chips in a breadboard; connect the ISP pin to the UNO, and use the Arduino-as-ISP to change the fuses, and upload your program.

PS why run at 1Mhz. The internal oscillator runs at 8Mhz. By default the divide-by-8 fuse is set, so it runs at 1Mhz out of the factory, but you can unset this fuse.

PPS use this website http://www.engbedded.com/fusecalc/ to generate the right fuse settings for your project.

  • This would set up the factory fresh device to work as an Arduino, right? That is, I could put the newly programmed chip into an empty Uno, program it, then move it onto a custom PCB? – Phoxtane Mar 13 '18 at 20:40
  • You can easily change the fuses using something like the sketch described in my answer - you just connect to the ICSP pins (MOSI/MISO/SCK/RESET). – Nick Gammon Mar 14 '18 at 5:02
  • Kind of, but you don’t want to do just that. You can program the 328 with your sketch directly, while it is in the breadboard. No need to take it out of the breadboard and put it into the UNO. – Gerben Mar 14 '18 at 8:54
1

You can set the fuses to run on the internal oscillator easily enough. You can still run at 8 MHz which the IDE supports (choose Lilypad in the IDE) and then the delays, serial prints, etc. will still work properly.

As for programming a new chip, you can use an Arduino as ISP, an external ISP programmer (available cheaply from eBay), or see my page about uploading hex files which just needs a few hook-up cables, and a $15 SD card adapter like this:

SD card adapter

You upload the sketch onto your Uno to make it into a programmer. Then you compile the code for your target chip and get the .hex file that the compiler produces.

Example setup:

Hex uploader

The hex uploader sketch also lets you change fuses.

The AVR Fuse Calculator page will help you with getting the correct fuse settings.

  • This is perfect - I assume the Lilypad is pin-compatible with the Uno? – Phoxtane Mar 13 '18 at 22:42
  • The Lilypad is just an Atmega328P clocked at 8 MHz, so that is fine for compiling from your point of view. It's the same processor, so in that sense, yes it's pin-compatible. – Nick Gammon Mar 13 '18 at 23:55
  • Even better is that I have an 8MHz ceramic resonator on hand, so even though the Lilypad schematic specifies an external clock source, I've got that covered without having to order extra components! – Phoxtane Mar 14 '18 at 3:44
  • 1
    I usually use the internal oscillator which generates 8 MHz. No extra parts needed. – Nick Gammon Mar 14 '18 at 4:27
  • I've heard horror stories about fuse bits, so the further I stay away from those, the better. I also don't have to explain to my professor why my board has an empty slot as well... – Phoxtane Mar 14 '18 at 4:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.