当前位置:网站首页>[carving master learning programming] Arduino hands-on (59) - RS232 to TTL serial port module
[carving master learning programming] Arduino hands-on (59) - RS232 to TTL serial port module
2022-07-24 10:23:00 【Full stack programmer webmaster】
Hello everyone , I meet you again , I'm your friend, Quan Jun .
37 It's about sensors and actuators , It's widely spread on the Internet , Actually Arduino Compatible sensor modules are definitely more than that 37 Species . In view of the fact that I have accumulated some sensor and actuator modules on hand , According to practice come true knowledge ( Do it ) Idea , For the purpose of learning and communication , Here we are going to try a series of experiments one by one , No matter how successful ( Program walk through ) Whether or not , It will be recorded — Small progress or problems that can't be solved , Hope to be able to lead the way .
【Arduino】168 A series of sensor module experiments ( Information + Code + graphics + Simulation )
Experiment 59 : RS232 turn TTL2 Generation serial port module brush board module (MAX3232 chip )
MAX3232 chip
The output stage of proprietary low dropout transmitter is adopted , Using double charge pump in 3.0V to 5.5V The power supply can realize real RS-232 performance , The device only needs four 0.1uF External small size charge pump capacitor .max3232 Make sure that the 120kbps Data rate , Keep at the same time RS-232 Output level .max3232 With two-way receiver and two-way driver , Provide 1uA Off mode , Effectively reduce the efficiency and delay the battery life of portable products . In off mode , The receiver remains active , Monitor external equipment , Consume only 1uA Power supply current ,max3232 The pin of 、 The package and function are respectively consistent with the industrial standard MAX242 and MAX232 compatible . Even when working at high data rates ,max3232 Can still maintain RS-232 The positive and negative requirements of the standard 5.0V Minimum transmitter output voltage .
MAX3232 yes MAXIM A product produced by the company 232 Communication chip , He can turn the level of the logic signal of the single chip microcomputer into RS232 The level of . because RS232 Yes, it is , Positive and negative levels 0 and 1 The signal of , therefore MAX3232 To generate the corresponding positive and negative voltage . In the use of MAX3232 when , First, confirm the voltage supplied by the system , Because this chip , For different working voltages , Different capacitors should be used to generate voltage . After power on , Check it out first 2 Does the foot have +5.4V Above voltage ,6 Feet have -5.4V Above voltage ,16 Whether the pin has voltage , If not, check the corresponding capacitance . Pay attention to 16 Feet must have capacitance , Otherwise, the corresponding voltage may not be generated .
RS232 turn TTL2 Generation serial port module brush board module (MAX3232 chip )
DB9 Pin function
1 、DCD( Data Carrier Detect) : Carrier detection . It is mainly used for Modem Notify the computer that it is online , namely Modem Dial tone detected , On line .
2 、RXD(Receive(rx) Data): This pin is used to receive data sent by external devices ; In your use Modem when , You'll find that RXD The indicator light is flashing , explain RXD There is data entry on the pin ( Computer 2 Pick up MAX232 Of RS232 End TOUT( Such as PIN7)).
3 、TXD(Transmit(tx) Data): This pin sends the data of the computer to the external device ; In your use Modem when , You'll find that TXD The indicator light is flashing , Indicates that the computer is passing TXD Pin sends data .
4 、DTR( Data Terminal Ready ): Data terminal ready ; When this pin is high , notice Modem Data transmission is possible , The computer is ready .
5 、GND(Ground): Logically .
6 、DSR(data set ready): Data set ready ; This pin is high , Notify the computer Modem You are ready to , Data communication is available .
7 、RTS(Request To Send): Request to send ; This foot is controlled by a computer , To inform Modem Send data to the computer immediately ; otherwise ,Modem Temporarily put the received data into the buffer .
8 、CTS(Clear to send): Clear send ; This foot is made by Modem control , It is used to inform the computer to send the data to Modem.
9 、RI ( Ring Indicator): Modem Notify the computer of a call coming in , Whether to answer the call is decided by the computer .
To realize the communication between serial ports , At least three pins are required , namely :RXD,TXD,GND,RXD With other serial ports TXD Connected to a ,TXD And RXD Connected to a ,GND And GND Connected to a , This realizes the communication between serial ports . The communication is full duplex , That is, it can be sent at the same time / receive data , Although it is serial , But because of sending / Reception is not a channel used , Therefore, full duplex can be realized .
DB9 And MAX3232 Connection circuit diagram of
Electrical schematic diagram of the module
Experiment with open source code
/* 【Arduino】168 A series of sensor module experiments (59) Experiment 59 : RS232 turn TTL2 Generation serial port module brush board module (MAX3232 chip ) One of the procedures , Read the serial port data in the cache Pay attention to the wiring method here , Soft serial port RX Pick up RS232 Of adapter plate RX mouth , TX Pick up RS232 Of adapter plate TX mouth */
#include <SoftwareSerial.h>
SoftwareSerial DLSerial(6, 7); // Soft serial port RX(D6), TX(D7)
void setup() {
DLSerial.begin(9600); // Device baud rate 9600
}
void loop() {
DLSerial.write(1); // Send byte data
DLSerial.write(3);
delay(500);
while (DLSerial.available()>0) // If there is received data in the cache
{
DLSerial.read(); // Read the serial port data in the cache
delay(2);
}
delay(500);
}/* 【Arduino】168 A series of sensor module experiments (59) Experiment 59 : RS232 turn TTL2 Generation serial port module brush board (MAX3232 chip ) Procedure II , Receive serial data rx = 6 tx = 7 */
#include <ctype.h>
#define bit9600Delay 100
#define halfBit9600Delay 50
#define bit4800Delay 188
#define halfBit4800Delay 94
byte rx = 6;
byte tx = 7;
byte SWval;
void setup() {
pinMode(rx,INPUT);
pinMode(tx,OUTPUT);
digitalWrite(tx,HIGH);
delay(2);
digitalWrite(13,HIGH);
SWprint('o');
SWprint('k');
SWprint(10);
}
void SWprint(int data)
{
byte mask;
digitalWrite(tx,LOW);
delayMicroseconds(bit9600Delay);
for (mask = 0x01; mask>0; mask <<= 1) {
if (data & mask){
digitalWrite(tx,HIGH);
}
else{
digitalWrite(tx,LOW);
}
delayMicroseconds(bit9600Delay);
}
digitalWrite(tx, HIGH);
delayMicroseconds(bit9600Delay);
}
int SWread()
{
byte val = 0;
while (digitalRead(rx));
if (digitalRead(rx) == LOW) {
delayMicroseconds(halfBit9600Delay);
for (int offset = 0; offset < 8; offset++) {
delayMicroseconds(bit9600Delay);
val |= digitalRead(rx) << offset;
}
delayMicroseconds(bit9600Delay);
delayMicroseconds(bit9600Delay);
return val;
}
}
void loop()
{
SWval = SWread();
SWprint(toupper(SWval));
}Experimental simulation programming (linkboy)
Publisher : Full stack programmer stack length , Reprint please indicate the source :https://javaforall.cn/125701.html Link to the original text :https://javaforall.cn
边栏推荐
- Value on the object Z rotation synchronization panel in unity
- Dynamic planning: robbing families and houses
- Tree array-
- 多表查询之子查询_单行单列情况
- ES6 question
- Arduino drive Lora module node
- How to solve command 'xxx GCC' not found, but can be installed with:??
- [recommendation system] the classic technical architecture of the data flow of the recommendation system + the most complete evolution map of the top 10 deep learning CTR models of Microsoft, Alibaba,
- CMS vulnerability recurrence - foreground arbitrary user password modification vulnerability
- 图像处理:RGB565转RGB888
猜你喜欢
![[STM32 learning] (22) STM32 realizes 360 degree rotary encoder](/img/8e/fb036296ec3aff5e60acee5018943c.png)
[STM32 learning] (22) STM32 realizes 360 degree rotary encoder

