当前位置:网站首页>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}边栏推荐
- 2022图片在线加水印源码
- kubernetes之DaemonSet以及滚动更新
- PAT 1167 Cartesian Tree(30)
- This article will take you to thoroughly clarify the working mechanism of certificates in Isito
- 什么是一致性哈希?可以应用在哪些场景?
- 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
- 安全又省钱,“15岁”老小区用上管道燃气
- iframe标签属性说明 详解[通俗易懂]
- 透过开发抽奖小程序,体会创新与迭代
- SQL函数 SQUARE
猜你喜欢

【2022蓝帽杯】file_session && 浅入opcode

芝加哥丰田技术学院 | Leveraging Natural Supervision for Language Representation Learning and Generation(利用自然监督进行语言表示学习和生成)

How do we do full-link grayscale on the database?

库函数的模拟实现(strlen)(strcpy)(strcat)(strcmp)(strstr)(memcpy)(memmove)(C语言)(VS)

全链路灰度在数据库上我们是怎么做的?

MCU开发是什么?国内MCU产业现状如何

【每日一题】1331. 数组序号转换

观察者模式

leetcode:1201. 丑数 III【二分 + 数学 + 容斥原理】

mysql的基本使用
随机推荐
动态库、静态库浅析
iPhone难卖,被欧洲反垄断的服务业务也难赚钱了,苹果的日子艰难
SQL函数 SQRT
四足机器人软件架构现状分析
Programmer's Romantic Tanabata
PAT1165 Block Reversing(25)
windows IDEA + PHP+xdebug 断点调试
搭建LNMT架构
MCU开发是什么?国内MCU产业现状如何
LeetCode_动态规划_中等_377.组合总和 Ⅳ
对标丰田!蔚来又一新品牌披露:产品价格低于20万
论文详读《基于改进 LeNet-5 模型的手写体中文识别》,未完待补充
[Cloud Enjoying Freshness] Community Weekly Vol.73- DTSE Tech Talk: 1 hour in-depth interpretation of SaaS application system design
Why does the maximum plus one equal the minimum
Software designer test center summary (interior designer personal summary)
意大利普拉托华社将游行示威 盼解决安全问题
leetcode:1201. 丑数 III【二分 + 数学 + 容斥原理】
RGB系列开发稳定响应快速灯带拾音灯氛围灯等应用定制方案
人像分割技术解析与应用
Service Mesher Meetup 成都站:Service Mesh是下一代SDN吗?