Modified version of the official mbed lib providing a RTOS enabled i2c-driver based on the official i2c-C-api.

Dependencies:   mbed-rtos mbed-src

Embed: (wiki syntax)

« Back to documentation index

I2CSlaveRtos Class Reference

I2CSlaveRtos Class Reference

I2C slave interface to the RTOS-I2CDriver. More...

#include <I2CSlaveRtos.h>

Public Types

enum  RxStatus
 

Status returned by the receiveSlave() function.

More...

Public Member Functions

 I2CSlaveRtos (PinName sda, PinName scl, int freq=100000, int address=42)
 Create an I2C Slave interface, connected to the specified pins.
void frequency (int hz)
 Set the frequency of the I2C interface.
int receive (uint32_t timeout_ms=osWaitForever)
 Checks to see if this I2C Slave has been addressed.
int read (char *data, int length)
 Read from an I2C master.
int read (void)
 Read a single byte from an I2C master.
int write (const char *data, int length)
 Write to an I2C master.
int write (int data)
 Write a single byte to an I2C master.
void address (int address)
 Sets the I2C slave address.
void stop (void)
 Reset the I2C slave back into the known ready receiving state.

Detailed Description

I2C slave interface to the RTOS-I2CDriver.

The interface is compatible to the original mbed I2C class.

Definition at line 11 of file I2CSlaveRtos.h.


Member Enumeration Documentation

enum RxStatus

Status returned by the receiveSlave() function.

Definition at line 17 of file I2CSlaveRtos.h.


Constructor & Destructor Documentation

I2CSlaveRtos ( PinName  sda,
PinName  scl,
int  freq = 100000,
int  address = 42 
)

Create an I2C Slave interface, connected to the specified pins.

Parameters:
sdaI2C data line pin
sclI2C clock line pin
Note:
Has to be created in a thread context, i.e. within the main or some other function. A global delaration does not work

Definition at line 31 of file I2CSlaveRtos.h.


Member Function Documentation

void address ( int  address )

Sets the I2C slave address.

Parameters:
addressThe address to set for the slave (ignoring the least signifcant bit). If set to 0, the slave will only respond to the general call address.

Definition at line 108 of file I2CSlaveRtos.h.

void frequency ( int  hz )

Set the frequency of the I2C interface.

Parameters:
hzThe bus frequency in hertz

Definition at line 38 of file I2CSlaveRtos.h.

int read ( void   )

Read a single byte from an I2C master.

Returns:
the byte read

Definition at line 73 of file I2CSlaveRtos.h.

int read ( char *  data,
int  length 
)

Read from an I2C master.

Parameters:
datapointer to the byte array to read data in to
lengthmaximum number of bytes to read
Returns:
0 on success, non-0 otherwise

Definition at line 64 of file I2CSlaveRtos.h.

int receive ( uint32_t  timeout_ms = osWaitForever )

Checks to see if this I2C Slave has been addressed.

Returns:
A status indicating if the device has been addressed, and how
  • 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

Definition at line 51 of file I2CSlaveRtos.h.

void stop ( void   )

Reset the I2C slave back into the known ready receiving state.

Definition at line 115 of file I2CSlaveRtos.h.

int write ( int  data )

Write a single byte to an I2C master.

the byte to write

Returns:
'1' if an ACK was received, '0' otherwise

Definition at line 98 of file I2CSlaveRtos.h.

int write ( const char *  data,
int  length 
)

Write to an I2C master.

Parameters:
datapointer to the byte array to be transmitted
lengththe number of bytes to transmite
Returns:
0 on success, non-0 otherwise

Definition at line 86 of file I2CSlaveRtos.h.