Mbed OS Reference
|
An I2C Slave, used for communicating with an I2C Master device. More...
#include <I2CSlave.h>
Public Member Functions | |
I2CSlave (PinName sda, PinName scl) | |
Create an I2C Slave interface, connected to the specified pins. More... | |
I2CSlave (const i2c_pinmap_t &static_pinmap) | |
Create an I2C Slave interface, connected to the specified pins. More... | |
void | frequency (int hz) |
Set the frequency of the I2C interface. More... | |
int | receive (void) |
Check if this I2C Slave has been addressed. More... | |
int | read (char *data, int length) |
Read bytes transmitted to this MCU from an I2C master. More... | |
int | read (void) |
Read a single byte from an I2C master. More... | |
int | write (const char *data, int length) |
Write to an I2C master which is addressing this slave device. More... | |
int | write (int data) |
Write a single byte to an I2C master. More... | |
void | address (int address) |
Set the I2C slave address. More... | |
void | stop (void) |
Reset the I2C slave back into the known ready receiving state. More... | |
An I2C Slave, used for communicating with an I2C Master device.
Example Simple I2C slave and master (requires two Mbed-boards):
Definition at line 128 of file I2CSlave.h.
I2CSlave | ( | PinName | sda, |
PinName | scl | ||
) |
I2CSlave | ( | const i2c_pinmap_t & | static_pinmap | ) |
Create an I2C Slave interface, connected to the specified pins.
static_pinmap | reference to structure which holds static pinmap. |
void frequency | ( | int | hz | ) |
Set the frequency of the I2C interface.
hz | The bus frequency in Hertz. |
int receive | ( | void | ) |
Check if this I2C Slave has been addressed.
NoData | The slave has not been addressed. |
ReadAddressed | The master has requested a read from this slave. |
WriteAddressed | The master is writing to this slave. |
WriteGeneral | The master is writing to all slave. |
int read | ( | char * | data, |
int | length | ||
) |
int read | ( | void | ) |
Read a single byte from an I2C master.
int write | ( | const char * | data, |
int | length | ||
) |
Write to an I2C master which is addressing this slave device.
Call this function only once receive()
returns ReadAddressed. This will send the given data bytes to the master and then send a NACK to end the read transaction.
data | Pointer to the buffer containing the data to be sent. |
length | Number of bytes to send. |
0 | If written all bytes successfully. |
nonzero | On error or if the number of bytes written is less than requested. |
int write | ( | int | data | ) |
Write a single byte to an I2C master.
data | Value to write. |
0 | If a NACK is received. |
1 | If an ACK is received. |
2 | On timeout. |
void address | ( | int | address | ) |
Set the I2C slave address.
address | The 8-bit address to set for the slave (least significant bit is ignored). |
void stop | ( | void | ) |
Reset the I2C slave back into the known ready receiving state.