Here we are going to establish a communication between an ATmega8 microcontroller and Arduino Uno. The communication established here is UART (Universal Asynchronous Receiver Transmitter) type. It’s serial communication. By this serial communication data can be shared between two controllers, which is a required in various embedded system applications.
In embedded systems we must have basic knowledge about system communications, so for this we are doing this project. In this project we will discuss basic communication system and we will send some data from transmitter to receiver in serial.
In this project ATMEGA8 acts as a TRANSMITTER and ARDUINO UNO acts as a RECECIVER. In serial communication we will send data BIT BY BIT, until a BYTE of data is transferred completely. The data can be of 10bit size but we will keep to 8BITS for now.
Hardware: ATMEGA8, ARDUINO UNO, power supply (5v), AVR-ISP PROGRAMMER, 100uF capacitor (connected across power supply), 1KΩ resistor (two pieces), LED , Button.
Software: Atmel studio 6.1, progisp or flash magic, ARDUINO NIGHTLY.
Circuit Diagram and Explanation
Before we discuss the circuit diagram and programming for transmitter and receiver, we need to understand about the serial communication. The ATMEGA here sends data to the UNO in serial as discussed earlier.
It has other modes of communication like MASTER SLAVE communication, JTAG communication but for easy communication we are choosing RS232. Here we will connect the TXD (Transmitter) PIN of ATMEGA8 to RXD (Receiver) PIN of ARDUINO UNO
The data communication established is programmed to have:
- Eight data bits
- Two stop bits
- No parity check bit
- Baud rate of 9600 BPS(Bits Per Second)
- Asynchronous communication(No clock share between ATMEGA8 and UNO (both have different clock units))
For establishing UART between Arduino Uno and ATMEGA8 we need to program the setting accurately. For this we need to keep the above mentioned parameters same at both ends. In this one acts as TRANSMITTER and other acts as RECEIVER. We will discuss each side settings below.
Now for the RS232 interface, the following features must be satisfied for the TRANSMITTER side (ATMEGA8):
1. The TXD pin (data receiving feature) of first controller must be enabled for TRANSMITTER.
2. Since the communication is serial we need to know whenever the data bye is received, so that we can stop the program until complete byte is received. This is done by enabling a data receive complete interrupt.
3. DATA is transmitted and received to controller in 8bit mode. So two characters will be sent to the controller at a time.
4. There are no parity bits, one stop bit in the data sent by the module.
DARK GREY (UDRE): This bit not set during startup but it is used during working to check whether transmitter is ready to transmit or not. See the program on TRASMITTER SIDE for more details.
VOILET (TXEN): This bit is set for enabling transmitter pin on TRASMITTER SIDE.
YELLOW (UCSZ0, UCSZ1, and UCSZ2): These three bits are used for selecting the number of data bits we are receiving or sending in a single go.
The communication between two SIDES is established as eight bit communication. By matching the communication with table we have, UCSZ0, UCSZ1 to one and UCSZ2 to zero.
ORANGE (UMSEL): This bit is set based on whether the system is communicating asynchronously (both use different clock) or synchronously (both use same clock).