Detailed explanation of uninstalling MySQL completely under Linux

Simply use golang SQLC to generate MySQL query code

What did zoneawareloadbalancer of ribbon and its parent class do?

zoj-Swordfish-2022-5-6
![[STM32 learning] (10) stm32f1 general timer realizes pulse counter](/img/42/1f5104f923b1868dda23bcc425fc62.png)
[STM32 learning] (10) stm32f1 general timer realizes pulse counter

Tree array-
![Raspberry Pie: [failed] failed to start /etc/rc local Compatibility.](/img/c3/d648cea4e8eef20a221dc034ecfc1d.png)
Raspberry Pie: [failed] failed to start /etc/rc local Compatibility.
![[STM32 learning] (13) STM32 realizes ultrasonic ranging (hc-sr04)](/img/6e/b7cf7a8e3296e29d61a0626e3793ea.png)
[STM32 learning] (13) STM32 realizes ultrasonic ranging (hc-sr04)
![[STM32 learning] (6) use of serial port 1 (usart1)](/img/b1/430d3501a99e46958c066f7fd7eee9.png)
[STM32 learning] (6) use of serial port 1 (usart1)
随机推荐
MySQL performance optimization (IV): how to use indexes efficiently and correctly
[STM32 learning] (16) STM32 realizes LCD1602 display (74HC595 drive) - 4-bit bus
Ask you to build a small program server
Balance between management / business and technology
Uniapp calendar component
How does ribbon get the default zoneawareloadbalancer?
Domain Driven practice summary (basic theory summary and analysis + Architecture Analysis and code design + specific application design analysis V) [easy to understand]
ZOJ 2770 differential restraint system -- 2 -- May 20, 2022
PostgreSQL rounding
cannot unpack non-iterable NoneType object
Activity exception lifecycle
Ffmpeg splash screen solution (modify the source code and discard incomplete frames)
给你的网站加一个爱发电角标
Dynamic planning: robbing families and houses
The role of glpushmatrix and glpopmatrix
zoj-Swordfish-2022-5-6
[STM32 learning] (5) press the key to control the flow light (interrupt Implementation)
Android uses JDBC to connect to a remote database
Create a vertical seekbar from scratch
图像处理:RGB565转RGB888