UART EClub IITK
-
Upload
rudra-pratap-suman -
Category
Documents
-
view
234 -
download
0
Transcript of UART EClub IITK
-
7/30/2019 UART EClub IITK
1/46
R U D R A P R ATA P S U M A N
UART
-
7/30/2019 UART EClub IITK
2/46
UART: Universal Asynchronous ReceiverTransmitter
UART is a simple half-duplex, asynchronous, serialprotocol.
Simple communication between two equivalentnodes. Any node can initiate communication.
Since connection is half-duplex, the two lanes of communication are completely independent.
-
7/30/2019 UART EClub IITK
3/46
UART: Universal Asynchronous ReceiverTransmitter
What makes it universal ?Its parameters (format,speed ..) are configurable.
Why asynchronous ?
It doesnt have a clock
-
7/30/2019 UART EClub IITK
4/46
UART Basics
Baud Rate:No. of bits transmitted/received per second = _____bits/sec.
Format of Communication
-
7/30/2019 UART EClub IITK
5/46
UART Basics
Connections for UART
-
7/30/2019 UART EClub IITK
6/46
UART Basics
Connections for UART
-
7/30/2019 UART EClub IITK
7/46
UART Basics
Connections for UART
-
7/30/2019 UART EClub IITK
8/46
UART Basics
Connections for UART
-
7/30/2019 UART EClub IITK
9/46
UART Characteristics
The speed of communication (measured in bauds) ispredetermined on both ends.
A general rule of thumb is to use 9600 bauds for wired communication.UART implements error-detection in the form of parity bit.
-
7/30/2019 UART EClub IITK
10/46
Parity Bit
Parity bit is HIGH when number of 1s in the Datais odd.
Respectively , it is LOW when number of 1s in theData is even
-
7/30/2019 UART EClub IITK
11/46
UART in AtMega16
-
7/30/2019 UART EClub IITK
12/46
Connecting AtMega16s with UART
-
7/30/2019 UART EClub IITK
13/46
MAX-232 and USB-Serial
-
7/30/2019 UART EClub IITK
14/46
Connecting AtMega16 with Computer
Latest Direct Way :
-
7/30/2019 UART EClub IITK
15/46
Coding with UART
Three simple commands : putchar(char);sends 8-bit characters through UART
getchar();receives 8-bit characters via UART
puts(string);
sends a constant string
-
7/30/2019 UART EClub IITK
16/46
Where do we code.. ?
-
7/30/2019 UART EClub IITK
17/46
Where do we code.. ?
-
7/30/2019 UART EClub IITK
18/46
Where do we code.. ?
-
7/30/2019 UART EClub IITK
19/46
Sample Code for UART
Input MCU LCD MCU// a is a char variable a = getchar();a = inputFromUser(); // Program will wait for dataputchar(a); // Data transmitted, now print
printChar(a);
-
7/30/2019 UART EClub IITK
20/46
Coding for Arduino
http://arduino.cc/en/Serial/Begin -
7/30/2019 UART EClub IITK
21/46
Coding for Arduino
Serial.begin(speed)Sets the data rate in bits per second (baud) for serial datatransmission.
http://arduino.cc/en/Serial/Begin -
7/30/2019 UART EClub IITK
22/46
Coding for Arduino
Serial.begin(speed)Sets the data rate in bits per second (baud) for serial datatransmission.
Serial.end()Disables serial communication, allowing the RX and TX pins to beused for general input and output.To re-enable serial communication, call Serial.begi n().
http://arduino.cc/en/Serial/Beginhttp://arduino.cc/en/Serial/Begin -
7/30/2019 UART EClub IITK
23/46
Coding for Arduino
Serial.begin(speed)Sets the data rate in bits per second (baud) for serial datatransmission.
Serial.end()Disables serial communication, allowing the RX and TX pins to beused for general input and output.To re-enable serial communication, call Serial.begi n().
Serial.read()Reads incoming serial data
http://arduino.cc/en/Serial/Beginhttp://arduino.cc/en/Serial/Begin -
7/30/2019 UART EClub IITK
24/46
Coding for Arduino
Serial.begin(speed)Sets the data rate in bits per second (baud) for serial datatransmission.
Serial.end()Disables serial communication, allowing the RX and TX pins to beused for general input and output.To re-enable serial communication, call Serial.begi n().
Serial.read()Reads incoming serial data
Serial.println(val)Serial.println(val, format)Prints data to the serial port as human-readable ASCII text followed by a carriage return character (ASCII 13, or '\r') and a newlinecharacter (ASCII 10, or '\n')
http://arduino.cc/en/Serial/Beginhttp://arduino.cc/en/Serial/Begin -
7/30/2019 UART EClub IITK
25/46
Coding for Arduino
Serial.print(val)Serial.print(val, format)
Prints data to the serial port as human-readable ASCII text.
-
7/30/2019 UART EClub IITK
26/46
Coding for Arduino
Serial.print(val)Serial.print(val, format)
Prints data to the serial port as human-readable ASCII text.
Serial.flush() Waits for the transmission of outgoing serial data to complete.(Prior to Arduino 1.0, this instead removed any bufferedincoming serial data.)
-
7/30/2019 UART EClub IITK
27/46
Coding for Arduino
Serial.print(val)Serial.print(val, format)
Prints data to the serial port as human-readable ASCII text.
Serial.flush() Waits for the transmission of outgoing serial data to complete.(Prior to Arduino 1.0, this instead removed any bufferedincoming serial data.)
Serial.available()Get the number of bytes (characters) available for readingfrom the serial port. This is data that's already arrived andstored in the serial receive buffer (which holds 64 bytes).
-
7/30/2019 UART EClub IITK
28/46
Sample Code for Arduino
int incomingByte = 0; // for incoming serial data void setup() {
Serial.begin(9600); // opens serial port, sets data rate to9600 bps}
void loop() {
// send data only when you receive data:if (Serial.available() > 0) {
// read the incoming byte:
incomingByte = Serial.read();// say what you got:Serial.print("I received: ");Serial.println(incomingByte, DEC);
}}
-
7/30/2019 UART EClub IITK
29/46
Coding in DevCPP
link for downloading DevC++
http://sourceforge.net/projects/dev-cpp/files/Binaries/Dev-
C%2B%2B%204.9.9.2/devcpp-
4.9.9.2_setup.exe/download
http://sourceforge.net/projects/dev-cpp/files/Binaries/Dev-C++%204.9.9.2/devcpp-4.9.9.2_setup.exe/downloadhttp://sourceforge.net/projects/dev-cpp/files/Binaries/Dev-C++%204.9.9.2/devcpp-4.9.9.2_setup.exe/downloadhttp://sourceforge.net/projects/dev-cpp/files/Binaries/Dev-C++%204.9.9.2/devcpp-4.9.9.2_setup.exe/downloadhttp://sourceforge.net/projects/dev-cpp/files/Binaries/Dev-C++%204.9.9.2/devcpp-4.9.9.2_setup.exe/downloadhttp://sourceforge.net/projects/dev-cpp/files/Binaries/Dev-C++%204.9.9.2/devcpp-4.9.9.2_setup.exe/downloadhttp://sourceforge.net/projects/dev-cpp/files/Binaries/Dev-C++%204.9.9.2/devcpp-4.9.9.2_setup.exe/downloadhttp://sourceforge.net/projects/dev-cpp/files/Binaries/Dev-C++%204.9.9.2/devcpp-4.9.9.2_setup.exe/downloadhttp://sourceforge.net/projects/dev-cpp/files/Binaries/Dev-C++%204.9.9.2/devcpp-4.9.9.2_setup.exe/downloadhttp://sourceforge.net/projects/dev-cpp/files/Binaries/Dev-C++%204.9.9.2/devcpp-4.9.9.2_setup.exe/downloadhttp://sourceforge.net/projects/dev-cpp/files/Binaries/Dev-C++%204.9.9.2/devcpp-4.9.9.2_setup.exe/downloadhttp://sourceforge.net/projects/dev-cpp/files/Binaries/Dev-C++%204.9.9.2/devcpp-4.9.9.2_setup.exe/download -
7/30/2019 UART EClub IITK
30/46
Coding in DevCPP
-
7/30/2019 UART EClub IITK
31/46
Coding in DevCPP
-
7/30/2019 UART EClub IITK
32/46
Coding in DevCPP
-
7/30/2019 UART EClub IITK
33/46
Coding in DevCPP
RxTxGnd Vcc
-
7/30/2019 UART EClub IITK
34/46
Coding in DevCPP
-
7/30/2019 UART EClub IITK
35/46
Coding in DevCPP
-
7/30/2019 UART EClub IITK
36/46
Coding in DevCPP
#ifdef __BORLANDC__#pragma hdrstop // borland specific#include #pragma argsusedUSEUNIT("Tserial.cpp");#endif #include "conio.h"#include "Tserial.cpp"
int main(){
Tserial *com;com = new Tserial();com->connect("COM3", 4800, spNONE);com->sendChar('F');com->disconnect();
}
-
7/30/2019 UART EClub IITK
37/46
Coding in DevCPP
For IncludingTserial.cpplibrary.placeTserial.Cpp with your code just placeit in same folder where your code ispresnt
#ifdef __BORLANDC__#pragma hdrstop // borland specific#include #pragma argsusedUSEUNIT("Tserial.cpp");#endif #include "conio.h"#include "Tserial.cpp"
int main(){
Tserial *com;com = new Tserial();com->connect("COM3", 4800, spNONE);com->sendChar('F');com->disconnect();
}
-
7/30/2019 UART EClub IITK
38/46
Coding in DevCPP
Object Declaration
#ifdef __BORLANDC__#pragma hdrstop // borland specific#include #pragma argsusedUSEUNIT("Tserial.cpp");#endif #include "conio.h"#include "Tserial.cpp"
int main(){
Tserial *com;com = new Tserial();com->connect("COM3", 4800, spNONE);com->sendChar('F');com->disconnect();
}
-
7/30/2019 UART EClub IITK
39/46
Coding in DevCPP
Object Creation
#ifdef __BORLANDC__#pragma hdrstop // borland specific#include #pragma argsusedUSEUNIT("Tserial.cpp");#endif #include "conio.h"#include "Tserial.cpp"
int main(){
Tserial *com;com = new Tserial();com->connect("COM3", 4800, spNONE);com->sendChar('F');com->disconnect();
}
-
7/30/2019 UART EClub IITK
40/46
Coding in DevCPP
Connecting to aserial port
#ifdef __BORLANDC__#pragma hdrstop // borland specific#include #pragma argsusedUSEUNIT("Tserial.cpp");#endif #include "conio.h"#include "Tserial.cpp"
int main(){
Tserial *com;com = new Tserial();com->connect("COM3", 4800, spNONE);com->sendChar('F');com->disconnect();
}
-
7/30/2019 UART EClub IITK
41/46
Coding in DevCPP
Send Character on Comport
#ifdef __BORLANDC__#pragma hdrstop // borland specific#include #pragma argsusedUSEUNIT("Tserial.cpp");#endif #include "conio.h"#include "Tserial.cpp"
int main(){
Tserial *com;com = new Tserial();com->connect("COM3", 4800, spNONE);com->sendChar('F');com->disconnect();
}
-
7/30/2019 UART EClub IITK
42/46
Coding in DevCPP
Dont forget todisconnect Com port
#ifdef __BORLANDC__#pragma hdrstop // borland specific#include #pragma argsusedUSEUNIT("Tserial.cpp");#endif #include "conio.h"#include "Tserial.cpp"
int main(){
Tserial *com;com = new Tserial();com->connect("COM3", 4800, spNONE);com->sendChar('F');com->disconnect();
}
-
7/30/2019 UART EClub IITK
43/46
Coding in DevCPP
#ifdef __BORLANDC__#pragma hdrstop // borland specific#include #pragma argsusedUSEUNIT("Tserial.cpp");#endif #include "conio.h"#include "Tserial.cpp"
int main(){
Tserial *com;com = new Tserial();com->connect("COM3", 4800, spNONE);com->sendChar('F');com->disconnect();
}
-
7/30/2019 UART EClub IITK
44/46
Coding in DevCPP
For More Details
http://www.tetraedre.com/advanced/serial/index.html
http://www.tetraedre.com/advanced/serial/index.htmlhttp://www.tetraedre.com/advanced/serial/index.htmlhttp://www.tetraedre.com/advanced/serial/index.htmlhttp://www.tetraedre.com/advanced/serial/index.htmlhttp://www.tetraedre.com/advanced/serial/index.htmlhttp://www.tetraedre.com/advanced/serial/index.html -
7/30/2019 UART EClub IITK
45/46
Opening Com Port
Python
Matlab
JAVA
C Lang
-
7/30/2019 UART EClub IITK
46/46
Thank YouQuestion??