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 specified number of bytes 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. 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 responder:
Definition at line 72 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 address | ( | int | address | ) |
Set the I2C slave address.
address | The address to set for the slave (least significant bit is ignored). |
void frequency | ( | int | hz | ) |
Set the frequency of the I2C interface.
hz | The bus frequency in Hertz. |
int read | ( | char * | data, |
int | length | ||
) |
Read specified number of bytes from an I2C master.
data | Pointer to the buffer to read data into. |
length | Number of bytes to read. |
0 | If the number of bytes read is equal to length requested. |
nonzero | On error or if the number of bytes read is less than requested. |
int read | ( | void | ) |
Read a single byte from an I2C master.
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. |
void stop | ( | void | ) |
Reset the I2C slave back into the known ready receiving state.
int write | ( | const char * | data, |
int | length | ||
) |
Write to an I2C master.
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. |