|
|
本帖最后由 andyup 于 2014-7-28 11:04 编辑
1.配置串口通信数据位、校验位、停止位
通常我们使用Serial.begin(speed)来完成串口的初始化,这种方式,只能配置串口的波特率。
而使用Serial.begin(speed, config)可以配置数据位、校验位、停止位等。
例如Serial.begin(9600,SERIAL_8E2)是将串口波特率设为9600,数据位8,偶校验,停止位2。
config可用配置如下:
config可选配置 数据位 校验位 停止位 config可选配置 数据位 校验位 停止位
SERIAL_5N1 5 无 1 SERIAL_5E2 5 偶 2
SERIAL_6N1 6 无 1 SERIAL_6E2 6 偶 2
SERIAL_7N1 7 无 1 SERIAL_7E2 7 偶 2
SERIAL_8N1 8 无 1 SERIAL_8E2 8 偶 2
SERIAL_5N2 5 无 2 SERIAL_5O1 5 奇 1
SERIAL_6N2 6 无 2 SERIAL_6O1 6 奇 1
SERIAL_7N2 7 无 2 SERIAL_7O1 7 奇 1
SERIAL_8N2 8 无 2 SERIAL_8O1 8 奇 1
SERIAL_5E1 5 偶 1 SERIAL_5O2 5 奇 2
SERIAL_6E1 6 偶 1 SERIAL_6O2 6 奇 2
SERIAL_7E1 7 偶 1 SERIAL_7O2 7 奇 2
SERIAL_8E1 8 偶 1 SERIAL_8O2 8 奇 2
官方论坛也有类似用法 http://arduino.cc/en/Serial/begin
从网上找到以上配置信息,想做19200 ,ODD 校验配置 8位数据,停止1位
得到配置如下
Serial.begin(19200,SERIAL_8O1);
编译出错了。'SERIAL_8O1' was not declared in this scope .... 请教一下。 |
|