当前位置:网站首页>gpio analog serial communication
gpio analog serial communication
2022-08-01 13:33:00 【Four Seasons Sail】
1. Serial transmission protocol
UART works in asynchronous mode and does not require a clock signal. Its general format is: start bit + data bit + parity bit + stop bit.Among them, the start bit is 1, the data bit is 5~8, the parity bit is 0 or 1, and the stop bit is 1, 1.5 or 2.But the most commonly used format is 1 start bit, 8 data bits, no parity, 1 stop bit, abbreviated as 8/N/1.
The timing diagram of the 8/N/1 format is as follows:

When idle, the data line is specified as logic 1.
When starting to transmit data, the start bit is sent first, which is specified as logic 0. The receiving end will detect this falling edge so that it can start to sample the received data later.
The start bit is followed by the data bit, which stipulates that the lowest bit is sent first, that is, LSB First.Because the UART does not have a clock signal, the baud rate is used to determine the length of each bit. However, in order to ensure the accuracy of detection, the actual sampling frequency will be higher than the baud rate. Generally, each bit will be sampled several times, and the middle one will be taken.Sample value as the result of this bit.
The parity bit is generally not used.
The stop bit generally uses 1 bit, which is specified as logic 1. In addition to indicating the end of the transmission, the stop bit can also play a role in clock synchronization.
It should be noted that the logic 0 here is not necessarily 0V, which is related to the level standard used.For TTL level, logic 0 is 0V, logic 1 is high level (usually 3.3V or 5V); for RS-232 level, logic 0 is 3V~15V, logic 1 is -3~-15V.
2. gpio analog serial communication
Take a chip with a crystal frequency of 11.0592M as an example to implement serial communication with a baud rate of 9600BPS (that is, it takes 1/9600 seconds to transmit one bit), timing time = timer count value * machine cycle = timer countValue*12/crystal frequency, now the timing time is 1/9600 second, timer count value=timing time*crystal frequency/12=110592/1152=96
Supplementary: The machine cycle represents the time required to execute a cpu instruction, the clock cycle is 1/crystal frequency, and a machine cycle is generally composed of multiple clock cycles. For example, a machine cycle of a 51 single-chip microcomputer consists of 12 clock cycles.
#define TM0_FLAG 0 //Set the transmission flag#define RXD P1_0 //Use the P1_0 IO pin to simulate the RXD function pin#define TXD P1_1 //Use P1_0 IO pin to simulate TXD function pin/* Counter and interrupt initialization */void S2INI(void){TMOD |= 0x02; //counter 0, mode 2TH0 = 0xA0; //The preset value is 256-96=140, hexadecimal A0TL0 = TH0;TR0 = 0; //Start using when sending or receivingTF0 = 0;ET0 = 1; //Enable timer 0 interruptEA = 1; //interrupt enable master switch}/* Read a character from the serial port */uchar RByte(){uchar Output = 0;uchar i = 8;TR0 = 1; //Start Timer0TL0 = TH0;WaitTF0(); //Wait for the start bit//Send 8 data bitswhile(i--){Output >>= 1;if(RXD) Output |= 0x80; //Close the low firstWaitTF0(); //Delay between bits}while(!TM0_FLAG){if(RXD) break; //Receive end bit}TR0 = 0; //stopTimer0return Output;}/* Write a byte to the serial port */void WByte(uchar input){uchar i = 8;TXD = (bit)0; //transmit start bitWaitTF0();//Send 8 data bitswhile(i--){TXD = (bit)(input & 0x01); //Pass the low bit firstWaitTF0();input = input >> 1;}TXD = (bit)1; //Transmission end bitWaitTF0();}/* Interrupt 1 handler */void IntTimer0() interrupt 1{TM0_FLAG = 1; //Set the flag bit.}/* Query the transfer flag */void WaitTF0( void ){while(!TM0_FLAG);TM0_FLAG = 0; //clear the flag bit}边栏推荐
- NebulaGraph v3.2.0 性能报告
- 态路小课堂丨浅谈优质光模块需要具备的条件!
- kubernetes之DaemonSet以及滚动更新
- 制售假劣农资、非法占用耕地……公安部公布十起危害粮食生产安全犯罪典型案例
- 批量替换Word中的表格为图片并保存
- 魔众短链接系统 v3.9.0
- postgresql之page分配管理(一)
- Software designer test center summary (interior designer personal summary)
- 论文笔记All about Eve: Execute-Verify Replication for Multi-Core Servers
- 【每日一题】952. 按公因数计算最大组件大小
猜你喜欢
随机推荐
LeetCode_动态规划_中等_313.超级丑数
PIR人体感应AC系列感应器投光灯人体感应开关等应用定制方案
PAT 1162 Postfix Expression(25)
Two Permutations
芝加哥丰田技术学院 | Leveraging Natural Supervision for Language Representation Learning and Generation(利用自然监督进行语言表示学习和生成)
formatdatetime函数 mysql(date sub函数)
The obstacles to put Istio into production and how we solve them
Towhee 每周模型
SQL函数 %SQLSTRING
求方阵的无穷范数「建议收藏」
Based on 10 years of experience in stability assurance, what are the three key questions to be answered in failure recovery?|TakinTalks big coffee sharing
Istio投入生产的障碍以及如何解决这些问题
微信UI在线聊天源码 聊天系统PHP采用 PHP 编写的聊天软件,简直就是一个完整的迷你版微信
2022-07-25 网工进阶(二十一)BGP-路由反射器、联盟、聚合
Simulation implementation of new of Js handwritten function
How does the SAP ABAP OData service support the Create operation trial version
论文笔记All about Eve: Execute-Verify Replication for Multi-Core Servers
RGB系列开发稳定响应快速灯带拾音灯氛围灯等应用定制方案
PanGu-Coder:函数级的代码生成模型
SQL函数 %SQLUPPER









