Run atmega328 @ 3.3v and external 8MHz crystal

I need to use an atmega328p on a circuit that will be powered by a battery and will be “talking” (serial communication Tx/Rx) with the esp8266 (operates only @3.3v).
In order to interface directly (no voltage divider, no level shifter, no diode in series etc) with the esp8266 the atmega needs to send 3.3v on the Tx pin.
For a quick moment I though that by powering the atmega on the vcc line with 3.3v the output of the HIGH signals would be 3.3v as well, but of course not; so I realized that I need to burn a version of the bootloader that sets the atmega328 at 3.3v and use the corresponding crystal value of < 10 MHz. Also I would need to change the value of the BOD to a suitable value or disable it
I found 2 tutorials on the Arduino website that explains how to burn the bootloader on a blank atmega chip and another one that explains how to do it using the internal 8MHZ oscillator as a clock.

But they don’t apply to my question ( and also they provide hardware configs that are supposed to work with older version of the Arduino IDE, so I am not sure if the current 1.8.5 version will work).

Can somebody provide an updated method on how to accomplish this.? I have seen videos on youtube using such configs like the moteino for example so it is doable .

But I only have a blank chip and don’t want to 'brick" it following the wrong procedure. I appreciate the help in advance!

The “breadboard-1-6-x.zip” file from that tutorial will work fine with Arduino IDE 1.8.5. By the way, the latest IDE version is 1.8.7. 1.8.5 is a year out of date.

Instead of that “breadboard” package, you might prefer to use MiniCore:

After installing and selecting Tools > Board > ATmega328, you can select any common clock configuration from the Tools > Clock menu.

[quote author=fborot link=msg=3880847 date=1537566370
But I only have a blank chip and don’t want to 'brick" it following the wrong procedure.
[/quote]
The most common way to “brick” chips when doing this is to configure it to use an external clock when no clock source is attached. The solution is to simply connect an external clock source long enough to set the fuses to use the internal oscillator. Since you’re going to be using a crystal anyway, that will not be a problem for you.

Thank you pert. Couple of more questions:

1- using the "breadboard-1-6-x.zip" file from that tutorial ..... where can I set the 3.3V option? is it in the hex file? is it done at some point during the install or burn process?

2- what about the minicore?

I mean I read the instructions for both and they mention the bod, clock settings etc but I did not see where to set the 3.3V option. Unless they are "preset" to that by default. I also check the optiboot github page since minicore comes from it and could not see that either. I also check the file "boards.txt" inside the "breadboard-1-6-x.zip" file and see noting that makes me think that setting is chosen.

fborot:
where can I set the 3.3V option?

You don't set 3.3 V anywhere. I/O pin levels are relative to the supply voltage (slightly less, see datasheet). If you power the ATmega328P at 3.3 V then you get 3.3 V I/O. If you power it at 5 V then you get 5 V I/O. The most important consideration for 3.3 V operation is that the ATmega328P is not rated to run at 16 MHz with 3.3 V supply voltage. You also might want to set an appropriate BOD level. For example, if the BOD is at 4.3 V and you're running at 3.3 V then the microcontroller will just constantly reset.

fborot:
is it in the hex file?

The clock and BOD fuse settings are in boards.txt. In the case of the "breadboard" hardware package:

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

...

atmega328bb.bootloader.lock_bits=0x0F

And here's what that configuration gives you:
http://eleccelerator.com/fusecalc/fusecalc.php?chip=atmega328p&LOW=E2&HIGH=DA&EXTENDED=05&LOCKBIT=0F
The clock is set for the internal RC oscillator, 8 MHz.
The boot section size is set for 1024 words (2 kB). This is the area of flash memory reserved for the bootloader.
The boot reset vector is enabled (for using the bootloader).
BOD is set to 2.7 V.

fborot:
is it done at some point during the install or burn process?

The Arduino IDE's Tools > Burn Bootloader is a two step process:

  • Set fuses according to boards.txt.
  • Flash the bootloader.

So even if you only want to set fuses in the Arduino IDE, you will use the Burn Bootloader command.

fborot:
2- what about the minicore?

Same thing. The only difference is that while the "breadboard" hardware package only permits a single board configuration, MiniCore gives you a bunch of configuration options via custom menus that appear under the Tools menu after you install MiniCore and select one of its boards. It also provides a more modern bootloader that fits in a 0.5 kB boot section, saving 1.5 kB of precious flash memory compared with the breadboard package's outdated bootloader. The breadboard hardware package's bootloader also has a bug that causes it to go into an infinite reset loop if you use the watchdog timer.

If you don't feel like messing with MiniCore and want to use an external 8 MHz crystal, you can simply select Tools > Board > Arduino Pro or Pro Mini and then Tools > Processor > ATmega328P (3.3 V, 8 MHz). That board selection uses the same bootloader as the "breadboard" package, with the same waste of flash memory and watchdog bug.

thank you again pert

“if you power the ATmega328P at 3.3 V then you get 3.3 V I/O. If you power it at 5 V then you get 5 V I/O.”

so, in summary: while burning the minicore, I select my frequency and then just power it up with 3.3v in the vcc pin and the HIGH values sent on the TX pin will be 3.3V as well ?

That was my initial assumption and I even measured the value with my multimeter running the blink sketch keeping the led lit for 10 secs and I saw 4.5+V most of the time. I will do it again to double check.

“The most important consideration for 3.3 V operation is that the ATmega328P is not rated to run at 16 MHz with 3.3 V supply voltage”

I have read several post were they state that, that is why I plan t use <10MHz, although there are several boards running @3.3v/16Mhz and seemed fine, I guess the atmega is very tolerant.

Something else, after I burn the minicore, I can load my sketches with my FTDI adapter (usb to serial) right ?

fborot:
so, in summary: while burning the minicore, I select my frequency and then just power it up with 3.3v in the vcc pin and the HIGH values sent on the TX pin will be 3.3V as well ?

Yes, actually a little less than 3.3 V on the output pins, but not so much that it matters.

fborot:
That was my initial assumption and I even measured the value with my multimeter running the blink sketch keeping the led lit for 10 secs and I saw 4.5+V most of the time. I will do it again to double check.

That's definitely wrong. But it's very good to check these things to be sure and also to learn.

fborot:
although there are several boards running @3.3v/16Mhz and seemed fine, I guess the atmega is very tolerant.

Correct. It is possible but it's not within the specifications provided by the manufacturer so you have no assurance it will work reliably.

fborot:
Something else, after I burn the minicore, I can load my sketches with my FTDI adapter (usb to serial) right ?

It's the bootloader that allows this. MiniCore does have an option Tools > Bootloader > No that will cause the bootloader to not be flashed when you to Tools > Bootloader, it only sets the fuses. That is useful if you only want to do uploads with your ISP programmer via Sketch > Upload Using Programmer and so don't want any boot section reserved for the bootloader. But if you have Tools > Bootloader > Yes then the bootloader will be flashed and you will be able to upload via your FTDI adapter.

thank you a lot pert, yo have been super helpful, I appreciate it a lot...., I think I have this clear now, once I test it I will update this post.

I powered the atmega with 3.3 V and indeed the HIGH output signal is 3.1 V - 3.2 V approximately. I guess I had a wrong setup before.
I will try the minicore soon and update this post with my observations