Infineon Logo AIROC BTSDK v4.0 - Documentation
 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages

Defines an I2C driver to facilitate communication with other devices on an I2C bus (such as a temperature sensor, etc). More...

Modules

 I2C EEPROM Interface
 Defines a driver for the I2C EEPROM interface.
 

Enumerations

enum  { I2CM_SPEED_100KHZ = 240, I2CM_SPEED_400KHZ = 60, I2CM_SPEED_800KHZ = 30, I2CM_SPEED_1000KHZ = 24 }
 Speed Options. More...
 
enum  { I2CM_SUCCESS, I2CM_OP_FAILED }
 Transaction Status Return Values. More...
 

Functions

void wiced_hal_i2c_init (void)
 Initializes the I2C driver and its private values. More...
 
void wiced_hal_i2c_set_speed (uint8_t speed)
 Sets the I2C bus speed. More...
 
uint8_t wiced_hal_i2c_get_speed (void)
 Gets the current I2C bus speed. More...
 
uint8_t wiced_hal_i2c_read (uint8_t *data, uint16_t length, uint8_t slave)
 Reads data into given buffer from the I2C HW addressing a particualr slave address. More...
 
uint8_t wiced_hal_i2c_write (uint8_t *data, uint16_t length, uint8_t slave)
 Writes the given data to the I2C HW addressing a particualr slave address. More...
 
void wiced_hal_i2c_select_pads (uint8_t scl_pin, uint8_t sda_pin)
 Configures I2C pins. More...
 
uint8_t wiced_hal_i2c_combined_read (uint8_t *rx_data, uint8_t rx_data_len, uint8_t *tx_data, uint16_t tx_data_len, uint8_t slave)
 Executes two transactions back-to-back with a repeated start condition between the first and the second. More...
 

Detailed Description

Defines an I2C driver to facilitate communication with other devices on an I2C bus (such as a temperature sensor, etc).

The driver is only capable of assuming a master role. Applications use this driver to obtain the status from and control the behavior of the I2C hardware. This driver only offers services for speed control and data transfer operations.

Please note that even though this driver can access off-chip memory (if installed; EEPROM, etc), please use the drivers found in wiced_hal_ieeprom.h to access those modules, as those drivers include checks to ensure safe data handling operations. This driver is intended only to interface with other devices on the I2C bus, such as a motion sensor.

Enumeration Type Documentation

anonymous enum

Speed Options.

Enumerator
I2CM_SPEED_100KHZ 

I2C speed is 100 KHz.

I2CM_SPEED_400KHZ 

I2C speed is 400 KHz.

I2CM_SPEED_800KHZ 

I2C speed is 800 KHz.

I2CM_SPEED_1000KHZ 

I2C speed is 1 MHz.

anonymous enum

Transaction Status Return Values.

Enumerator
I2CM_SUCCESS 

The transaction was sucessful.

I2CM_OP_FAILED 

The attempted operation failed, possibly because of no ack from slave.

Function Documentation

uint8_t wiced_hal_i2c_combined_read ( uint8_t *  rx_data,
uint8_t  rx_data_len,
uint8_t *  tx_data,
uint16_t  tx_data_len,
uint8_t  slave 
)

Executes two transactions back-to-back with a repeated start condition between the first and the second.

tx_data is written to the slave in the first transaction while data is read back from the slave into rx_data after the repeated start.

Parameters
rx_dataPointer to the buffer where data is to be read after the repeated start
rx_data_lenNumber of bytes to read from slaveAdr - rx_data should be at least this big
tx_dataPointer to the buffer that is to be written to the slave
tx_data_lenNumber of bytes to write to the slave starting from tx_data
slaveslave addr
Returns
The status of the transaction (success[0], failure[1])
uint8_t wiced_hal_i2c_get_speed ( void  )

Gets the current I2C bus speed.

Smaller numbers indicate higher speeds. See the Parameters section for more information.

Parameters
none
Returns
The SCL ref clock cycle counter value that corresponding to the SCL speed.
void wiced_hal_i2c_init ( void  )

Initializes the I2C driver and its private values.

This initialization sets the bus speed to 100KHz by default (I2CM_SPEED_100KHZ). To make the bus run at another speed, call wiced_hal_i2c_setSpeed(<speed>) right after this call.

I2C pins are configured through platform_gpio_pins[] in wiced_platform_pin_config.c In case of change in I2C pins from default platform initialization, the user needs to use external pull-ups or internal GPIO pull-ups. It is recommended to use external pull-ups for a reliable design

Parameters
none
Returns
none
uint8_t wiced_hal_i2c_read ( uint8_t *  data,
uint16_t  length,
uint8_t  slave 
)

Reads data into given buffer from the I2C HW addressing a particualr slave address.

The data bytes are transparent. Though any arbitrary length of data may be read from the slave, atomic transactions greater than HW's capability are not possible - they will be split into multiple transactions. This is a blocking call. Interrupts will not affect timing within a transaction. Note: Please see the Kit Guide or HW User Manual for your device for the actual limitation of the part on your platform.

Parameters
data- Pointer to a buffer that will hold the incoming data.
length- The length of the data to read.
slave- The source slave address.
Returns
The status of the transaction (success[0], failure[1]).
void wiced_hal_i2c_select_pads ( uint8_t  scl_pin,
uint8_t  sda_pin 
)

Configures I2C pins.

Parameters
scl_pinLHL GPIO to be used for SCL
sda_pinLHL GPIO to be used for SDA
void wiced_hal_i2c_set_speed ( uint8_t  speed)

Sets the I2C bus speed.

Note that the default after initialization is set to 100KHz by default (I2CM_SPEED_100KHZ). To make the bus run at another speed, use one of the following parameters (also see Parameters section):

// I2C speed is 100 KHz
I2CM_SPEED_100KHZ

// I2C speed is 400 KHz
I2CM_SPEED_400KHZ

// I2C speed is 800 KHz
I2CM_SPEED_800KHZ

// I2C speed is 1 MHz
I2CM_SPEED_1000KHZ
Parameters
speed- The new speed to be used. This is the transport clock counter that counts the number of reference clock cycles.
Returns
none
uint8_t wiced_hal_i2c_write ( uint8_t *  data,
uint16_t  length,
uint8_t  slave 
)

Writes the given data to the I2C HW addressing a particualr slave address.

The data bytes are transparent. Though any arbitrary length of data may be written to the slave, atomic transactions greater than HW's capability are not possible - they will be split into multiple transactions. This is a blocking call. Interrupts will not affect timing within a transaction. Note: Please see the Kit Guide or HW User Manual for your device for the actual limitation of the part on your platform.

Parameters
data- Pointer to a buffer holding the data to write.
length- The length of the data to write.
slave- The destination slave address.
Returns
The status of the transaction (success[0], failure[1]).