RS232

What is RS232 Protocol?

In RS232, ‘RS’ stands for Recommended Standard. It defines the serial communication using DTE and DCE signals. Here, DTE refers to Data Terminal Equipment and DCE refers to the Data Communication Equipment. Example of DTE device is a computer and DCE is a modem. Formally, it is specified as the interface between DTE equipment and DCE equipment using serial binary data exchange.

RS232 describes the common voltage levels, electrical standards, operation mode and number of bits to be transferred from DTE to DCE. This standard is used for transmission of information exchange over the telephone lines.

Electrical Standards

The electrical specifications for RS232 are updated in the year 1969. It specifies the electrical voltages, slew rate, line impedance, operation mode, and baud rate.

Voltage Levels

The line voltages of RS232 range from -25V to +25V. They are categorized as signal voltage and control voltage.

RS232 Voltage Levels

The signal voltage between +3V to +25V represents logic ‘1’ and the signal voltages between -3V to -25V represents logic ‘0’. Whereas the control voltage signals use negative logic, i.e., logic ‘1’ indicates -3 to -25 volts and logic ‘0’ indicates +3V to +25V. The voltage from -3V to +3V is considered as an indeterminate state

ps:

控制电压:

控制电压则是指在控制线上(如RTS、CTS、DSR、DTR和DCD等)传输的电压,用于控制通信过程中的各种状态和行为。在RS232标准中,控制电压的有效范围通常也是+3V至+15V之间,表示信号的有效状态(ON或接通)。然而,与信号电压不同,控制电压的具体值可能因不同的控制信号和用途而有所差异。

Baud rate:(...)

Communication Interface

RS232 determines the communication between the DTE and DCE using DB9 and DB25

connectors. The D-sub connectors (DB9, DB25) comes with male and female cable. DB9 connector has 9 pins and DB25 connector has 25 pins with each pin having its own function.

DB9 Male and Female Pinouts

DB25 Pinout

Functional Description

Apart from the electrical characteristics, RS232 defined the functions of signals that are used in the serial interface. Some of them are common ground, Data, control and timing signals. Here is a list of signals used in RS232 pinout.

Signal NameFunction
Protective GroundThis signal is connected to chassis ground of metallic connector.
Common GroundZero reference voltage level for all the control signals.
TxD (Transmit Pin)To transmit data from DTE to DCE.
RxD (Receive Pin)Sends data from DCE to DTE.
DTR (Data Terminal Ready)DTE is ready to accept request.
DCD (Data carrier Detect)DCE accepts a carrier from a DTE located at remote location.
DSR (Data Set Ready)DCE is prepared to send and receive the information.
RI (Ring Indicator)Detects the incoming ring tone on the telephone line.
RTS (Request to Send)DTE call for DCE to send the data.
RTR (Ready to Receive)DTE is geared up to receive data coming from DCE.
CTS (Clear To Send)DCE is in a ready state to accept data coming from DTE.

Other than above signals, (primary signals) RS232 provides secondary signals such as secondary DTE, secondary RTS, secondary DCD, secondary TxD and secondary RxD for optional connection of DTE and DCE.

cable:

Protocol Format :

 other:

Why to use Handshaking?

cache... singal...

Difference between RS232 and UART

The main difference between RS232 and UART protocol is the voltage levels. Apart from this, they both supports half duplex and full duplex communication.

Microcontrollers don’t tolerate RS232 voltages and may be damaged. To avoid this, UART (Universal Asynchronous Transmitter Receiver) is used. It sends and receives the data in serial form. To do the level conversion of voltages, RS232 driver IC such as MAX232 is used between the UART and serial port.

 

proteus 模拟  rs232:

前提:由于我们要与本机的串口助手通信,要安装:

安装程序在共享网盘中:

通过网盘分享的文件:我的资源
链接: https://pan.baidu.com/s/1OWzEhGr570lhDL6PayWk6g 提取码: ndxb 
--来自百度网盘超级会员v8的分享

或者自己百度安装破解。

安装完成后:新建一对virtual port:

这时候 在设备管理器能看到这个: 

有了这个神器,我们proteus 就能和本机串行通信了。 

接线图如下:

 

 compim设置如下:

本机串口助手设置:

 

代码:


void setup() {
  // put your setup code here, to run once:
pinMode(0,INPUT);  
Serial.begin(9600);
Serial.println("hello my friend!");
}

void loop() {
  // put your main code here, to run repeatedly:
Serial.println(analogRead(0));
 delay(100);

}

运行效果:

 

 通过RS232发送数据没问题,接受数据呢?

改一下代码:

int led=0;
void setup() {
  // put your setup code here, to run once:
pinMode(0,INPUT);  
Serial.begin(9600);
Serial.println("hello my friend!");
for(int i=13;i>5; i--)
pinMode(i,OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
  int rslt = Serial.read();  
  Serial.println(rslt);
 
  switch(rslt){
  case 0:
  digitalWrite(led+6,HIGH);
  break;
    case 1:
  digitalWrite(led+7,HIGH);
  break;
    case 2:
  digitalWrite(led+8,HIGH);
  break;
    case 3:
  digitalWrite(led+9,HIGH);
  break;
    case 4:
  digitalWrite(led+10,HIGH);
  break;
    case 5:
  digitalWrite(led+11,HIGH);
  break;
    case 6:
  digitalWrite(led+12,HIGH);
  break;
    case 55:
  digitalWrite(led+13,HIGH);
  break;
       
  default:
       
  delay(200);
  break;
      
  } 

接受数据运行效果:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值