Download presentation
Presentation is loading. Please wait.
1
Electronics and Networks: Dumb things with Wires Week 2: Serial Overview Jonah Brucker-Cohen Matthew Karau Monday 10am - 12pm Trinity College Dublin MSc. Multimedia Systems Spring 2003
2
Serial Overview What is Serial Communication and why do we care? Specifics of Serial Protocol Synchronous Serial Asynchronous Serial Things that “talk” Serial Director Movie + Code Basic Stamp Code Serial Schematics for BS2
3
What is Serial Communication and why do we care? Serial Communication is a communications protocol defined in the RS232-C Standard Serial sends one bit at a time on a physical channel Serial allows us to connect microcontrollers (like BS2, PIC, BX24, etc..) to computers Serial exists both wired (cable) or wireless (sent over radio transmission - FM/AM) Allows for screen to physical interaction with a PC - incoming data can be connected to online inputs/outputs (servers, HTML pages, scripting languages (CGI, ASP, PHP) ) Simple to implement with many benefits
4
Specifics of Serial Protocol Baud Rate - this is the speed of the transmission and is measured in Bits Per Second (BPS) Start bit - first bit sent as “attention” bit. This helps the receiver to know which is the first bit to receive. Data bits - Directly following the start bit, the data bits are sent. A bit value 1 causes the line to go in marking state, the bit value 0 is represented by a space. The least significant bit is always the first bit sent. Parity bit - Used for error detecting purposes, it is possible to add an extra bit to the data word automatically. The transmitter calculates the value of the bit depending on the information sent. The receiver performs the same calculation and checks if the actual parity bit value corresponds to the calculated value. Stop bits - closes the frame with the startbit to make sure the packet is sent correctly. Example: Director talks to the BS2 at 9600bps, 8 data bits, 1 stop bit, 0 Parity
5
Synchronous Serial A clock or trigger signal must be present which indicates the beginning of each transfer Allows for time-sensitive transfer between devices Two devices initially synchronize themselves to each other, and then continually send characters to stay in sync (even if the data is filler) Faster than Asynchronous - because header/footer bits are not required Example: One controller BS2 sends commands to several slave BS2 - all the commands are sent out synchronously to ensure that all BS2s react at the same time and timings
6
Asynchronous Serial Does not require sending idle characters Beginning and end of each packet of data much have start and stop bits Slower, but less processor intensive than synchronous serial All PC Serial ports are asynchronous Example: Most applications use asynchronous serial - used when each device keeps their own time and exchange data at a certain rate
7
Serial Port 9 Pin Connector Male RS232 DB9 Pin Descriptions Direction of signal: 1 - Carrier Detect (CD) (from DCE) Incoming signal 2 - Received Data (RD) 3 - Transmitted Data (TD) 4 -Data Terminal Ready (DTR 5 - Signal Ground Common reference voltage 6 - Data Set Ready (DSR) 7 - Request To Send (RTS) 8 - Clear To Send (CTS) 9 - Ring Indicator (RI) (from DCE)
8
Things that “talk” Serial Computers (Macintosh and PC) - all major programming languages (Lingo, C, C++, Java, VB, C#, etc..) Microcontrollers (BS2, PIC, BX24, etc..) Serial RF modules (send serial over radio waves) Motor Controllers (motormind B, Stepper motors, servo controllers) LCD screens Serial mice, tablets USB to Serial Converters Printers (older models), fax machines GPS modules, Bluetooth Palm Pilot, PocketPC, Mobile Phones, etc..
9
Director Movie + Lingo Breakdown of Lingo Code: Serial Handlers configure This is called in the startmovie and executes once Initializes the SerialXtra.x32 by making an instance(or object) of the port which can then be sent commands in Lingo Example: openXlib "SerialXtra.32" --opens the Xtra set serialobj= new(xtra "SerialXtra", ("COM2")) --initialize the Xtra as port 2 --standard Serial communication parameters SetBaudRate(serialObj,9600) SetDataBits(serialObj,8) SetStopBits(serialObj, 1) SetBufferSize serialObj, 0 checkserial This is called in the exitframe and executes every frame Checks to see what is coming in the serial port from the BS2 send This is called when you want to send a value out the serial port Can be a number, character, or string killport This is called when you stop the movie and kills the instance of the Xtra Open Demo Movie
10
Basic Stamp Code 'Code Example for BS2 Serial Communication 'this program sends and receives a byte of serial data from Director when you press a physical button on pin 9 it sends the state of the pin to Director which then does something and sends back a 1 or 0 'if a 1 comes back, the BS2 then turns on a motor input 9 'make input and variable declarations incoming var byte main: serout 10, 16468, [in9] 'send out the state of the button serin 11, 16468, [incoming] 'check for serial input debug ?incoming 'check in the debug window for incoming value if incoming = 1 then motoron 'if the value is 1, turn on motor goto main motoron: high 6 'turn on a motor on pin 6 goto main
11
Serial Schematics - BS2 Serial Schematic For Basic Stamp 2 To PC: This schematic has an LED - pin 8 Serin -pin 6 Serout- pin 7
Similar presentations
© 2024 SlidePlayer.com Inc.
All rights reserved.