rfLPC
A low level library for using NXP's LPC17xx SoC. Config is given for MBED prototyping board

Provides functions for I2C bus manipulation. More...

Enumerations

enum  rflpc_i2c_port_t {
  RFLPC_I2C_PORT0,
  RFLPC_I2C_PORT1,
  RFLPC_I2C_PORT2
}
 These constants selects which port the driver functions manipulate. More...
 
enum  rflpc_i2c_mode_t {
  RFLPC_I2C_MODE_MASTER,
  RFLPC_I2C_MODE_SLAVE
}
 Defines the operating mode of the I2C bus. More...
 
enum  rflpc_i2c_status_t {
  RFLPC_I2C_SUCCESSFUL_TRANSMISSION = 0,
  RFLPC_I2C_SIZE_EQUAL_TO_ZERO,
  RFLPC_I2C_SLAVE_IS_BUSY,
  RFLPC_I2C_SLAVE_DID_NOT_ACKNOWLEDGED_DATA,
  RFLPC_I2C_MASTER_DID_NOT_ACKNOWLEDGED_DATA,
  RFLPC_I2C_STOP_CONDITION_RECEIVED,
  RFLPC_I2C_SLAVE_TRANSMITTED_DATA,
  RFLPC_I2C_UNKNOWN_ERROR,
  RFLPC_I2C_NOT_YET_IMPLEMENTED
}
 Defines the return status of the I2C driver. More...
 

Functions

int rflpc_i2c_init (rflpc_i2c_port_t port, rflpc_i2c_mode_t mode, uint8_t addr)
 Inits a given I2C port on a given mode. More...
 
uint16_t rflpc_i2c_write (rflpc_i2c_port_t port, uint8_t addr, uint8_t *data, uint8_t nbytes, uint8_t stop)
 Send bytes on the I2C bus. More...
 
uint16_t rflpc_i2c_read (rflpc_i2c_port_t port, uint8_t addr, uint8_t *data, uint8_t nbytes, uint8_t stop)
 Reads data from the I2C bus. More...
 
void rflpc_i2c_set_slave_transmitter_config (uint8_t *data, uint8_t size)
 Set data's location and size to be transmitted as slave. More...
 

Detailed Description

Provides functions for I2C bus manipulation.

Enumeration Type Documentation

Defines the operating mode of the I2C bus.

Definition at line 47 of file i2c.h.

These constants selects which port the driver functions manipulate.

Definition at line 40 of file i2c.h.

Defines the return status of the I2C driver.

Definition at line 53 of file i2c.h.

Function Documentation

int rflpc_i2c_init ( rflpc_i2c_port_t  port,
rflpc_i2c_mode_t  mode,
uint8_t  addr 
)

Inits a given I2C port on a given mode.

Parameters
portThe I2C port to initialize (cf. rflpc_i2c_port_t)
modeThe I2C mode to use (cf. rflpc_i2c_mode_t)
addrIf Slave mode is requested, this parameter is the I2C address of
Returns
If initialization was successful, returns 0. Else, returns -1.
Note
The port is configured to operate at 100kHz (standard mode).
At this time, ONLY MASTER MODE is allowed and functionnal.
uint16_t rflpc_i2c_read ( rflpc_i2c_port_t  port,
uint8_t  addr,
uint8_t *  data,
uint8_t  nbytes,
uint8_t  stop 
)

Reads data from the I2C bus.

Parameters
[in]portThe I2C port to read on.
[in]addrThe I2C address of the slave from which a message will be read.
[in]dataA pointer to a data buffer where the message will be stored.
[in]nbytesThe expected number of bytes to be received.
[in]stopIf equal to zero, the driver will send a RESTART condition instead of a STOP condition at the end of transmission.
Returns
Returns a 16-bits value. The 8 MSBs store the final status of I2C action. The 8 LSBs store the effective number of bytes transmitted.
Note
In Slave mode, in case of receiving a Read command, this driver will automatically switch to rflpc_i2c_write to transmit data. Data to be transmitted can be set using the rflpc_i2c_set_slave_transmitter_config function. If this Slave to Master transmission is successful, the 8 MSBs of the returned value will store the RFLPC_I2C_SLAVE_TRANSMITTED_DATA specific status, and the 8 LSBs of the returned value will store the number of bytes transmitted, matching the number of bytes to transmit as set with rflpc_i2c_set_slave_transmitter_config. If this Slave to Master transmission fails, the returned value will be the returned value of the internal call of rflpc_i2c_write, which is similar as an external call. See documentation of rflpc_i2c_status_t for more informations.
void rflpc_i2c_set_slave_transmitter_config ( uint8_t *  data,
uint8_t  size 
)

Set data's location and size to be transmitted as slave.

Parameters
[in]dataA pointer to the data to be transmitted.
[in]sizeSize in bytes of the data to be transmitted.
Note
Size must be greater than zero. If not, this function has no effect.
uint16_t rflpc_i2c_write ( rflpc_i2c_port_t  port,
uint8_t  addr,
uint8_t *  data,
uint8_t  nbytes,
uint8_t  stop 
)

Send bytes on the I2C bus.

Parameters
[in]portThe I2C port to write on.
[in]addrThe I2C address of the slave to which the message will be sent. This parameter has no effect if Slave mode is set.
[in]dataA pointer to the data buffer to be transmitted.
[in]nbytesThe number of bytes to be transmitted.
[in]stopIf equal to zero, the driver will send a RESTART condition instead of a STOP condition at the end of transmission.
Returns
Returns a 16-bits value. The 8 MSBs store the final status of I2C action. The 8 LSBs store the effective number of bytes transmitted.