> For the complete documentation index, see [llms.txt](https://mwx.twelite.info/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://mwx.twelite.info/latest_en/api-reference/predefined_objs/wire.md).

# Wire

Reads and writes two-wire serial (I2C) master.

#### Alias Definition

```cpp
using TwoWire = mwx::periph_twowire<MWX_TWOWIRE_RCVBUFF>;
```

The `mwx::periph_wire<MWX_TWOWIRE_RCVBUFF>` can be referred as `TwoWire`.

#### Type Definitions

The following definition types describe the types of arguments and return values.

```cpp
typedef uint8_t size_type;
typedef uint8_t value_type;
```

## hint style="warning %}

{% hint style="warning" %}
Some APIs make calls where the STOP bit is not strictly handled.
{% endhint %}

{% hint style="info" %}
`write(), writer::operator() ()` has several arguments defined in addition to the ones described here.

* fixed array type\
  `uint8_t cmds[]={11,12};`\
  `...`\
  `Wire.write(cmds);`
* `initializer_list<>` 型\
  `Wire.write({11,12})`
  {% endhint %}

## Initialization and termination

### Wire Instance Creation

Instance creation and necessary initialization is done in the library. In user code, it is made available by calling `Wire.begin()`.

When using the `requestFrom()` method, you can specify the size of the FIFO queue for temporary data storage. At compile time, compile the macro `MWX_TWOWIRE_BUFF` with the required number of bytes. The default is 32 bytes.

> Example: `-DMWX_TWOWIRE_BUFF=16`

### begin()

```cpp
void begin(
    const size_type u8mode = WIRE_100KHZ,
    bool b_portalt = false)
```

Initialize hardware.

{% hint style="danger" %}
Performing any Wire operation without initialization will cause the TWELITE radio module to hang.
{% endhint %}

{% hint style="warning" %}
When waking from sleep, if the module was operating just before sleep, it will return to the previous state.
{% endhint %}

| Parameters  | Description                                                                                                                                                                                                                                                                                                                                                               |
| ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `u8mode`    | <p>Specifies the bus frequency. Default is 100Khz (<code>WIRE\_CONF::WIRE\_100KHZ</code>)<br>The frequency is specified by <code>WIRE\_CONF::WIRE\_? KHZ</code> and <code>? KHZ</code> can be <code>50</code>,<code>66</code>,<code>80</code>,<code>100</code>,<code>133</code>,<code>160</code>,<code>200</code>,<code>266</code>,<code>320</code>,<code>400</code>.</p> |
| `b_portalt` | Change hardware pin assignments.                                                                                                                                                                                                                                                                                                                                          |

### Example

```cpp
void setup() {
    ...
    Wire.begin();
    ...
}

void wakeup() {
    ...
    Wire.begin();
    ...
}
```

## Reading and Writing

There are two types of read/write procedures. Select and use one of them.

* [Member function (input/output using the following member functions)](/latest_en/api-reference/predefined_objs/wire/wire-member.md)\
  `requestFrom(), beginTransmission(), endTransmission(), write()`
* [Helper class (stream function available)](/latest_en/api-reference/predefined_objs/wire/wire-helperclass.md)\
  `reader, writer`

####

## Others

### Probe（Determine presence of device)

```cpp
bool probe(uint8_t address)
```

Checks if the device specified by `address` is responding. If the device exists, `true` is returned.

### setClock()

```cpp
void setClock(uint32_t speed)
```

The procedure is originally intended to change the bus frequency, but no action is taken.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://mwx.twelite.info/latest_en/api-reference/predefined_objs/wire.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
