

如何STM32duino
source link: https://www.gaficat.com/posts/db9a01ad.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

如何STM32duin_
429 字
6 分钟
118 次
本文最后更新于:2021年1月6日 凌晨
如何在STM32duino中使用多个串口。
最近在制作涂鸦智能TVOC传感器的过程中,需要使用多个串口。但STM32duino默认定义了Serial可以直接使用,但如果需要串口2、串口3应该怎么使用呢?
我查阅了STM32duino官方的Wiki,发现是可以直接使用HardwareSerial的:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
HardwareSerial mySerial(PA3, PA2); // RX, TX
void setup() {
// put your setup code here, to run once:
mySerial.begin(115200); // 软件串口初始化
mySerial.println("myserial init successful!");
Serial.begin(115200); // PA3 RX PA2 TX
Serial.println("serial init successful!");
}
void loop() {
// put your main code here, to run repeatedly:
}
可以看到,直接使用HardwareSerial创建一个串口对象就行了,其中的两个参数,分别是RX和TX(实际使用中,可以根据情况,选择芯片串口对应的引脚填入,映射的引脚也是可以的哦),之后就与原生的串口对象使用无异了。
当然了,Arduino的示例代码中,还有SoftwareSerial的使用方法,二选一就可以了。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/*
Software serial multple serial test
Receives from the hardware serial, sends to software serial.
Receives from software serial, sends to hardware serial.
The circuit:
* RX is digital pin 10 (connect to TX of other device)
* TX is digital pin 11 (connect to RX of other device)
created back in the mists of time
modified 25 May 2012
by Tom Igoe
based on Mikal Hart's example
This example code is in the public domain.
*/
#include <SoftwareSerial.h>
SoftwareSerial mySerial(10, 11); // RX, TX
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(57600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
Serial.println("Goodnight moon!");
// set the data rate for the SoftwareSerial port
mySerial.begin(4800);
mySerial.println("Hello, world?");
}
void loop() { // run over and over
if (mySerial.available()) {
Serial.write(mySerial.read());
}
if (Serial.available()) {
mySerial.write(Serial.read());
}
}
Recommend
-
80
中国经济 如何投资于转型中的“新中国”? 中国正努力实现经济转型,一些基金经理称此为“新中国”。目前投资者对中国的看法大为好转,...
-
118
垃圾股,在中国A股市场,超级垃圾股的唯一客观衡量指标便是每股未分配利润的“亏空”程度。超级垃圾股与ST股是两个不同的概念,因为ST股大多只是近几年公司业绩(短期业绩)糟糕的标志,而超级垃圾股则是久经考验的僵尸企业,它更可怕
-
109
美联储如何“缩表” 来源于 《财新周刊...
-
146
在上篇中,我们已经讨论过如何去实现一个 Map 了,并且也讨论了诸多优化点。在下篇中,我们将继续讨论如何实现一个线程安全的 Map。说到线程安全,需要从概念开始说起。 线程安全就是如果你的代码块所在的进程中有多个线程在同时运行,而这些线程可能会同时运行这...
-
142
OKR的全称是Objectives and Key Results,中文可以直译为“目标和主要成果”,这套系统最初由英特尔公司制定,但是付诸实践的最大公司并不是英特尔自己,而是谷歌。大家还记得谷歌的成立时间吗?1998年9月4日。英特尔在1999年(成立一年后)就全面引入了OKR管理方式...
-
210
超实用!如何制作统一可复用iOS/Material Design元件库?(附源文件)
-
67
如何缔造不可超越的品牌帝国?DR钻戒超级品牌启示录_推荐_i黑马 如何缔造不可超越的品牌帝国?DR钻戒超级品牌启示录 ...
-
107
如何挖掘消费者的隐性需求? “某富翁娶妻,有三个人选,富翁给了三个女孩各一千元,请她们把房间装满。女孩A买了很多棉花,装满房间的1/2。女孩B买了很多气球,装满房间3/4。女孩C买了蜡烛,让光充满房间。最终……富翁选...
-
121
相信不少同学在维护老项目时,都遇到过在深深的 if else 之间纠缠的业务逻辑。面对这样的一团乱麻,简单粗暴地继续增量修改常常只会让复杂度越来越高,可读性越来越差,有没有固定的套路来梳理它呢?这里分享三种简单通用的重构方式。 什么是面条代码 所谓的【面条...
-
59
README.md Arduino core support for STM32 based boards
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK