I2C Master

Functions for using Inter-Integrated Circuit (I2C) peripheral. More...

Modules

Types
Hardware I2C data types.
 
Macros
Hardware I2C macros.
 

Functions

zos_result_t zn_i2c_stream_configure (uint8_t slave_address, uint32_t clock_rate, uint16_t retries, uint16_t flags)
 Configure an I2C slave device. More...
 
zos_result_t zn_i2c_stream_open (uint32_t *handle, uint16_t rx_buffer_size)
 Open data stream with I2C slave device. More...
 
zos_result_t zn_i2c_stream_write (uint32_t handle, const void *data, uint32_t size)
 Write I2C data stream. More...
 
zos_result_t zn_i2c_stream_write_with_flags (uint32_t handle, const void *data, uint32_t size, zos_i2c_write_flag_t flags)
 Write I2C data stream with specific flags. More...
 
zos_result_t zn_i2c_stream_read (uint32_t handle, void *data, uint32_t max_size, uint32_t *bytes_read)
 Read I2C data stream. More...
 
zos_result_t zn_i2c_stream_write_reg8 (uint32_t handle, uint8_t reg_address, uint8_t value)
 Write I2C device's register with 8bit value. More...
 
zos_result_t zn_i2c_stream_write_reg (uint32_t handle, uint8_t reg_address, const uint8_t *data, uint16_t length)
 Write I2C device's register with given data. More...
 
zos_result_t zn_i2c_stream_read_reg8 (uint32_t handle, uint8_t reg_address, uint8_t *value_ptr)
 Read I2C device's register's 8bit value. More...
 
zos_result_t zn_i2c_stream_read_reg (uint32_t handle, uint8_t reg_address, uint8_t *data, uint16_t length)
 Read I2C device's register(s) into given buffer. More...
 
zos_result_t zn_i2c_stream_close (uint32_t handle)
 Close I2C data stream. More...
 
zos_result_t zn_i2c_stream_set_slave_address (uint32_t handle, uint8_t slave_address)
 Set I2C data stream's slave address. More...
 
zos_result_t zn_i2c_init (const zos_i2c_device_t *i2c)
 Initialize the I2C bus. More...
 
zos_result_t zn_i2c_transfer (const zos_i2c_device_t *i2c, const zos_i2c_message_t *messages, uint16_t message_count)
 Transfer I2C messages. More...
 
zos_result_t zn_i2c_master_write_reg8 (const zos_i2c_device_t *i2c, uint8_t reg_address, uint8_t value)
 Write register with 8bit value. More...
 
zos_result_t zn_i2c_master_write_reg (const zos_i2c_device_t *i2c, uint8_t reg_address, const uint8_t *data, uint16_t length)
 Write register with given buffer. More...
 
zos_result_t zn_i2c_master_read_reg8 (const zos_i2c_device_t *i2c, uint8_t reg_address, uint8_t *value_ptr)
 Read register's 8bit value. More...
 
zos_result_t zn_i2c_master_read_reg (const zos_i2c_device_t *i2c, uint8_t reg_address, uint8_t *data, uint16_t length)
 Read register into given buffer. More...
 

Detailed Description

Functions for using Inter-Integrated Circuit (I2C) peripheral.

Function Documentation

zos_result_t zn_i2c_init ( const zos_i2c_device_t i2c)

Initialize the I2C bus.

This API directly accesses the I2C driver.

Note
zn_i2c_transfer() will automatically initialize the bus, is this only needed to re-initialize the bus
Parameters
[in]i2cI2C slave device, see zos_i2c_device_t
Returns
result of API call
zos_result_t zn_i2c_master_read_reg ( const zos_i2c_device_t i2c,
uint8_t  reg_address,
uint8_t *  data,
uint16_t  length 
)

Read register into given buffer.

Note
This API directly accesses the I2C driver.
Parameters
[in]i2cI2C slave device, see zos_i2c_device_t
[in]reg_address8bit I2C slave register address
[out]dataBuffer to hold register value(s)
[in]lengthNumber of bytes to read
Returns
result of API call
zos_result_t zn_i2c_master_read_reg8 ( const zos_i2c_device_t i2c,
uint8_t  reg_address,
uint8_t *  value_ptr 
)

Read register's 8bit value.

Note
This API directly accesses the I2C driver.
Parameters
[in]i2cI2C slave device, see zos_i2c_device_t
[in]reg_address8bit I2C slave device register address
[out]value_ptrValue of register
Returns
result of API call
zos_result_t zn_i2c_master_write_reg ( const zos_i2c_device_t i2c,
uint8_t  reg_address,
const uint8_t *  data,
uint16_t  length 
)

Write register with given buffer.

Note
This API directly accesses the I2C driver.
Parameters
[in]i2cI2C slave device, see zos_i2c_device_t
[in]reg_address8bit I2C slave device register address
[in]dataData to write to slave device's register(s)
[in]lengthNumber of bytes to write to device
Returns
result of API call
zos_result_t zn_i2c_master_write_reg8 ( const zos_i2c_device_t i2c,
uint8_t  reg_address,
uint8_t  value 
)

Write register with 8bit value.

Note
This API directly accesses the I2C driver.
Parameters
[in]i2cI2C slave device, see zos_i2c_device_t
[in]reg_address8bit I2C slave device register address
[in]value8bit value to write to slave device's register
Returns
result of API call
zos_result_t zn_i2c_stream_close ( uint32_t  handle)

