SDK3.5
This document shows Ameba SDK 3.5 APIs
Enumerator

I2C functions. More...

Ameba Common

enum  { I2C_ERROR_NO_SLAVE = -1, I2C_ERROR_BUS_BUSY = -2 }
 
typedef struct i2c_s i2c_t
 
void i2c_init (i2c_t *obj, PinName sda, PinName scl)
 Initializes the I2C device, include clock/function/I2C registers. More...
 
void i2c_frequency (i2c_t *obj, int hz)
 Set i2c frequency. More...
 
int i2c_start (i2c_t *obj)
 Start i2c device. More...
 
int i2c_stop (i2c_t *obj)
 Stop i2c device. More...
 
void i2c_reset (i2c_t *obj)
 Deinitializes the I2C device. More...
 
int i2c_byte_read (i2c_t *obj, int last)
 I2C master receive single byte. More...
 
int i2c_byte_write (i2c_t *obj, int data)
 I2C master send single byte. More...
 
void i2c_slave_mode (i2c_t *obj, int enable_slave)
 Set i2c device to be slave. More...
 
int i2c_slave_receive (i2c_t *obj)
 Get i2c slave state. More...
 
void i2c_slave_address (i2c_t *obj, int idx, uint32_t address, uint32_t mask)
 Set i2c slave address. More...
 
int i2c_read (i2c_t *obj, int address, char *data, int length, int stop)
 I2C master read in poll mode. More...
 
int i2c_write (i2c_t *obj, int address, const char *data, int length, int stop)
 I2C master write in poll mode. More...
 
int i2c_slave_read (i2c_t *obj, char *data, int length)
 I2C slave read in poll mode. More...
 
int i2c_slave_write (i2c_t *obj, const char *data, int length)
 I2C slave write in poll mode. More...
 
int i2c_slave_set_for_rd_req (i2c_t *obj, int set)
 Set/clear i2c slave RD_REQ interrupt mask. More...
 
int i2c_slave_set_for_data_nak (i2c_t *obj, int set_nak)
 Set/clear i2c slave NAK or ACK data part in transfer. More...
 

AmebaZ Only

int i2c_repeatread (i2c_t *obj, int address, u8 *pWriteBuf, int Writelen, u8 *pReadBuf, int Readlen)
 I2C master send data and read data in poll mode. More...
 

Detailed Description

I2C functions.

Function Documentation

int i2c_byte_read ( i2c_t *  obj,
int  last 
)

I2C master receive single byte.

Parameters
obji2c object define in application software.
lasthold the received data.
Return values
the received data.
int i2c_byte_write ( i2c_t *  obj,
int  data 
)

I2C master send single byte.

Parameters
obji2c object define in application software.
datathe data to be sent.
Return values
result.
void i2c_frequency ( i2c_t *  obj,
int  hz 
)

Set i2c frequency.

Parameters
obji2c object define in application software.
hzi2c clock(unit is Hz).
Return values
none
void i2c_init ( i2c_t *  obj,
PinName  sda,
PinName  scl 
)

Initializes the I2C device, include clock/function/I2C registers.

Parameters
obji2c object define in application software.
sdaSDA PinName according to pinmux spec.
sclSCL PinName according to pinmux spec.
Return values
none
int i2c_read ( i2c_t *  obj,
int  address,
char *  data,
int  length,
int  stop 
)

I2C master read in poll mode.

Parameters
obji2c object define in application software.
addressslave address which will be transmitted.
datapoint to the buffer to hold the received data.
lengththe length of data that to be received.
stopspecifies whether a STOP is issued after all the bytes are received.
Return values
the length of data received.
int i2c_repeatread ( i2c_t *  obj,
int  address,
u8 *  pWriteBuf,
int  Writelen,
u8 *  pReadBuf,
int  Readlen 
)

I2C master send data and read data in poll mode.

Parameters
obji2c object define in application software.
addressslave address which will be transmitted.
pWriteBufpoint to the data to be sent.
Writelenthe length of data that to be sent.
pReadBufpoint to the buffer to hold the received data.
Readlenthe length of data that to be received.
Return values
thelength of data received.
void i2c_reset ( i2c_t *  obj)

Deinitializes the I2C device.

Parameters
obji2c object define in application software.
Return values
none
void i2c_slave_address ( i2c_t *  obj,
int  idx,
uint32_t  address,
uint32_t  mask 
)

Set i2c slave address.

Parameters
obji2c object define in application software.
idxi2c index, this parameter can be one of the following values:
  • 0 I2C0 Device
  • 1 I2C1 Device
addressslave address.
maskthe mask of address
Return values
none
void i2c_slave_mode ( i2c_t *  obj,
int  enable_slave 
)

Set i2c device to be slave.

Parameters
obji2c object define in application software.
enable_slaveenable slave function, this parameter can be one of the following values:
  • 0 disable
  • 1 enable
Return values
none
int i2c_slave_read ( i2c_t *  obj,
char *  data,
int  length 
)

I2C slave read in poll mode.

Parameters
obji2c object define in application software.
datapoint to the buffer to hold the received data.
lengththe length of data that to be received.
Return values
the length of data received.
int i2c_slave_receive ( i2c_t *  obj)

Get i2c slave state.

Parameters
obji2c object define in application software.
Return values
the state of i2c slave.
int i2c_slave_set_for_data_nak ( i2c_t *  obj,
int  set_nak 
)

Set/clear i2c slave NAK or ACK data part in transfer.

Parameters
obji2c object define in application software.
set_nakset or clear for data NAK.
Return values
1SUCCESS
int i2c_slave_set_for_rd_req ( i2c_t *  obj,
int  set 
)

Set/clear i2c slave RD_REQ interrupt mask.

Parameters
obji2c object define in application software.
setset or clear for read request.
Return values
1SUCCESS
int i2c_slave_write ( i2c_t *  obj,
const char *  data,
int  length 
)

I2C slave write in poll mode.

Parameters
obji2c object define in application software.
datapoint to the data to be sent.
lengththe length of data that to be sent.
Return values
0FAIL
1SUCCESS
int i2c_start ( i2c_t *  obj)

Start i2c device.

Parameters
obji2c object define in application software.
Return values
0
int i2c_stop ( i2c_t *  obj)

Stop i2c device.

Parameters
obji2c object define in application software.
Return values
0
int i2c_write ( i2c_t *  obj,
int  address,
const char *  data,
int  length,
int  stop 
)

I2C master write in poll mode.

Parameters
obji2c object define in application software.
addressslave address which will be transmitted.
datapoint to the data to be sent.
lengththe length of data that to be sent.
stopspecifies whether a STOP is issued after all the bytes are sent.
Return values
the length of data send.