XCORE SDK
XCORE Software Development Kit
Classes | Typedefs | Enumerations | Functions
hil_i2c_master

Classes

struct  i2c_master_struct
 

Typedefs

typedef struct i2c_master_struct i2c_master_t
 

Enumerations

enum  i2c_res_t { I2C_NACK , I2C_ACK , I2C_STARTED , I2C_NOT_STARTED }
 

Functions

i2c_res_t i2c_master_write (i2c_master_t *ctx, uint8_t device_addr, uint8_t buf[], size_t n, size_t *num_bytes_sent, int send_stop_bit)
 
i2c_res_t i2c_master_read (i2c_master_t *ctx, uint8_t device_addr, uint8_t buf[], size_t n, int send_stop_bit)
 
void i2c_master_stop_bit_send (i2c_master_t *ctx)
 
void i2c_master_init (i2c_master_t *ctx, const port_t p_scl, const uint32_t scl_bit_position, const uint32_t scl_other_bits_mask, const port_t p_sda, const uint32_t sda_bit_position, const uint32_t sda_other_bits_mask, const unsigned kbits_per_second)
 
void i2c_master_shutdown (i2c_master_t *ctx)
 

Detailed Description

The public API for using the RTOS I2C slave driver.

Typedef Documentation

◆ i2c_master_t

Type representing an I2C master context

Enumeration Type Documentation

◆ i2c_res_t

enum i2c_res_t

Status codes for I2C master operations

Enumerator
I2C_NACK 

The slave has NACKed the last byte.

I2C_ACK 

The slave has ACKed the last byte.

I2C_STARTED 

The requested I2C transaction has started.

I2C_NOT_STARTED 

The requested I2C transaction could not start.

Function Documentation

◆ i2c_master_init()

void i2c_master_init ( i2c_master_t ctx,
const port_t  p_scl,
const uint32_t  scl_bit_position,
const uint32_t  scl_other_bits_mask,
const port_t  p_sda,
const uint32_t  sda_bit_position,
const uint32_t  sda_other_bits_mask,
const unsigned  kbits_per_second 
)

Implements an I2C master device on one or two single or multi-bit ports.

Parameters
ctxA pointer to the I2C master context to initialize.
p_sclThe port containing SCL. This may be either the same as or different than p_sda.
scl_bit_positionThe bit number of the SCL line on the port p_scl.
scl_other_bits_maskA value that is ORed into the port value driven to p_scl both when SCL is high and low. The bit representing SCL (as well as SDA if they share the same port) must be set to 0.
p_sdaThe port containing SDA. This may be either the same as or different than p_scl.
sda_bit_positionThe bit number of the SDA line on the port p_sda.
sda_other_bits_maskA value that is ORed into the port value driven to p_sda both when SDA is high and low. The bit representing SDA (as well as SCL if they share the same port) must be set to 0.
kbits_per_secondThe speed of the I2C bus. The maximum value allowed is 400.

◆ i2c_master_read()

i2c_res_t i2c_master_read ( i2c_master_t ctx,
uint8_t  device_addr,
uint8_t  buf[],
size_t  n,
int  send_stop_bit 
)

Reads data from an I2C bus as a master.

Parameters
ctxA pointer to the I2C master context to use.
device_addrThe address of the device to read from.
bufThe buffer to fill with data.
nThe number of bytes to read.
send_stop_bitIf this is non-zero then a stop bit. will be sent on the bus after the transaction. This is usually required for normal operation. If this parameter is zero then no stop bit will be omitted. In this case, no other task can use the component until a stop bit has been sent.
Returns
I2C_ACK if the read was acknowledged by the device, I2C_NACK otherwise.

◆ i2c_master_shutdown()

void i2c_master_shutdown ( i2c_master_t ctx)

Shuts down the I2C master device.

Parameters
ctxA pointer to the I2C master context to shut down.

This function disables the ports associated with the I2C master and deallocates its timer if it was not provided by the application.

If subsequent reads or writes need to be performed, then i2c_master_init() must be called again first.

◆ i2c_master_stop_bit_send()

void i2c_master_stop_bit_send ( i2c_master_t ctx)

Send a stop bit to an I2C bus as a master.

This function will cause a stop bit to be sent on the bus. It should be used to complete/abort a transaction if the send_stop_bit argument was not set when calling the i2c_master_read() or i2c_master_write() functions.

Parameters
ctxA pointer to the I2C master context to use.

◆ i2c_master_write()

i2c_res_t i2c_master_write ( i2c_master_t ctx,
uint8_t  device_addr,
uint8_t  buf[],
size_t  n,
size_t *  num_bytes_sent,
int  send_stop_bit 
)

Writes data to an I2C bus as a master.

Parameters
ctxA pointer to the I2C master context to use.
device_addrThe address of the device to write to.
bufThe buffer containing data to write.
nThe number of bytes to write.
num_bytes_sentThe function will set this value to the number of bytes actually sent. On success, this will be equal to n but it will be less if the slave sends an early NACK on the bus and the transaction fails.
send_stop_bitIf this is non-zero then a stop bit will be sent on the bus after the transaction. This is usually required for normal operation. If this parameter is zero then no stop bit will be omitted. In this case, no other task can use the component until a stop bit has been sent.
Returns
I2C_ACK if the write was acknowledged by the device, I2C_NACK otherwise.