UART - Indian Institute of Technology Kanpur · Serial.print(val, format) Prints data to the serial...
Transcript of UART - Indian Institute of Technology Kanpur · Serial.print(val, format) Prints data to the serial...
![Page 1: UART - Indian Institute of Technology Kanpur · Serial.print(val, format) Prints data to the serial port as human-readable ASCII text. Serial.flush() Waits for the transmission of](https://reader033.fdocuments.net/reader033/viewer/2022050601/5fa8e0198cb1191a6a373964/html5/thumbnails/1.jpg)
R U D R A P R A T A P S U M A N
UART
![Page 2: UART - Indian Institute of Technology Kanpur · Serial.print(val, format) Prints data to the serial port as human-readable ASCII text. Serial.flush() Waits for the transmission of](https://reader033.fdocuments.net/reader033/viewer/2022050601/5fa8e0198cb1191a6a373964/html5/thumbnails/2.jpg)
UART: Universal Asynchronous Receiver Transmitter
UART is a simple half-duplex, asynchronous, serial protocol.
Simple communication between two equivalent nodes.
Any node can initiate communication.
Since connection is half-duplex, the two lanes of communication are completely independent.
![Page 3: UART - Indian Institute of Technology Kanpur · Serial.print(val, format) Prints data to the serial port as human-readable ASCII text. Serial.flush() Waits for the transmission of](https://reader033.fdocuments.net/reader033/viewer/2022050601/5fa8e0198cb1191a6a373964/html5/thumbnails/3.jpg)
UART: Universal Asynchronous Receiver Transmitter
What makes it ‘universal’ ?
Its parameters (format,speed ..) are configurable.
Why ‘asynchronous’ ?
It doesn’t have a clock
![Page 4: UART - Indian Institute of Technology Kanpur · Serial.print(val, format) Prints data to the serial port as human-readable ASCII text. Serial.flush() Waits for the transmission of](https://reader033.fdocuments.net/reader033/viewer/2022050601/5fa8e0198cb1191a6a373964/html5/thumbnails/4.jpg)
UART Basics
Baud Rate:
No. of bits transmitted/received per second = _____bits/sec.
Format of Communication
![Page 5: UART - Indian Institute of Technology Kanpur · Serial.print(val, format) Prints data to the serial port as human-readable ASCII text. Serial.flush() Waits for the transmission of](https://reader033.fdocuments.net/reader033/viewer/2022050601/5fa8e0198cb1191a6a373964/html5/thumbnails/5.jpg)
UART Basics
Connections for UART
![Page 6: UART - Indian Institute of Technology Kanpur · Serial.print(val, format) Prints data to the serial port as human-readable ASCII text. Serial.flush() Waits for the transmission of](https://reader033.fdocuments.net/reader033/viewer/2022050601/5fa8e0198cb1191a6a373964/html5/thumbnails/6.jpg)
UART Basics
Connections for UART
![Page 7: UART - Indian Institute of Technology Kanpur · Serial.print(val, format) Prints data to the serial port as human-readable ASCII text. Serial.flush() Waits for the transmission of](https://reader033.fdocuments.net/reader033/viewer/2022050601/5fa8e0198cb1191a6a373964/html5/thumbnails/7.jpg)
UART Basics
Connections for UART
![Page 8: UART - Indian Institute of Technology Kanpur · Serial.print(val, format) Prints data to the serial port as human-readable ASCII text. Serial.flush() Waits for the transmission of](https://reader033.fdocuments.net/reader033/viewer/2022050601/5fa8e0198cb1191a6a373964/html5/thumbnails/8.jpg)
UART Basics
Connections for UART
![Page 9: UART - Indian Institute of Technology Kanpur · Serial.print(val, format) Prints data to the serial port as human-readable ASCII text. Serial.flush() Waits for the transmission of](https://reader033.fdocuments.net/reader033/viewer/2022050601/5fa8e0198cb1191a6a373964/html5/thumbnails/9.jpg)
UART Characteristics
The speed of communication (measured in bauds) is predetermined 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.
![Page 10: UART - Indian Institute of Technology Kanpur · Serial.print(val, format) Prints data to the serial port as human-readable ASCII text. Serial.flush() Waits for the transmission of](https://reader033.fdocuments.net/reader033/viewer/2022050601/5fa8e0198cb1191a6a373964/html5/thumbnails/10.jpg)
Parity Bit
•Parity bit is HIGH when number of 1’s in the Data is odd.
•Respectively, it is LOW when number of 1’s in the Data is even
![Page 11: UART - Indian Institute of Technology Kanpur · Serial.print(val, format) Prints data to the serial port as human-readable ASCII text. Serial.flush() Waits for the transmission of](https://reader033.fdocuments.net/reader033/viewer/2022050601/5fa8e0198cb1191a6a373964/html5/thumbnails/11.jpg)
UART in AtMega16
![Page 12: UART - Indian Institute of Technology Kanpur · Serial.print(val, format) Prints data to the serial port as human-readable ASCII text. Serial.flush() Waits for the transmission of](https://reader033.fdocuments.net/reader033/viewer/2022050601/5fa8e0198cb1191a6a373964/html5/thumbnails/12.jpg)
Connecting AtMega16’s with UART
![Page 13: UART - Indian Institute of Technology Kanpur · Serial.print(val, format) Prints data to the serial port as human-readable ASCII text. Serial.flush() Waits for the transmission of](https://reader033.fdocuments.net/reader033/viewer/2022050601/5fa8e0198cb1191a6a373964/html5/thumbnails/13.jpg)
MAX-232 and USB-Serial
![Page 14: UART - Indian Institute of Technology Kanpur · Serial.print(val, format) Prints data to the serial port as human-readable ASCII text. Serial.flush() Waits for the transmission of](https://reader033.fdocuments.net/reader033/viewer/2022050601/5fa8e0198cb1191a6a373964/html5/thumbnails/14.jpg)
Connecting AtMega16 with Computer
Latest Direct Way :
![Page 15: UART - Indian Institute of Technology Kanpur · Serial.print(val, format) Prints data to the serial port as human-readable ASCII text. Serial.flush() Waits for the transmission of](https://reader033.fdocuments.net/reader033/viewer/2022050601/5fa8e0198cb1191a6a373964/html5/thumbnails/15.jpg)
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
![Page 16: UART - Indian Institute of Technology Kanpur · Serial.print(val, format) Prints data to the serial port as human-readable ASCII text. Serial.flush() Waits for the transmission of](https://reader033.fdocuments.net/reader033/viewer/2022050601/5fa8e0198cb1191a6a373964/html5/thumbnails/16.jpg)
Where do we code.. ?
![Page 17: UART - Indian Institute of Technology Kanpur · Serial.print(val, format) Prints data to the serial port as human-readable ASCII text. Serial.flush() Waits for the transmission of](https://reader033.fdocuments.net/reader033/viewer/2022050601/5fa8e0198cb1191a6a373964/html5/thumbnails/17.jpg)
Where do we code.. ?
![Page 18: UART - Indian Institute of Technology Kanpur · Serial.print(val, format) Prints data to the serial port as human-readable ASCII text. Serial.flush() Waits for the transmission of](https://reader033.fdocuments.net/reader033/viewer/2022050601/5fa8e0198cb1191a6a373964/html5/thumbnails/18.jpg)
Where do we code.. ?
![Page 19: UART - Indian Institute of Technology Kanpur · Serial.print(val, format) Prints data to the serial port as human-readable ASCII text. Serial.flush() Waits for the transmission of](https://reader033.fdocuments.net/reader033/viewer/2022050601/5fa8e0198cb1191a6a373964/html5/thumbnails/19.jpg)
Sample Code for UART
Input MCU LCD MCU // a is a char variable a = getchar(); a = inputFromUser(); // Program will wait for data putchar(a); // Data transmitted, now print printChar(a);
![Page 21: UART - Indian Institute of Technology Kanpur · Serial.print(val, format) Prints data to the serial port as human-readable ASCII text. Serial.flush() Waits for the transmission of](https://reader033.fdocuments.net/reader033/viewer/2022050601/5fa8e0198cb1191a6a373964/html5/thumbnails/21.jpg)
Coding for Arduino
Serial.begin(speed) Sets the data rate in bits per second (baud) for serial data
transmission.
![Page 22: UART - Indian Institute of Technology Kanpur · Serial.print(val, format) Prints data to the serial port as human-readable ASCII text. Serial.flush() Waits for the transmission of](https://reader033.fdocuments.net/reader033/viewer/2022050601/5fa8e0198cb1191a6a373964/html5/thumbnails/22.jpg)
Coding for Arduino
Serial.begin(speed) Sets the data rate in bits per second (baud) for serial data
transmission.
Serial.end() Disables serial communication, allowing the RX and TX pins to be
used for general input and output.
To re-enable serial communication, call Serial.begin().
![Page 23: UART - Indian Institute of Technology Kanpur · Serial.print(val, format) Prints data to the serial port as human-readable ASCII text. Serial.flush() Waits for the transmission of](https://reader033.fdocuments.net/reader033/viewer/2022050601/5fa8e0198cb1191a6a373964/html5/thumbnails/23.jpg)
Coding for Arduino
Serial.begin(speed) Sets the data rate in bits per second (baud) for serial data
transmission.
Serial.end() Disables serial communication, allowing the RX and TX pins to be
used for general input and output.
To re-enable serial communication, call Serial.begin().
Serial.read() Reads incoming serial data
![Page 24: UART - Indian Institute of Technology Kanpur · Serial.print(val, format) Prints data to the serial port as human-readable ASCII text. Serial.flush() Waits for the transmission of](https://reader033.fdocuments.net/reader033/viewer/2022050601/5fa8e0198cb1191a6a373964/html5/thumbnails/24.jpg)
Coding for Arduino
Serial.begin(speed) Sets the data rate in bits per second (baud) for serial data
transmission.
Serial.end() Disables serial communication, allowing the RX and TX pins to be
used for general input and output.
To re-enable serial communication, call Serial.begin().
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 newline character (ASCII 10, or '\n')
![Page 25: UART - Indian Institute of Technology Kanpur · Serial.print(val, format) Prints data to the serial port as human-readable ASCII text. Serial.flush() Waits for the transmission of](https://reader033.fdocuments.net/reader033/viewer/2022050601/5fa8e0198cb1191a6a373964/html5/thumbnails/25.jpg)
Coding for Arduino
Serial.print(val) Serial.print(val, format)
Prints data to the serial port as human-readable ASCII text.
![Page 26: UART - Indian Institute of Technology Kanpur · Serial.print(val, format) Prints data to the serial port as human-readable ASCII text. Serial.flush() Waits for the transmission of](https://reader033.fdocuments.net/reader033/viewer/2022050601/5fa8e0198cb1191a6a373964/html5/thumbnails/26.jpg)
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 buffered incoming serial data.)
![Page 27: UART - Indian Institute of Technology Kanpur · Serial.print(val, format) Prints data to the serial port as human-readable ASCII text. Serial.flush() Waits for the transmission of](https://reader033.fdocuments.net/reader033/viewer/2022050601/5fa8e0198cb1191a6a373964/html5/thumbnails/27.jpg)
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 buffered incoming serial data.)
Serial.available()
Get the number of bytes (characters) available for reading from the serial port. This is data that's already arrived and stored in the serial receive buffer (which holds 64 bytes).
![Page 28: UART - Indian Institute of Technology Kanpur · Serial.print(val, format) Prints data to the serial port as human-readable ASCII text. Serial.flush() Waits for the transmission of](https://reader033.fdocuments.net/reader033/viewer/2022050601/5fa8e0198cb1191a6a373964/html5/thumbnails/28.jpg)
Sample Code for Arduino
int incomingByte = 0; // for incoming serial data void setup() { Serial.begin(9600); // opens serial port, sets data rate to 9600 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); } }
![Page 29: UART - Indian Institute of Technology Kanpur · Serial.print(val, format) Prints data to the serial port as human-readable ASCII text. Serial.flush() Waits for the transmission of](https://reader033.fdocuments.net/reader033/viewer/2022050601/5fa8e0198cb1191a6a373964/html5/thumbnails/29.jpg)
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
![Page 30: UART - Indian Institute of Technology Kanpur · Serial.print(val, format) Prints data to the serial port as human-readable ASCII text. Serial.flush() Waits for the transmission of](https://reader033.fdocuments.net/reader033/viewer/2022050601/5fa8e0198cb1191a6a373964/html5/thumbnails/30.jpg)
Coding in DevCPP
![Page 31: UART - Indian Institute of Technology Kanpur · Serial.print(val, format) Prints data to the serial port as human-readable ASCII text. Serial.flush() Waits for the transmission of](https://reader033.fdocuments.net/reader033/viewer/2022050601/5fa8e0198cb1191a6a373964/html5/thumbnails/31.jpg)
Coding in DevCPP
![Page 32: UART - Indian Institute of Technology Kanpur · Serial.print(val, format) Prints data to the serial port as human-readable ASCII text. Serial.flush() Waits for the transmission of](https://reader033.fdocuments.net/reader033/viewer/2022050601/5fa8e0198cb1191a6a373964/html5/thumbnails/32.jpg)
Coding in DevCPP
![Page 33: UART - Indian Institute of Technology Kanpur · Serial.print(val, format) Prints data to the serial port as human-readable ASCII text. Serial.flush() Waits for the transmission of](https://reader033.fdocuments.net/reader033/viewer/2022050601/5fa8e0198cb1191a6a373964/html5/thumbnails/33.jpg)
Coding in DevCPP
Rx Tx Gnd Vcc
![Page 34: UART - Indian Institute of Technology Kanpur · Serial.print(val, format) Prints data to the serial port as human-readable ASCII text. Serial.flush() Waits for the transmission of](https://reader033.fdocuments.net/reader033/viewer/2022050601/5fa8e0198cb1191a6a373964/html5/thumbnails/34.jpg)
Coding in DevCPP
![Page 35: UART - Indian Institute of Technology Kanpur · Serial.print(val, format) Prints data to the serial port as human-readable ASCII text. Serial.flush() Waits for the transmission of](https://reader033.fdocuments.net/reader033/viewer/2022050601/5fa8e0198cb1191a6a373964/html5/thumbnails/35.jpg)
Coding in DevCPP
![Page 36: UART - Indian Institute of Technology Kanpur · Serial.print(val, format) Prints data to the serial port as human-readable ASCII text. Serial.flush() Waits for the transmission of](https://reader033.fdocuments.net/reader033/viewer/2022050601/5fa8e0198cb1191a6a373964/html5/thumbnails/36.jpg)
Coding in DevCPP
#ifdef __BORLANDC__
#pragma hdrstop // borland specific
#include <condefs.h>
#pragma argsused
USEUNIT("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();
}
![Page 37: UART - Indian Institute of Technology Kanpur · Serial.print(val, format) Prints data to the serial port as human-readable ASCII text. Serial.flush() Waits for the transmission of](https://reader033.fdocuments.net/reader033/viewer/2022050601/5fa8e0198cb1191a6a373964/html5/thumbnails/37.jpg)
Coding in DevCPP
For Including “Tserial.cpp” library.place “Tserial.Cpp “ with your code just place it in same folder where your code is presnt
#ifdef __BORLANDC__
#pragma hdrstop // borland specific
#include <condefs.h>
#pragma argsused
USEUNIT("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();
}
![Page 38: UART - Indian Institute of Technology Kanpur · Serial.print(val, format) Prints data to the serial port as human-readable ASCII text. Serial.flush() Waits for the transmission of](https://reader033.fdocuments.net/reader033/viewer/2022050601/5fa8e0198cb1191a6a373964/html5/thumbnails/38.jpg)
Coding in DevCPP
Object Declaration
#ifdef __BORLANDC__
#pragma hdrstop // borland specific
#include <condefs.h>
#pragma argsused
USEUNIT("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();
}
![Page 39: UART - Indian Institute of Technology Kanpur · Serial.print(val, format) Prints data to the serial port as human-readable ASCII text. Serial.flush() Waits for the transmission of](https://reader033.fdocuments.net/reader033/viewer/2022050601/5fa8e0198cb1191a6a373964/html5/thumbnails/39.jpg)
Coding in DevCPP
Object Creation
#ifdef __BORLANDC__
#pragma hdrstop // borland specific
#include <condefs.h>
#pragma argsused
USEUNIT("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();
}
![Page 40: UART - Indian Institute of Technology Kanpur · Serial.print(val, format) Prints data to the serial port as human-readable ASCII text. Serial.flush() Waits for the transmission of](https://reader033.fdocuments.net/reader033/viewer/2022050601/5fa8e0198cb1191a6a373964/html5/thumbnails/40.jpg)
Coding in DevCPP
Connecting to a serial port
#ifdef __BORLANDC__
#pragma hdrstop // borland specific
#include <condefs.h>
#pragma argsused
USEUNIT("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();
}
![Page 41: UART - Indian Institute of Technology Kanpur · Serial.print(val, format) Prints data to the serial port as human-readable ASCII text. Serial.flush() Waits for the transmission of](https://reader033.fdocuments.net/reader033/viewer/2022050601/5fa8e0198cb1191a6a373964/html5/thumbnails/41.jpg)
Coding in DevCPP
Send Character on Com port
#ifdef __BORLANDC__
#pragma hdrstop // borland specific
#include <condefs.h>
#pragma argsused
USEUNIT("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();
}
![Page 42: UART - Indian Institute of Technology Kanpur · Serial.print(val, format) Prints data to the serial port as human-readable ASCII text. Serial.flush() Waits for the transmission of](https://reader033.fdocuments.net/reader033/viewer/2022050601/5fa8e0198cb1191a6a373964/html5/thumbnails/42.jpg)
Coding in DevCPP
Don’t forget to disconnect Com port
#ifdef __BORLANDC__
#pragma hdrstop // borland specific
#include <condefs.h>
#pragma argsused
USEUNIT("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();
}
![Page 43: UART - Indian Institute of Technology Kanpur · Serial.print(val, format) Prints data to the serial port as human-readable ASCII text. Serial.flush() Waits for the transmission of](https://reader033.fdocuments.net/reader033/viewer/2022050601/5fa8e0198cb1191a6a373964/html5/thumbnails/43.jpg)
Coding in DevCPP
#ifdef __BORLANDC__
#pragma hdrstop // borland specific
#include <condefs.h>
#pragma argsused
USEUNIT("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();
}
![Page 44: UART - Indian Institute of Technology Kanpur · Serial.print(val, format) Prints data to the serial port as human-readable ASCII text. Serial.flush() Waits for the transmission of](https://reader033.fdocuments.net/reader033/viewer/2022050601/5fa8e0198cb1191a6a373964/html5/thumbnails/44.jpg)
Coding in DevCPP
For More Details
http://www.tetraedre.com/advanced/serial/index.html
![Page 45: UART - Indian Institute of Technology Kanpur · Serial.print(val, format) Prints data to the serial port as human-readable ASCII text. Serial.flush() Waits for the transmission of](https://reader033.fdocuments.net/reader033/viewer/2022050601/5fa8e0198cb1191a6a373964/html5/thumbnails/45.jpg)
Opening Com Port
Python
Matlab
JAVA
C Lang
![Page 46: UART - Indian Institute of Technology Kanpur · Serial.print(val, format) Prints data to the serial port as human-readable ASCII text. Serial.flush() Waits for the transmission of](https://reader033.fdocuments.net/reader033/viewer/2022050601/5fa8e0198cb1191a6a373964/html5/thumbnails/46.jpg)
Thank You Question??