I2C Functions


Data Structures

struct  i2c_address

Defines

#define I2C_ARBITRATION_LOST   7
#define I2C_BUSY   1
#define I2C_CONT_NACK_ON_ADDR   1
#define I2C_CONT_NACK_ON_DATA   2
#define I2C_DEVICE_NOT_PRESENT   6
#define I2C_ERR   2
#define I2C_INIT_ERROR   10
#define I2C_MAX_RETRY   11
#define I2C_NACK_ON_ADDRESS   5
#define I2C_NACK_ON_DATA   4
#define I2C_NO_DATA   3
#define I2C_NOBUS   12
#define I2C_SLAVE_ERROR   9
#define I2C_TIME_OUT   8

Typedefs

typedef i2c_address i2c_addr_t

Functions

int32_t i2c_init (u_int16_t mode)
int32_t i2c_init_clock (u_int16_t mode, u_int8_t frequency)
 initialse and reset the i2c controller and set i2c clock
void i2c_perror (int rc, char *msg)
 print and i2c error message
int32_t i2c_read_rbt (u_int32_t addr, u_int8_t *buf, u_int32_t count, u_int32_t *bytecount, u_int32_t *flag)
int32_t i2c_scan (u_int32_t addr, u_int8_t dir)
 scan for an i2c device
int32_t i2c_write_rbt (u_int32_t addr, u_int8_t *buf, u_int32_t count, u_int32_t *bytecount, u_int32_t *flag)
int32_t i2c_writeread_rbt (u_int32_t addr, u_int8_t *wbuf, u_int32_t wcount, u_int8_t *rbuf, u_int32_t rcount, u_int32_t *flag)
 write to i2c device issued a repeated start condition then read

Define Documentation

#define I2C_ARBITRATION_LOST   7
 

err: Device not present

#define I2C_BUSY   1
 

transfer ended No Errors

#define I2C_CONT_NACK_ON_ADDR   1
 

ignore NACK from slave on address byte

#define I2C_CONT_NACK_ON_DATA   2
 

ignore NACK from slave on data byte

#define I2C_DEVICE_NOT_PRESENT   6
 

err: No ack on address

#define I2C_ERR   2
 

transfer busy

#define I2C_INIT_ERROR   10
 

err: Slave mode error

#define I2C_MAX_RETRY   11
 

err: Initialization (not done)

#define I2C_NACK_ON_ADDRESS   5
 

err: No ack on data

#define I2C_NACK_ON_DATA   4
 

err: No data in block

#define I2C_NO_DATA   3
 

err: general error

#define I2C_NOBUS   12
 

exceeded maximal number of retries

#define I2C_SLAVE_ERROR   9
 

err: Time out occurred

#define I2C_TIME_OUT   8
 

err: Arbitration lost


Typedef Documentation

typedef struct i2c_address i2c_addr_t
 

full i2c address with channel and bus address


Function Documentation

int32_t i2c_init u_int16_t  mode  ) 
 

initialise and reset the i2c controller

Parameters:
mode master or slave. Use 0 for master
Bug:
slave mode is not supported yet. Putting the controller in slave mode will work. But an external master will not be able to write to the glue-card

int32_t i2c_init_clock u_int16_t  mode,
u_int8_t  frequency
 

initialse and reset the i2c controller and set i2c clock

Parameters:
mode i2c_init
frequency i2c clock frequency according to PCF8845 data sheet

void i2c_perror int  rc,
char *  msg
 

print and i2c error message

This is an emulation of the standard perror function. Since there is no global i2c error variable (this is maybe a design flaw), the status value must be passed.

Parameters:
rc the return code of an i2c function
*msg a message to be prepended

int32_t i2c_read_rbt u_int32_t  addr,
u_int8_t *  buf,
u_int32_t  count,
u_int32_t *  bytecount,
u_int32_t *  flag
 

read bytes from i2c

Parameters:
addr i2c_address
*buf buffer for bytes to read
count number of bytes to read
*bytecount number of bytes actually read
*flag is an OR of I2C_CONT_NACK_ON_ADDR and I2C_CONT_NACK_ON_DATA. The respective conditions will be ignored. On return *flag will have the bits set if the ignored condition has been encountered during processing.

int32_t i2c_scan u_int32_t  addr,
u_int8_t  dir
 

scan for an i2c device

Parameters:
addr i2c_address
dir can be I2C_SCAN_READ or I2C_SCAN_WRITE (usally WRITE works better)

int32_t i2c_write_rbt u_int32_t  addr,
u_int8_t *  buf,
u_int32_t  count,
u_int32_t *  bytecount,
u_int32_t *  flag
 

write bytes to i2c

Parameters:
addr i2c_address
*buf buffer with bytes to write
count number of bytes to write
*bytecount number of bytes actually written
*flag is an OR of I2C_CONT_NACK_ON_ADDR and I2C_CONT_NACK_ON_DATA. The respective conditions will be ignored. On return *flag will have the bits set if the ignored condition has been encountered during processing.

int32_t i2c_writeread_rbt u_int32_t  addr,
u_int8_t *  wbuf,
u_int32_t  wcount,
u_int8_t *  rbuf,
u_int32_t  rcount,
u_int32_t *  flag
 

write to i2c device issued a repeated start condition then read

Bug:
This might not be flexible enough for all situations (multiple repeats)
Parameters:
addr i2c_address
*wbuf buffer with bytes to write
wcount number of bytes to write
*rbuf buffer for bytes to be read
rcount number of bytes to be read
*flag is an OR of I2C_CONT_NACK_ON_ADDR and I2C_CONT_NACK_ON_DATA. The respective conditions will be ignored. On return *flag will have the bits set if the ignored condition has been encountered during processing.


Generated on Thu Mar 23 21:03:37 2006 for CCPC i2culib by  doxygen 1.4.6