api / mbed / trunk / I2C
I2C
class I2C : public Base
An I2C Master, used for communicating with I2C slave devices
Example
// Read from I2C slave at address 0x62
#include "mbed.h"
I2C i2c(p28, p27);
int main() {
int address = 0x62;
char data[2];
i2c.read(address, data, 2);
}| I2C | An I2C Master, used for communicating with I2C slave devices |
| Functions | |
| I2C | Create an I2C Master interface, connected to the specified pins |
| frequency | Set the frequency of the I2C interface |
| read | Read from an I2C slave |
| read | Read a single byte from the I2C bus |
| write | Write to an I2C slave |
| write | Write single byte out on the I2C bus |
| start | Creates a start condition on the I2C bus |
| stop | Creates a stop condition on the I2C bus |
read
int read( int address, char * data, int length, bool repeated = false )
Read from an I2C slave
Performs a complete read transaction. The bottom bit of the address is forced to 1 to indicate a read.
Variables
| address | 8-bit I2C slave address [ addr | 1 ] |
| data | Pointer to the byte-array to read data in to |
| length | Number of bytes to read |
| repeated | Repeated start, true - don’t send stop at end |
| returns | 0 on success (ack), or non-0 on failure (nack) |
write
int write( int address, const char * data, int length, bool repeated = false )
Write to an I2C slave
Performs a complete write transaction. The bottom bit of the address is forced to 0 to indicate a write.
Variables
| address | 8-bit I2C slave address [ addr | 0 ] |
| data | Pointer to the byte-array data to send |
| length | Number of bytes to send |
| repeated | Repeated start, true - do not send stop at end |
| returns | 0 on success (ack), or non-0 on failure (nack) |
An I2C Master, used for communicating with I2C slave devices
class I2C : public Base
Create an I2C Master interface, connected to the specified pins
I2C( PinName sda, PinName scl, const char * name = NULL )
Set the frequency of the I2C interface
void frequency( int hz )
Read from an I2C slave
int read( int address, char * data, int length, bool repeated = false )
Write to an I2C slave
int write( int address, const char * data, int length, bool repeated = false )
Creates a start condition on the I2C bus
void start( void )
Creates a stop condition on the I2C bus
void stop( void )
