Interface might not be required at all.
But let me be particular here: this isn't a production-ready design-grade answer; it's probably too
stupid clever for its own good. I would at least urge a statistical sampling process with full voltage and temperature sweep testing to deploy this in production.
But just for hacking together a one-off, it's probably fine.
Anyway, the method.
Consider that the
2 pins are (depending on configuration, maybe) the input and output of a single-stage CMOS inverter. (Probably with some bias resistance between them, and maybe other features to control amplitude / bias current / transconductance.)
When such an element is wired to a phase-shift network (like the crystal loaded with capacitors), loop gain has a peak at the resonant frequency, and oscillation results.
simulate this circuit – Schematic created using CircuitLab
The typical amplitude of such an oscillator is under a volt (in the "low power" configuration). So, clearly a full logic-level signal is not strictly required to get reliable internal clocking. At least as long as the oscillator is free to do its own thing like this.
What we could do, then, is simply capacitor-couple some external signal to the
XTAL1 pin, and maybe wire a resistor (say 1M or so) between
XTAL2. (Again, there is probably an internal resistor so this may not be required.)
simulate this circuit
This should be effective for even fairly weak signals (100s mV?), but several volts should be quite reliable, and rounded (sinusoidal) waveforms should be as effective as square waves. (Just as long as the waveform doesn't have a double-peaked or multiple-zero-crossings sort of shape; a reasonably clean fundamental with at most square-wave-ish levels of harmonics. Which seems to be fine here.)
Notice the active assumptions:
- Some kind of self-biased transconductance amplifier is present
- High input impedance
- Working amplitude as stated
- Lots of shoulds in here
We can refer to the datasheet to try and check these assumptions:
ATmega328P Datasheet | Microchip
Pages 26-28, use of the internal oscillator is discussed. Likely the Low Power configuration would be best suited: internal gain is likely the highest, i.e. most suitable for small external amplitude. (There should be no reason that an "excessive" input amplitude wouldn't work.)
Possibly the Full Swing mode would also be suitable. I would guess the
XTAL1 input characteristics are similar or identical, and only the
XTAL2 output characteristics differ.
External Clock mode likely has ordinary logic levels (see below), so would not be suitable for lower input amplitudes. Likely the amplifier bias (or amplification at all) is disabled in this mode, so an external bias resistor would be required for capacitor coupling. It isn't stated whether
XTAL2 is active in this mode. (Possibly
CLKO could be used for feedback, but an inverter may be required in case it has noninverting phase. It would be limited to 1x prescaler operation.)
Page 258, input threshold voltage is given:
Evidently, given suitable bias (with AC coupling like so), at least 0.6 VDD peak-to-peak is required. Though that would leave zero noise margin, and a stronger level (say 4V at 5V supply) would be desirable.
XTAL characteristics are given; p.261 gives external clock parameters but they're only timing.
So we don't know actual gain and offset behavior in the oscillator configurations. (Hence, the disclaimer at the top of this post!)
Some supporting information appears in AVR186: Best Practices for the PCB Layout of Oscillators | Microchip, but nothing of substance (we do see acknowledgement of the low (~1V) amplitude). I see no other
XTAL related appnotes listed in the manufacturer's documentation for this part.
XTAL pin capacitances are given nowhere, making it difficult to design a crystal oscillator with this family at all(!). It seems they mean their recommendation seriously: the values are strictly "initial guidelines" and a real design should be evaluated for stability and accuracy over temperature and manufacture variation.
Which, curiously, isn't far from the caution this post opens with -- though we can at least hope that intended operation is the more reliable one, and indeed, little trouble is had with using ~20pF crystals with this family. (At least, that I have heard of...)
For confident design purposes, I would, of course, suggest a more canonical solution: use a 5V oscillator, use a buffer/inverter/level shifter (the AHCT part will do fine), or change the MCU's supply to 3V. (It is quite capable at 3V, but if you have other 5V-required devices, and interfacing them would require more level shifters, that's obviously not a suitable option. It is worth mentioning for completeness.)