Atmega328
for this week i will design a new board using atmega328 because it has more pins, and it will be usefull for my final project check the datasheet for more information about it.
microchip parametric
Designing New board using Kicad
In this section i will not go through all details on how to make new boards because i already did that in Electronic Design Week, so here i will go through the steps.
Step 1: Add the component
Start by adding Electronic commpnnet of your board in the schematic Editor,
- Atmega328au
- 100nf
- 2 X 10uf
- 1uf
- FTDI connetor
- 3 X 3-Pin-Male-Connector
- 2 X 2=Pin-Male-Connector
- AVR ISP SMD
- 10Kohm Resistor
- 100 ohm Resistor
- 2 * 1Kohm Resistor
- 20 mhz Crystal
- SMD Push Button
Step 2 : Connect them
in this step you need to connect the component together with atmega328 pins,
Step 3 : Annotate schematic
in this step you need to annotate the component or click on the Annotate button to do the annotation. The annotator automatically replaced the question marks with numbers so that each component has a unique designator.
Step 4: Assign footprint
Unlike other PCB design tools, in Kicad, schematic components are not automatically linked to a footprint. This of a footprint as the outline of a component that is mounted on a circuit board. It contains the outline of the pins, the device, and often text markings with the name of the device or its values
Step 5: Generate netlist
click on Generate to generate the Netlist file. Next, choose the location for the exported file to be saved
Step 6: load netlist in pcp layot
choose the file that you saved in step 5 and loaded into pcp layot
Step 7 : connect Traces
in this step you need to connect the traces of the component.
Step 8: Gnd Fill Traces
Fill the empty spaces with copper and let it be connected to all GND pins,
Step 9: Export as svg
Export the board as svg
Generate tool path
Go to Mods and generate a toolpath depend on the milling machine you have
for this week i was planning to mill my atmega328 board in the lab and use it in this assignment, but one of the staff got infected with covid19 and they had to close the workshop tell everyone doing the covid test, plus we had here in saudi arabia a Eid vacation start from next week.
- so i have decided to complete this assignment with what
- i have Attiny85 that i can use it with breadboard
- and i have the board that i made during electronic Design week and INPUT week
Serial Communication
Serial communication is the most widely used approach to transfer information between data processing equipment and peripherals. I
serial protocol.
The protocol is the secure and reliable form of communication having a set of rules addressed by the source host (sender) and destination host (receiver). To have a better insight, I have explained the concept of serial communication.
In embedded system
In embedded system Serial communication is the way of exchanging data using different methods in the form of serial digital binary. Some of the well-known interfaces used for the data exchange are RS-232, RS-485, I2C, SPI etc.
Data in Serial Communication
In serial communication, data is in the form of binary pulses. In other words, we can say Binary One represents a logic HIGH or 5 Volts, and zero represents a logic LOW or 0 Volts. Serial communication can take many forms depending on the type of transmission mode and data transfer. The transmission modes are classified as Simplex, Half Duplex, and Full Duplex. There will be a source (also known as a sender) and destination (also called a receiver) for each transmission mode.
-
Simplex method is a one-way communication technique. Only one client (either the sender or receiver is active at a time). If a sender transmits, the receiver can only accept. Radio and Television transmission are the examples of simplex mode.
-
Half Duplex mode, both sender and receiver are active but not at a time, i.e. if a sender transmits, the receiver can accept but cannot send and vice versa. A good example is an internet. If a client (laptop) sends a request for a web page, the web server processes the application and sends back the information.
-
Full Duplex mode is widely used communication in the world. Here both sender and receiver can transmit and receive at the same time. An example is your smartphone.
Serial Vs Parallel
Data transfer can happen in two ways. They are serial communication and parallel communication.
- Serial Communication Serial communication is a technique used to send data bit by bit using a two-wires i.e. transmitter (sender) and receiver.these require fewer I/O (input-output) lines. Hence, occupying less space and more resistant to cross-talk. The main advantage of serial communication is, the cost of the entire embedded system becomes cheap and transmits the information over a long distance. Serial transfer is used in DCE (Data communication Equipment) devices like a modem.
From the above diagram, for every clock pulse; the transmitter sends a single bit of data to the receiver.
- Parallel communication In parallel communication, a chunk of data (8,16 or 32 bit) is sent at a time. So, each bit of data requires a separate physical I/O line. The advantage of parallel communication is it is fast but its drawback is it use more number of I/O (input-output) lines. Parallel transfer is used in PC (personal computer) for interconnecting CPU (central processing unit), RAM (random access memory), modems, audio, video and network hardware.
Clock Synchronization
For efficient working of serial devices, the clock is the primary source. Malfunction of the clock may lead to unexpected results. The clock signal is different for each serial device, and it is categorized as synchronous protocol and asynchronous protocol.
-
Synchronous serial interface All the devices on Synchronous serial interface use the single CPU bus to share both clock and data. Due to this fact, data transfer is faster. The advantage is there will be no mismatch in baud rate. Moreover, fewer I/O (input-output) lines are required to interface components. Examples are I2C, SPI etc.
-
Asynchronous serial interface
The asynchronous interface does not have an external clock signal, and it relies on four parameters namely
Baud rate control Data flow control Transmission and reception control Error control.
1 What is Baud rate?
Baud rate is the speed of transferring data from the transmitter to a receiver in the form of bits per second. Some of the standard baud rates are 1200, 2400, 4800, 9600, 57600.
Note:
The Higher a baud rate, more data can be transferred in less amount of time.
You have to set the same baud rate on both Master and Clint’s
2 Framing
Framing shows how many data bits you want to send from the host device (Laptop) to mobile (receiver). Is it 5, 6, 7, or 8 bits? Mostly many devices, 8 bits are preferred. After selecting the8-bit data chunk, endianness has to be agreed by the sender and receiver.
3 Synchronization
Transmitter appends synchronization bits (1 Start bit and 1 or 2 Stop bit) to the original data frame. Synchronization bits help the receiver to identify the start and end of the data transfer. This process is known as asynchronous data transfer.
4 Error Control
Data corruption may happen due to external noise at the receiver end. The only solution to get the stable output is to check the Parity.
If the binary data contains an even number of 1’s it is known as even parity and the Parity bit is set to ‘1’. If the binary data include an odd number of 1’s, it is called odd parity, and now parity bit is set to ‘0’.
Asynchronous Serial Protocols
The most common question that will come to mind when you start working on the embedded system is why to use Asynchronous protocols?
- To move around the information at a longer distance and
- For more reliable data transfer.
Some of the asynchronous communication protocols are:
RS-232 protocol
- RS232 is the first serial protocol used for connecting modems for telephony. RS stands for Recommended Standard, and now it has changed to EIA (Electronic Industries Alliance ) / TIA ( Telecommunication Industry Association).
- It is also used in modem, mouse, and CNC (computed numerical computing) machines. You can connect only a single transmitter to a single receiver.
- It supports full duplex communication and allows baud rate up to 1Mbps.
- Cable length is limited to 50 feet
RS422 Interface
We can transfer data only up to 1Mpbs limit using RS232. To overcome this problem RS422 comes into the picture. RS422 is a multi-drop serial interface. we can connect ten transmitters to 10 receivers at a time using the single bus. It sends data using two twisted pair cables ( differential configuration). Cable length is 4000 feet with a baud rate of 10Mbps.
RS485 Interface
RS485 is the industry preferred protocol. Unlike RS422, you can connect 32 line drivers and 32 receivers in a differential configuration. The transmitter is also called Line driver. However, only one transmitter is active at a time.
Note: For both RS232 and RS485, you have to terminate the connection manually.
programming
After understanding how serial communication work, its time to apply our understanding practically. to do that i have started with Hello Serial Bus - Using C Tutorial i used the example hello.bus.45.c that was in the tutorial and made a modification
- for the bridge i didn’t have to change anything because the example matches the pin number i am using, and the node number is zero ( 0 )
- for the nodes i changed the pin number to match my boards , and changed the node id
Opened the serial monitor
then connect TX and RX of the Arduino here what you have to do
- open serial monitor,
- Enter number of the node into serial monitor - press “enter”
- The node name (ex: node 1) should echo in on the serial monitor and the LED on the board that was flashed with the node id of 1 should flash.
Alternately- If you don’t have / want to use the Arduino IDE,
- After flashing boards with 3 different node numbers:
- Download term.py(righ click save as)
- Run term.py
In Ubuntu this is:
The node name (ex: node 1) should echo in on the serial monitor and the LED on the board that was flashed with the node id of 1 should flash.
Attiny85
-
My first try was with attiny85, i made three bread boards of it, and then connected it with arduino serial monitor, it did worked
-
but as you see in the picture above its kind of missy connection and its hard to even explain the wiring happening here, so i have decided to redo it again with attiny45 and the board that i did in the previous weeks
Attiny45
- the Board that i will use as bridge is the one i designed during INPUT week
- and for the Nodes i used the board that i designed during electronic Design week ,
- And found one of the boards that has some traces can be fixed, so i fixed the traces by soldering jumper wire to complete the circuit, and used it
- So i end up with having 1 bridge and 2 nodes
Then i uploaded the files to the boards and connected the arduino TX , RX to bridge
Opened the serial monitor
after Connecting TX and RX of the Arduino here what you have to do
- open serial monitor,
- Enter number of the node into serial monitor - press “enter”
- The node name (ex: node 1) should echo in on the serial monitor and the LED on the board that was flashed with the node id of 1 should flash.