Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Session 5

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 31

SPIDER

presents

µ-CON
Session 5

Featuring TI’s MSP430


launch pad
Types of Serial communication

Asynchronous (UART) Synchronous (USART)

• Has no clock line. • Has a clock line which


• Transfers data bit by bit. synchronizes reading and writing
• Requires a start bit and a stop operations.
bit. • Transfers data as a block.
• Also both sides have to agree
on a common transmission rate.
• Conforms with RS232 standards
and is also called RS232
communication.
Serial Parallel
Data is transmitted one bit at a Whole data unit, say a byte
time (8bits) is transmitted at once.

Only one wire is used for data No of wires is same as number


transfer of bits in Data Unit
Medium Range Short Range Communication,
Communication, Slow speeds Fast speeds
Used for connecting external Used to connect components
peripherals like mice, to motherboard like RAM,
keyboards graphics card where speed
matters
A Serial Line.(HIGH=RED & LOW=WHITE)

Logic level changes according to bit being


transmitted (0 or 1)
Is it possible to make out the received
data?
Now if we add another line called the clock line to
synchronize the signal, then it becomes easy.

You need to note down the value of data line only when you
see the "clock line" high.
Baud rate=9600 bits per second 1/9600 =104 µsec
•This is Universal Synchronous Receiver and Transmitter ( USART )

•So USART has clock line

•UART - Universal Asynchronous Receiver Transmitter

•In UART, a start bit and stop bits are used to synchronize the
incoming data line
•As there is no "clock" line so for synchronization accurate timing is
required so transmissions are carried out with certain standard speeds.

•The speeds are measured in bits per second. Number of bits


transmitted is also known as baud rate.

•Some standard baud rates are1200,2400,4800,9600,19200 ... etc

•To transmit a single byte we need to extra bits they are START BIT
AND STOP BIT.

•BITS are transmitted as a packet of 7 or 8 bits ( ASCII code )


RS 232 LOGIC : HIGH -12V
LOW +12V

TTL LOGIC HIGH 3.3V


LOW 0V
So we need a interface to compensate this
mismatch.

This interface is provided by a IC called


MAX232.

In MSP430, all of the circuitry needed to do


this is included in the Flash Emulation tool
portion of the Launchpad.
•Half duplex
•Types of UART available :
1. Hardware
2. Software

•Receiving and Transmission Functions


•Need for Interrupts.
APPLICATIONS OF UART

• Found in your motherboard/modem.


• Old computers, that had 8 bit parallel architecture
used UART to communicate with external devices
such as printers, etc. This is because serial has only
one wire for each direction of flow.
• Used in conjunction with existing communication
standards such as RS-232.
• RS232 was intended as a short distance, moderately
low speed (9600 bps usual) and one device per port
(exceptions proving the rule). Now USB rules the
roost, with high speed and full standardization.
• UART holds a prime spot in microcontroller-
peripheral communication.
TASKS:

1) Write a code that echoes back the sent


character to the Launchpad.

2) Display a string on the computer on


pressing a switch.
#include "msp430g2553.h"

void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
P1SEL = BIT1 + BIT2 ; // P1.1 = RXD, P1.2=TXD
P1SEL2 = BIT1 + BIT2 ; // P1.1 = RXD, P1.2=TXD
UCA0CTL1 |= UCSSEL_2; // SMCLK
UCA0BR0 = 104; // 1MHz 9600
UCA0BR1 = 0; // 1MHz 9600
UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state machine**
IE2 |= UCA0RXIE; // Enable USCI_A0 RX interrupt

__bis_SR_register(LPM0_bits + GIE); // Enter LPM0, interrupts


enabled
}

#pragma vector=USCIAB0RX_VECTOR
__interrupt void USCI0RX_ISR(void)
{
while (!(IFG2 & UCA0TXIFG)); // USCI_A0 TX buffer empty?
UCA0TXBUF = UCA0RXBUF; // TX -> RXed character
}
#include<msp430g2553.h>

char string[]="Spider µ-Con Workshop";


int i=0;
void main()
{
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
P1DIR|=BIT0; P1OUT|=BIT3; P1REN|=BIT3;
P1IE|=BIT3; P1IES|=BIT3; P1IFG &= ~BIT3; //Configure P1.3 button
P1SEL=BIT1+BIT2; P1SEL2=BIT1+BIT2; // P1.1 = RXD, P1.2=TXD
UCA0CTL0=0;
UCA0CTL1|=UCSSEL_2; //SMCLK
UCA0BR0=104; //1 MHz = 9600
UCA0BR1=0; //1 MHz = 9600
UCA0CTL1&= ~UCSWRST; // **Initialize USCI state machine**
IE2|=UCA0RXIE; // Enable USCI_A0 RX interrupt
__bis_SR_register(LPM0_bits+GIE);
while(1);
}

#pragma vector=PORT1_VECTOR
__interrupt void Port_1(void)
{ P1OUT ^=BIT0;
P1IFG &= ~BIT3;

while (!(IFG2&UCA0TXIFG));
UCA0TXBUF=string[i++]; //TX->string characters
IFG2 &= ~UCA0TXIFG;
}
This is how a simple program looks like in C.
• c = 2.1 + 3.4
print c (Or just any other arithmetic operation)

•c = “Spider”
print c
print c[0:6]
print c[1:5]
print c[0:6:2]
print c[::-1]
•Extensive support for libraries which make
Python very versatile. You can make websites,
apps or just about anything.
•A strongly typed and easy to understand
interface. For example, variable data types don’t
have to be explicitly specified
•Good community support from users all over the
world. There’ll always be people to help you
debug your code.
Python has while and for loops too.
Although they look a bit different.
•serial : Enables serial data transfer via Python. You
can send and read data using UART.
•win32api and win32con : Allow you to
detect/simulate windows events like key presses,
mouse movement and button presses etc.
•winsound : Allows you to play some sounds from
Python.
•time : Allows for delays to be coded into Python.
 This library has some functions to open a serial
port and read data from the device connected to
that port.
 serial.Serial(‘PORT’,’BAUD’,timeout = x). This
function opens a serial port specified by ‘PORT’
and sets the baud rate to the ‘BAUD’ value. The
timeout value sets the read timeout.
 write(value). This function sends a character to
an opened port.
 Read(). This function reads one byte from an
open port. The user can specify the number of
bytes to be read. The default value is one.
 Range : 2cm – 400cm
 Operates in the 40 Khz ultrasonic
range
 Operating voltage : 4.8v – 5.5v
 Measuring angle : 15 degrees
 It works in a similar fashion to an echo. Initially,
you have to trigger the module (With a 20uS pulse).
After this it sends ultrasonic pulses and records
the time they take to come back. Finally, it sends a
pulse back to the MCU whose width gives an idea
of how far the object is. The distance of the object
can be calculated using this formula.
 D = 0.5 * Speed of Sound * ( t );
 t = smallest measurable time increment in micro
seconds;
 D = 0.5 * 344 * (0.000001) *t = 0.000172
meters=0.0172 centimetres

You might also like