Skip to content

Commit c1dc611

Browse files
authored
Merge pull request #448 from per1234/add-wire-docs
Import of Wire library reference pages
2 parents c197a53 + feed565 commit c1dc611

15 files changed

+647
-0
lines changed
+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
---
2+
title: Wire
3+
categories: [ "Functions" ]
4+
subCategories: [ "Communication" ]
5+
---
6+
7+
8+
= Wire
9+
10+
11+
//OVERVIEW SECTION STARTS
12+
[#overview]
13+
--
14+
15+
[float]
16+
=== Description
17+
18+
19+
This library allows you to communicate with I2C/TWI devices. On the Arduino boards with the R3 layout (1.0 pinout), the SDA (data line) and SCL (clock line) are on the pin headers close to the AREF pin. The Arduino Due has two I2C/TWI interfaces SDA1 and SCL1 are near to the AREF pin and the additional one is on pins 20 and 21.
20+
21+
As a reference the table below shows where TWI pins are located on various Arduino boards.
22+
23+
[cols="1,1"]
24+
|===
25+
|Board
26+
|I2C/TWI pins
27+
28+
|UNO, Ethernet
29+
|A4 (SDA), A5 (SCL)
30+
31+
|Mega2560
32+
|20 (SDA), 21 (SCL)
33+
34+
|Leonardo
35+
|20 (SDA), 21 (SCL), SDA1, SCL1
36+
|===
37+
38+
39+
As of Arduino 1.0, the library inherits from the Stream functions, making it consistent with other read/write libraries. Because of this, `send()` and `receive()` have been replaced with `read()` and `write()`.
40+
41+
Recent versions of the Wire library can use timeouts to prevent a lockup in the face of certain problems on the bus, but this is not enabled by default (yet) in current versions. It is recommended to always enable these timeouts when using the Wire library. See the Wire.setWireTimeout function for more details.
42+
43+
*Note:* There are both 7 and 8-bit versions of I2C addresses. 7 bits identify the device, and the eighth bit determines if it's being written to or read from. The Wire library uses 7 bit addresses throughout. If you have a datasheet or sample code that uses 8-bit address, you'll want to drop the low bit (i.e. shift the value one bit to the right), yielding an address between 0 and 127. However the addresses from 0 to 7 are not used because are reserved so the first address that can be used is 8. Please note that a pull-up resistor is needed when connecting SDA/SCL pins. Please refer to the examples for more information. MEGA 2560 board has pull-up resistors on pins 20 and 21 onboard.
44+
45+
*The Wire library implementation uses a 32 byte buffer, therefore any communication should be within this limit. Exceeding bytes in a single transmission will just be dropped.*
46+
47+
To use this library:
48+
49+
`#include <Wire.h>`
50+
51+
--
52+
// OVERVIEW SECTION ENDS
53+
54+
//FUNCTION SECTION STARTS
55+
[#functions]
56+
--
57+
58+
'''
59+
[float]
60+
=== Functions
61+
link:../wire/begin[begin()] +
62+
link:../wire/end[end()] +
63+
link:../wire/requestfrom[requestFrom()] +
64+
link:../wire/begintransmission[beginTransmission()] +
65+
link:../wire/write[write()] +
66+
link:../wire/available[available()] +
67+
link:../wire/read[read()] +
68+
link:../wire/setclock[setClock()] +
69+
link:../wire/onreceive[onReceive()] +
70+
link:../wire/onrequest[onRequest()] +
71+
link:../wire/setwiretimeout[setWireTimeout()] +
72+
link:../wire/clearwiretimeoutflag[clearWireTimeoutFlag()] +
73+
link:../wire/getwiretimeoutflag[getWireTimeoutFlag()]
74+
75+
'''
76+
77+
--
78+
// FUNCTION SECTION ENDS
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
---
2+
title: available()
3+
---
4+
5+
= available
6+
7+
//OVERVIEW SECTION STARTS
8+
[#overview]
9+
--
10+
11+
[float]
12+
=== Description
13+
This function returns the number of bytes available for retrieval with `read()`. This function should be called on a controller device after a call to `requestFrom()` or on a peripheral inside the `onReceive()` handler. `available()` inherits from the Stream utility class.
14+
15+
[float]
16+
=== Syntax
17+
`Wire.available()`
18+
19+
[float]
20+
=== Parameters
21+
22+
None.
23+
24+
[float]
25+
=== Returns
26+
27+
The number of bytes available for reading.
28+
29+
--
30+
//OVERVIEW SECTION STARTS
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
title: begin()
3+
---
4+
= begin
5+
6+
//OVERVIEW SECTION STARTS
7+
[#overview]
8+
--
9+
10+
[float]
11+
=== Description
12+
13+
This function initializes the Wire library and join the I2C bus as a controller or a peripheral. This function should normally be called only once.
14+
15+
[float]
16+
=== Syntax
17+
18+
`Wire.begin()`
19+
20+
`Wire.begin(address)`
21+
22+
[float]
23+
=== Parameters
24+
* _address_: the 7-bit slave address (optional); if not specified, join the bus as a controller device.
25+
26+
[float]
27+
=== Returns
28+
None.
29+
--
30+
31+
//OVERVIEW SECTION ENDS
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
title: beginTransmission()
3+
---
4+
5+
= beginTransmission
6+
7+
//OVERVIEW SECTION STARTS
8+
[#overview]
9+
--
10+
11+
[float]
12+
=== Description
13+
This function begins a transmission to the I2C peripheral device with the given address. Subsequently, queue bytes for transmission with the `write()` function and transmit them by calling `endTransmission()`.
14+
15+
[float]
16+
=== Syntax
17+
18+
`Wire.beginTransmission(address)`
19+
20+
[float]
21+
=== Parameters
22+
* _address_: the 7-bit address of the device to transmit to.
23+
24+
[float]
25+
=== Returns
26+
None.
27+
--
28+
//OVERVIEW SECTION ENDS
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
---
2+
title: clearWireTimeoutFlag()
3+
---
4+
= clearWireTimeoutFlag
5+
6+
//OVERVIEW SECTION STARTS
7+
[#overview]
8+
--
9+
10+
[float]
11+
=== Description
12+
13+
Clears the timeout flag.
14+
15+
Timeouts might not be enabled by default. See the documentation for `Wire.setWireTimeout()` for more information on how to configure timeouts and how they work.
16+
17+
18+
[float]
19+
=== Syntax
20+
21+
`Wire.clearTimeout()`
22+
23+
[float]
24+
=== Parameters
25+
None.
26+
27+
[float]
28+
=== Returns
29+
* bool: The current value of the flag
30+
31+
[float]
32+
=== Portability Notes
33+
This function was not available in the original version of the Wire library and might still not be available on all platforms. Code that needs to be portable across platforms and versions can use the `WIRE_HAS_TIMEOUT` macro, which is only defined when `Wire.setWireTimeout()`, `Wire.getWireTimeoutFlag()` and `Wire.clearWireTimeout()` are all available.
34+
35+
--
36+
37+
//OVERVIEW SECTION ENDS
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
title: end()
3+
---
4+
= end
5+
6+
//OVERVIEW SECTION STARTS
7+
[#overview]
8+
--
9+
10+
[float]
11+
=== Description
12+
13+
Disable the Wire library, reversing the effect of `Wire.begin()`. To use the Wire library again after this, call `Wire.begin()` again.
14+
15+
*Note:* This function was not available in the original version of the Wire library and might still not be available on all platforms. Code that needs to be portable across platforms and versions can use the `WIRE_HAS_END` macro, which is only defined when `Wire.end()` is available.
16+
17+
[float]
18+
=== Syntax
19+
20+
`Wire.end()`
21+
22+
[float]
23+
=== Parameters
24+
None.
25+
26+
[float]
27+
=== Returns
28+
None.
29+
--
30+
31+
//OVERVIEW SECTION ENDS
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
---
2+
title: endTransmission()
3+
---
4+
5+
= endTransmission
6+
7+
//OVERVIEW SECTION STARTS
8+
[#overview]
9+
--
10+
11+
[float]
12+
=== Description
13+
This function ends a transmission to a peripheral device that was begun by `beginTransmission()` and transmits the bytes that were queued by `write()`. As of Arduino 1.0.1, `endTransmission()` accepts a boolean argument changing its behavior for compatibility with certain I2C devices. If true, `endTransmission()` sends a stop message after transmission, releasing the I2C bus. If false, `endTransmission()` sends a restart message after transmission. The bus will not be released, which prevents another controller device from transmitting between messages. This allows one controller device to send multiple transmissions while in control. The default value is true.
14+
15+
[float]
16+
=== Syntax
17+
`Wire.endTransmission()`
18+
`Wire.endTransmission(stop)`
19+
20+
[float]
21+
=== Parameters
22+
23+
* _stop_: true or false. True will send a stop message, releasing the bus after transmission. False will send a restart, keeping the connection active.
24+
[float]
25+
=== Returns
26+
27+
* _0_: success.
28+
* _1_: data too long to fit in transmit buffer.
29+
* _2_: received NACK on transmit of address.
30+
* _3_: received NACK on transmit of data.
31+
* _4_: other error.
32+
* _5_: timeout
33+
--
34+
//OVERVIEW SECTION ENDS
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
---
2+
title: getWireTimeoutFlag()
3+
---
4+
= getWireTimeoutFlag
5+
6+
//OVERVIEW SECTION STARTS
7+
[#overview]
8+
--
9+
10+
[float]
11+
=== Description
12+
13+
Checks whether a timeout has occured since the last time the flag was cleared.
14+
15+
This flag is set is set whenever a timeout occurs and cleared when `Wire.clearWireTimeoutFlag()` is called, or when the timeout is changed using `Wire.setWireTimeout()`.
16+
17+
18+
[float]
19+
=== Syntax
20+
21+
`Wire.getWireTimeoutFlag()`
22+
23+
[float]
24+
=== Parameters
25+
None.
26+
27+
[float]
28+
=== Returns
29+
* bool: The current value of the flag
30+
31+
[float]
32+
=== Portability Notes
33+
This function was not available in the original version of the Wire library and might still not be available on all platforms. Code that needs to be portable across platforms and versions can use the `WIRE_HAS_TIMEOUT` macro, which is only defined when `Wire.setWireTimeout()`, `Wire.getWireTimeoutFlag()` and `Wire.clearWireTimeout()` are all available.
34+
35+
--
36+
37+
//OVERVIEW SECTION ENDS
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
---
2+
title: onReceieve()
3+
---
4+
5+
= onReceive
6+
7+
//OVERVIEW SECTION STARTS
8+
[#overview]
9+
--
10+
11+
[float]
12+
=== Description
13+
14+
This function registers a function to be called when a peripheral device receives a transmission from a controller device.
15+
16+
[float]
17+
=== Syntax
18+
`Wire.onReceive(handler)`
19+
20+
[float]
21+
=== Parameters
22+
23+
* _handler_: the function to be called when the peripheral device receives data; this should take a single int parameter (the number of bytes read from the controller device) and return nothing.
24+
25+
[float]
26+
=== Returns
27+
28+
None.
29+
--
30+
//OVERVIEW SECTION ENDS
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
---
2+
title: onRequest()
3+
---
4+
5+
= onRequest
6+
7+
//OVERVIEW SECTION STARTS
8+
[#overview]
9+
--
10+
11+
[float]
12+
=== Description
13+
This function registers a function to be called when a controller device requests data from a peripheral device.
14+
15+
[float]
16+
=== Syntax
17+
`Wire.onRequest(handler)`
18+
19+
[float]
20+
=== Parameters
21+
22+
* _handler_: the function to be called, takes no parameters and returns nothing.
23+
24+
[float]
25+
=== Returns
26+
27+
None.
28+
29+
--
30+
//OVERVIEW SECTION ENDS

0 commit comments

Comments
 (0)