Serial
Communication:
· serial communication uses single data line making it much cheaper
· enables two computers in different cities to communicate over the telephone
· byte of data must be converted to serial bits using a parallel-in-serial-out shift register and transmitted over a single data line
· receiving end there must be a serial-in-parallel-out shift register
· if transferred on the telephone line, it must be converted to audio tones by modem
· for short distance the signal can be transferred using wire
· how PC keyboards transfer data to the motherboard
· 2 methods, asynchronous and synchronous
· synchronous method transfers a block of data (characters) at a time
· asynchronous method transfers a single byte at a time
· Uses special IC chips called UART (universal asynchronous receiver-transmitter) and USART (universal synchronous asynchronous receiver-transmitter)
· Half- and full-duplex transmission
· if the data can be transmitted and received, it is a duplex transmission
· simplex transmissions the computer only sends data
· duplex transmissions can be half or full duplex
· depends on whether or not the data transfer can be simultaneous
· If one way at a time, it is half duplex
· If can go both ways at the same time, it is full duplex
· full duplex requires two wire conductors for the data lines (in addition to the signal ground)
Asynchronous serial communication and data framing
· data coming in 0s and 1s
· to make sense of the data sender and receiver agree on a set of rules
· Protocol
· how the data is packed
· how many bits/character
· when the data begins and ends
· Start and stop bits
· asynchronous method, each character is placed between start and stop bits
· called framing
· start bit is always one bit
· stop bit can be one or two bits
· start bit is always a 0 (low)
· stop bit(s) is 1 (high)
· LSB is sent out first
· in modern PCs one stop bit is standard
· when transferring a text file of ASCII characters using 1 stop bit there
is total of 10 bits for each character
· 8 bits for the ASCII code (1 parity bit), 1 bit each for the start and
stop bits
· for each 8-bit character there are an extra 2 bits, which gives 20%
overhead
Data transfer rate
· rate of data transfer bps (bits per
second)
· widely used terminology for bps is baud rate
· baud and bps rates are not necessarily equal
· baud rate is defined as the number of signal changes per second
RS232 standards
· most widely used serial I/O interfacing standard
· input and output voltage levels are not TTL compatible
· 1 bit is represented by -3 to -25 V
· 0 bit is +3 to +25 V
· -3 to +3 is undefined
· to connect RS232 to a microcontroller system must use voltage converters
such as MAX232 to convert the TTL logic levels to the RS232 voltage levels, and
vice versa
· MAX232 IC chips are commonly referred to as line drivers
·
· DTE (data terminal equipment)
· DCE (data communication equipment)
· DTE - terminals and computers that send and receive data
· DCE - communication equipment responsible for transferring the data
· simplest connection between a PC and microcontroller requires a minimum
of three pins, TxD, RxD, and ground
· Examining RS232 handshaking signals
· many of the pins of the RS-232 connector are used for handshaking
signals
· they are not supported by the 8051 UART chip
· PC/compatible COM ports
· PC/compatible computers (Pentium) microprocessors normally have two COM
ports
· both ports have RS232-type connectors
· COM ports are designated as COM 1 and COM 2 (replaced by USB ports)
· can connect the AVR serial port to the COM 2 port
LPC21 CONNECTION TO RS232:
· RxD and TxD pins in the ARM Cortex
· LPC2148 has two pins used for transferring and receiving data serially
· TxD and RxD are part of the port 3 group
· these pins are TTL compatible
· require a line driver to make them RS232 compatible
· driver is the MAX232 chip
· MAX232
· converts from RS232 voltage levels to TTL voltage levels
· uses a +5 V power source
· MAX232 has two sets of line drivers for transferring and receiving data
· line drivers used for TxD are called T1 and T2
· line drivers for RxD are designated as R1 and R2
· T1 and R1 are used together for TxD and RxD of the AVR
· second set is left unused
· MAX233
· MAX233 performs the same job as the MAX232
· eliminates the need for capacitors
· much more expensive than the MAX232
ARM CORTEX SERIAL PORT PROGRAMMING IN C:
Ex1(a):
Write a program to transfer letter "GOD BLESS YOU " serially at 9600 baud, continuously.
// Smpl_UART0 : while loop for UART0-TX keep transmitting 8 bytes string
// : IRQ routine for UART0-RX keep receiving 8 bytes string & print to LCD
// : need two learning board to perform UART communication (TX & RX at the same time)
//
// Nu-LB-NUC140
// pin32 GPB0/RX0 to another board's UART TX
// pin33 GPB1/TX0 to another board's UART RX
#include "NUC1xx.h"
#include "GPIO.h"
#include "SYS.h"
#include "UART.h"
void txstring(uint8_t *str)
{
while(*str)
{
DrvUART_Write(UART_PORT0,str,1);
DrvSYS_Delay(100000);
str++;
}
}
int main()
{
STR_UART_T myuart;
DrvGPIO_InitFunction(E_FUNC_UART0);
DrvGPIO_Open(E_GPC,12,E_IO_OUTPUT);
DrvGPIO_Open(E_GPC,13,E_IO_OUTPUT);
DrvGPIO_SetBit(E_GPC,12);
DrvGPIO_SetBit(E_GPC,13);
/* UART Setting */
myuart.u32BaudRate = 9600;
myuart.u8cDataBits = DRVUART_DATABITS_8;
myuart.u8cStopBits = DRVUART_STOPBITS_1;
myuart.u8cParity = DRVUART_PARITY_NONE;
myuart.u8cRxTriggerLevel= DRVUART_FIFO_1BYTES;
/* Set UART Configuration */
if(DrvUART_Open(UART_PORT0,&myuart) != E_SUCCESS)
DrvGPIO_ClrBit(E_GPC,12);
while(1)
{
txstring("GOD BLESS YOU");
}
}
Ex2:
Program the AVR to receive bytes of data serially and put them on LCD. Set the baud rate at 9600, 8-bit data, and 1 stop bit.
//
// Smpl_UART0 : while loop for UART0-TX keep transmitting 8 bytes string
// : IRQ routine for UART0-RX keep receiving 8 bytes string & print to LCD
// : need two learning board to perform UART communication (TX & RX at the same time)
//
// Nu-LB-NUC140
// pin32 GPB0/RX0 to another board's UART TX
// pin33 GPB1/TX0 to another board's UART RX
#include "NUC1xx.h"
#include "GPIO.h"
#include "SYS.h"
#include "UART.h"
void txstring(uint8_t *str)
{
while(*str)
{
DrvUART_Write(UART_PORT0,str,1);
DrvSYS_Delay(100000);
str++;
}
}
int main()
{
uint8_t ch;
//unsigned char ch;
STR_UART_T myuart;
DrvGPIO_InitFunction(E_FUNC_UART0);
DrvGPIO_Open(E_GPC,12,E_IO_OUTPUT);
DrvGPIO_Open(E_GPC,13,E_IO_OUTPUT);
DrvGPIO_SetBit(E_GPC,12);
DrvGPIO_SetBit(E_GPC,13);
/* UART Setting */
myuart.u32BaudRate = 9600;
myuart.u8cDataBits = DRVUART_DATABITS_8;
myuart.u8cStopBits = DRVUART_STOPBITS_1;
myuart.u8cParity = DRVUART_PARITY_NONE;
myuart.u8cRxTriggerLevel= DRVUART_FIFO_1BYTES;
/* Set UART Configuration */
if(DrvUART_Open(UART_PORT0,&myuart) != E_SUCCESS)
DrvGPIO_ClrBit(E_GPC,12);
while(1)
{
txstring("waiting of data");
//txstring("\n\n");
while(DrvUART_Read(UART_PORT0,&ch,1)!=E_SUCCESS);
DrvSYS_Delay(100000);
DrvUART_Write(UART_PORT0,&ch,1);
//DrvUART_Write(UART_PORT0,&ch,1);
txstring(&ch);
}
}
0 comments:
Post a Comment
if you have any doubt please let me know