1 /* mbed Microcontroller Library
2 * Copyright (c) 2006-2013 ARM Limited
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
27 /** An I2C Master, used for communicating with I2C slave devices
31 * // Read from I2C slave at address 0x62
40 * i2c.read(address, data, 2);
59 /** Create an I2C Master interface, connected to the specified pins
61 * @param sda I2C data line pin
62 * @param scl I2C clock line pin
64 I2C(PinName sda, PinName scl);
66 /** Set the frequency of the I2C interface
68 * @param hz The bus frequency in hertz
70 void frequency(int hz);
72 /** Read from an I2C slave
74 * Performs a complete read transaction. The bottom bit of
75 * the address is forced to 1 to indicate a read.
77 * @param address 8-bit I2C slave address [ addr | 1 ]
78 * @param data Pointer to the byte-array to read data in to
79 * @param length Number of bytes to read
80 * @param repeated Repeated start, true - don't send stop at end
84 * non-0 on failure (nack)
86 int read(int address, char *data, int length, bool repeated = false);
88 /** Read a single byte from the I2C bus
90 * @param ack indicates if the byte is to be acknowledged (1 = acknowledge)
97 /** Write to an I2C slave
99 * Performs a complete write transaction. The bottom bit of
100 * the address is forced to 0 to indicate a write.
102 * @param address 8-bit I2C slave address [ addr | 0 ]
103 * @param data Pointer to the byte-array data to send
104 * @param length Number of bytes to send
105 * @param repeated Repeated start, true - do not send stop at end
108 * 0 on success (ack),
109 * non-0 on failure (nack)
111 int write(int address, const char *data, int length, bool repeated = false);
113 /** Write single byte out on the I2C bus
115 * @param data data to write out on bus
118 * '1' if an ACK was received,
123 /** Creates a start condition on the I2C bus
128 /** Creates a stop condition on the I2C bus