Close I2C data stream.

See ZentriOS Command API documentation: stream_close

Parameters
[in]handleHandle of I2C stream
Returns
result of API call
zos_result_t zn_i2c_stream_configure ( uint8_t  slave_address,
uint32_t  clock_rate,
uint16_t  retries,
uint16_t  flags 
)

Configure an I2C slave device.

See ZentriOS Command API documentation: i2c_master_config.

Parameters
[in]slave_address7bit slave address of I2C device
[in]clock_rateClock rate of I2C device
[in]retriesNumber of attempts to read/write a message from/to slave device
[in]flagsConfiguration flags
Returns
result of API call
zos_result_t zn_i2c_stream_open ( uint32_t *  handle,
uint16_t  rx_buffer_size 
)

Open data stream with I2C slave device.

See ZentriOS Command API documentation: i2c_master_open.

The device must have been previously configured with zn_i2c_stream_configure()

Once opened used a zn_i2c_stream_xxx API to read/write the device.

Parameters
[out]handleStream handle of opened I2C slave stream
[in]rx_buffer_sizeSize of RX buffer in bytes
Returns
result of API call
zos_result_t zn_i2c_stream_read ( uint32_t  handle,
void *  data,
uint32_t  max_size,
uint32_t *  bytes_read 
)

Read I2C data stream.

See ZentriOS Command API documentation: stream_read, i2c_master_open.

Parameters
[in]handleHandle of I2C stream
[out]dataBuffer to hold read data
[in]max_sizeMaximum number of bytes to read
[out]bytes_readNumber of bytes actually read
Returns
result of API call
zos_result_t zn_i2c_stream_read_reg ( uint32_t  handle,
uint8_t  reg_address,
uint8_t *  data,
uint16_t  length 
)

Read I2C device's register(s) into given buffer.

See ZentriOS Command API documentation: stream_read, i2c_master_open.

Parameters
[in]handleHandle of I2C stream
[in]reg_address8bit I2C slave register address
[out]dataBuffer to hold register value(s)
[in]lengthNumber of bytes to read
Returns
result of API call
zos_result_t zn_i2c_stream_read_reg8 ( uint32_t  handle,
uint8_t  reg_address,
uint8_t *  value_ptr 
)

Read I2C device's register's 8bit value.

See ZentriOS Command API documentation: stream_read, i2c_master_open.

Parameters
[in]handleHandle of I2C stream
[in]reg_address8bit I2C slave register address
[out]value_ptrValue of register
Returns
result of API call
zos_result_t zn_i2c_stream_set_slave_address ( uint32_t  handle,
uint8_t  slave_address 
)

Set I2C data stream's slave address.

Multiple I2C devices may be accessed using the same I2C stream. Each I2C device should first be configured using zn_i2c_stream_configure() . This API can then be used to switch between the I2C slave devices.

Parameters
[in]handleHandle of I2C stream
[in]slave_addressSlave address to update given I2C stream
Returns
result of API call
zos_result_t zn_i2c_stream_write ( uint32_t  handle,
const void *  data,
uint32_t  size 
)

Write I2C data stream.

See ZentriOS Command API documentation: stream_write, i2c_master_open.

Parameters
[in]handleHandle of I2C stream
[in]dataData to write to device
[in]sizeSize in bytes of data to write
Returns
result of API call
zos_result_t zn_i2c_stream_write_reg ( uint32_t  handle,
uint8_t  reg_address,
const uint8_t *  data,
uint16_t  length 
)

Write I2C device's register with given data.

See ZentriOS Command API documentation: stream_write, i2c_master_open.

Parameters
[in]handleHandle of I2C stream
[in]reg_address8bit I2C slave register address
[in]dataData to write
[in]lengthSize in bytes of data to write
Returns
result of API call
zos_result_t zn_i2c_stream_write_reg8 ( uint32_t  handle,
uint8_t  reg_address,
uint8_t  value 
)

Write I2C device's register with 8bit value.

See ZentriOS Command API documentation: stream_write, i2c_master_open.

Parameters
[in]handleHandle of I2C stream
[in]reg_address8bit I2C slave register address
[in]value8bit value to write to slave
Returns
result of API call
zos_result_t zn_i2c_stream_write_with_flags ( uint32_t  handle,
const void *  data,
uint32_t  size,
zos_i2c_write_flag_t  flags 
)

Write I2C data stream with specific flags.

See ZentriOS Command API documentation: stream_write, i2c_master_open.

Parameters
[in]handleHandle of I2C stream
[in]dataData to write to device
[in]sizeSize in bytes of data to write
[in]flagsAdditional write flags, see zos_i2c_write_flag_t
Returns
result of API call
zos_result_t zn_i2c_transfer ( const zos_i2c_device_t i2c,
const zos_i2c_message_t messages,
uint16_t  message_count 
)

Transfer I2C messages.

Transfer one or more messages to/from an I2C slave device.

Note
This API directly accesses the I2C driver.
Parameters
[in]i2cI2C slave device, see zos_i2c_device_t
[in,out]messagesArray of zos_i2c_message_t to send/receive to/from I2C slave device
[in]message_countNumber of messages to transfer
Returns
result of API call