I apologize if this has been asked before, but I could only find 1. How to use ATMega without Arduino, and 2. How to use Arduino UNO to program an ATMega for separate use.
What I'm considering is using an Arduino UNO for my project, and also using a separate ATMega328, controlled in real time by the Arduino. Will I still need a crystal, or can the Arduino UNO control the timing of the 328? Has anyone seen any references online? Thanks!
The Atmega 328 is the the processing chip used in the Arduino Uno.
The Uno can be used to program other Atmega328 chips. Using Arduino as an ISP to Program a Standalone ATmega 328P
One Arduino can be used to control another Arduino. I"m not sure what you mean by "controlling the timing" .
I program my standalone Atmega 328s using this tutorial.
This is also a popular article from Nick Gammon.
When you create your standalone ATmega328P circuit and report back in the forum asking about errors or trouble with it, the first thing many of the forum members are going to ask you is "where are your decoupling capacitors?" Those are covered in Nick's article.
Also, consider many people like to use a Pro Mini in the finished project, as they are inexpensive and and small, and already have the support circuitry such as crystal and decoupling caps built-in.
When ordering your processor, I recommend paying attention to the whole part number. Get ATmega328P-PU. Some people order ATmega328-PU and then they end up with the wrong thing. Although you can get it to work, many people struggle with dealing with the different chip signature and getting it to program correctly with the Arduino IDE. ATmega328P-PU is the processor on the Uno.
OK, let me phrase my question more directly:
How do I connect an Arduino UNO and an ATMega328P to work TOGETHER in a project?
The Arduino UNO will be powered optionally by USB or its power jack. The separate ATMega328P will be the slave of the Arduino UNO. Both will be present in the final thing.
I have already seen many of the hundreds of tutorials on using an UNO to program an ATMega328P. I'm not asking how to program the thing, at least not yet. I'm asking how to make the two work together, e.g., assuming I want to run both at 16MHz, can I use the crystal from the UNO to control the separate Mega chip as well, or does it need its own crystal? E.g., how do I set up the ATMega to send serial data to the UNO, or to the same destination as the UNO?
Has anyone tried this?
You can use the same crystal, but that requires the 2 to be very close to each other, and non-standard fuses for at least and possibly both of them. It's a lot easier to give each their own crystal and bootload both as Unos.
I offer a board with dual 328Ps. How you connect them to talk to each other is up you - can be hardware Serial-hardware Serial if you don't need to go offboard to a USB/serial to talk to a PC, can be software serial-software serial, can be SPI master-slave, can be I2C master-slave.