@@ -41,16 +41,32 @@ namespace mbed {
4141 *
4242 * Example:
4343 * @code
44- * // Read from I2C slave at address 0x62
45- *
44+ * Read temperature from LM75BD
4645 * #include "mbed.h"
47- *
48- * I2C i2c(p28, p27);
46+ * I2C i2c(I2C_SDA , I2C_SCL);
47+ * const int addr7bit = 0x48; // 7-bit I2C address
48+ * const int addr8bit = 0x48 << 1; // 8-bit I2C address, 0x90
4949 *
5050 * int main() {
51- * int address = 0x62;
52- * char data[2];
53- * i2c.read(address, data, 2);
51+ * char cmd[2];
52+ * while (1) {
53+ * cmd[0] = 0x01;
54+ * cmd[1] = 0x00;
55+ *
56+ * // read and write takes the 8-bit version of the address.
57+ * // set up configuration register (at 0x01)
58+ * i2c.write(addr8bit, cmd, 2);
59+ *
60+ * wait(0.5);
61+ *
62+ * // read temperature register
63+ * cmd[0] = 0x00;
64+ * i2c.write(addr8bit, cmd, 1);
65+ * i2c.read( addr8bit, cmd, 2);
66+ *
67+ * float tmp = (float((cmd[0]<<8)|cmd[1]) / 256.0);
68+ * printf("Temp = %.2f\n", tmp);
69+ * }
5470 * }
5571 * @endcode
5672 * @ingroup drivers
@@ -92,10 +108,11 @@ class I2C : private NonCopyable<I2C> {
92108 * @param data Pointer to the byte-array to read data in to
93109 * @param length Number of bytes to read
94110 * @param repeated Repeated start, true - don't send stop at end
111+ * default value is false.
95112 *
96113 * @returns
97114 * 0 on success (ack),
98- * non-0 on failure (nack)
115+ * nonzero on failure (nack)
99116 */
100117 int read (int address, char *data, int length, bool repeated = false );
101118
@@ -117,10 +134,11 @@ class I2C : private NonCopyable<I2C> {
117134 * @param data Pointer to the byte-array data to send
118135 * @param length Number of bytes to send
119136 * @param repeated Repeated start, true - do not send stop at end
137+ * default value is false.
120138 *
121139 * @returns
122140 * 0 on success (ack),
123- * non-0 on failure (nack)
141+ * nonzero on failure (nack)
124142 */
125143 int write (int address, const char *data, int length, bool repeated = false );
126144
@@ -137,7 +155,6 @@ class I2C : private NonCopyable<I2C> {
137155
138156 /* * Creates a start condition on the I2C bus
139157 */
140-
141158 void start (void );
142159
143160 /* * Creates a stop condition on the I2C bus
@@ -159,23 +176,25 @@ class I2C : private NonCopyable<I2C> {
159176
160177#if DEVICE_I2C_ASYNCH
161178
162- /* * Start non-blocking I2C transfer.
179+ /* * Start nonblocking I2C transfer.
163180 *
164181 * This function locks the deep sleep until any event has occurred
165182 *
166183 * @param address 8/10 bit I2C slave address
167184 * @param tx_buffer The TX buffer with data to be transfered
168185 * @param tx_length The length of TX buffer in bytes
169- * @param rx_buffer The RX buffer which is used for received data
186+ * @param rx_buffer The RX buffer, which is used for received data
170187 * @param rx_length The length of RX buffer in bytes
171188 * @param event The logical OR of events to modify
172189 * @param callback The event callback function
173190 * @param repeated Repeated start, true - do not send stop at end
174- * @return Zero if the transfer has started, or -1 if I2C peripheral is busy
191+ * default value is false.
192+ *
193+ * @returns Zero if the transfer has started, or -1 if I2C peripheral is busy
175194 */
176195 int transfer (int address, const char *tx_buffer, int tx_length, char *rx_buffer, int rx_length, const event_callback_t &callback, int event = I2C_EVENT_TRANSFER_COMPLETE, bool repeated = false );
177196
178- /* * Abort the on-going I2C transfer
197+ /* * Abort the ongoing I2C transfer
179198 */
180199 void abort_transfer ();
181200
@@ -193,6 +212,7 @@ class I2C : private NonCopyable<I2C> {
193212 bool _deep_sleep_locked;
194213#endif
195214
215+ #if !defined(DOXYGEN_ONLY)
196216protected:
197217 void aquire ();
198218
@@ -202,6 +222,7 @@ class I2C : private NonCopyable<I2C> {
202222 static SingletonPtr<PlatformMutex> _mutex;
203223 PinName _sda;
204224 PinName _scl;
225+ #endif
205226
206227private:
207228 /* * Recover I2C bus, when stuck with SDA low
@@ -210,7 +231,7 @@ class I2C : private NonCopyable<I2C> {
210231 * @param sda I2C data line pin
211232 * @param scl I2C clock line pin
212233 *
213- * @returns:
234+ * @returns
214235 * '0' - Successfully recovered
215236 * 'I2C_ERROR_BUS_BUSY' - In case of failure
216237 *
0 commit comments