Arduino设置SoftwareSerial缓冲区大小

编程入门 行业动态 更新时间:2024-10-18 21:20:11

Arduino设置SoftwareSerial<a href=https://www.elefans.com/category/jswz/34/1768630.html style=缓冲区大小"/>

Arduino设置SoftwareSerial缓冲区大小

SoftwareSerial的缓冲区大小设置

  • 概述
  • 修改缓冲区的大小
  • 实验

概述

新的Arduino的ESP8266软串口的缓冲区原来老的库中有宏定义可以用来修改接收和发送缓冲区的大小。在现在新的库中已经没有这个设置了,那怎么才能修改缓冲区的大小哪?

修改缓冲区的大小

定义软串口

#include 《SoftwareSerial.h>
// 程序中定义软串口
SoftwareSerial mSerial(RXD1, TXD1);
// 在setup() 定义缓冲区大小
setup()
{Serial.begin(115200);delay(2000);mSerial.begin(19200,SWSERIAL_8N1,RXD1,TXD1,false,256);
}

这就可以将缓冲区修改成256个字节。

实验

原来在程序中默认大小为64个字节

void begin(uint32_t baud, Config config,int8_t rxPin, int8_t txPin, bool invert,int bufCapacity = 64, int isrBufCapacity = 0) {UARTBase::begin(baud, config, rxPin, txPin, invert);if (GpioCapabilities::isValidInputPin(rxPin)) {beginRx(GpioCapabilities:: hasPullUp(rxPin), bufCapacity, isrBufCapacity);}if (GpioCapabilities::isValidOutputPin(txPin)) {beginTx();}enableRx(true);}

现在经过调用begin,将缓冲区扩大为256.
实际运行结果:

更多推荐

Arduino设置SoftwareSerial缓冲区大小

本文发布于:2023-11-16 16:29:57,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1627222.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:缓冲区   大小   Arduino   SoftwareSerial

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!