@@ -41,16 +41,32 @@ namespace mbed {
41
41
*
42
42
* Example:
43
43
* @code
44
- * // Read from I2C slave at address 0x62
45
- *
44
+ * Read temperature from LM75BD
46
45
* #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; // 8bit I2C address, 0x90
49
49
*
50
50
* 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
+ * }
54
70
* }
55
71
* @endcode
56
72
* @ingroup drivers
@@ -92,10 +108,11 @@ class I2C : private NonCopyable<I2C> {
92
108
* @param data Pointer to the byte-array to read data in to
93
109
* @param length Number of bytes to read
94
110
* @param repeated Repeated start, true - don't send stop at end
111
+ * default value is false.
95
112
*
96
113
* @returns
97
114
* 0 on success (ack),
98
- * non-0 on failure (nack)
115
+ * non-zero on failure (nack)
99
116
*/
100
117
int read (int address, char *data, int length, bool repeated = false );
101
118
@@ -117,10 +134,11 @@ class I2C : private NonCopyable<I2C> {
117
134
* @param data Pointer to the byte-array data to send
118
135
* @param length Number of bytes to send
119
136
* @param repeated Repeated start, true - do not send stop at end
137
+ * default value is false.
120
138
*
121
139
* @returns
122
140
* 0 on success (ack),
123
- * non-0 on failure (nack)
141
+ * non-zero on failure (nack)
124
142
*/
125
143
int write (int address, const char *data, int length, bool repeated = false );
126
144
@@ -137,7 +155,6 @@ class I2C : private NonCopyable<I2C> {
137
155
138
156
/* * Creates a start condition on the I2C bus
139
157
*/
140
-
141
158
void start (void );
142
159
143
160
/* * Creates a stop condition on the I2C bus
@@ -171,7 +188,9 @@ class I2C : private NonCopyable<I2C> {
171
188
* @param event The logical OR of events to modify
172
189
* @param callback The event callback function
173
190
* @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
175
194
*/
176
195
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 );
177
196
@@ -212,7 +231,7 @@ class I2C : private NonCopyable<I2C> {
212
231
* @param sda I2C data line pin
213
232
* @param scl I2C clock line pin
214
233
*
215
- * @returns:
234
+ * @returns
216
235
* '0' - Successfully recovered
217
236
* 'I2C_ERROR_BUS_BUSY' - In case of failure
218
237
*
0 commit comments