# begin

{% tabs %}
{% tab title="常见用法" %}

## 函数原型

```cpp
void Serial.begin(long speed);
```

## 作用

初始化串口，指定串口数据传播速率(波特率)

## 参数

* `pin`

  指定引脚的编号，如： `10` , `A0` 等。

## 示例

```cpp
Serial.begin(9600);             // 一般将波特率设为9600
```

{% endtab %}

{% tab title="高级用法" %}

## 函数原型

```cpp
void Serial.begin(long speed, uint8_t config);
```

## 参数

* `pin`

  指定引脚的编号，如： `10` , `A0` 等。
* `config`

  可选，很少用到，可能的值如下：

  |     config可选配置    | 数据位 | 校验位 | 停止位 |
  | :---------------: | :-: | :-: | :-: |
  |    SERIAL\_5N1    |  5  |  无  |  1  |
  |    SERIAL\_6N1    |  6  |  无  |  1  |
  |    SERIAL\_7N1    |  7  |  无  |  1  |
  | SERIAL\_8N1(默认配置) |  8  |  无  |  1  |
  |    SERIAL\_5N2    |  5  |  无  |  2  |
  |    SERIAL\_6N2    |  6  |  无  |  2  |
  |    SERIAL\_7N2    |  7  |  无  |  2  |
  |    SERIAL\_8N2    |  8  |  无  |  2  |
  |    SERIAL\_5E1    |  5  |  偶  |  1  |
  |    SERIAL\_6E1    |  6  |  偶  |  1  |
  |    SERIAL\_7E1    |  7  |  偶  |  1  |
  |    SERIAL\_8E1    |  8  |  偶  |  1  |
  |    SERIAL\_5E2    |  5  |  偶  |  2  |
  |    SERIAL\_6E2    |  6  |  偶  |  2  |
  |    SERIAL\_7E2    |  7  |  偶  |  2  |
  |    SERIAL\_8E2    |  8  |  偶  |  2  |
  |    SERIAL\_5O1    |  5  |  奇  |  1  |
  |    SERIAL\_6O1    |  6  |  奇  |  1  |
  |    SERIAL\_7O1    |  7  |  奇  |  1  |
  |    SERIAL\_8O1    |  8  |  奇  |  1  |
  |    SERIAL\_5O2    |  5  |  奇  |  2  |
  |    SERIAL\_6O2    |  6  |  奇  |  2  |
  |    SERIAL\_7O2    |  7  |  奇  |  2  |
  |    SERIAL\_8O2    |  8  |  奇  |  2  |

## 示例

```cpp

Serial.begin(9600, SERIAL_8E2); // 将串口波特率设为9600，数据位8，偶校验，停止位2。
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://arduino.doc.skyone.host/core/serial/begin.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
