Cascoda SDK
Cascoda SDK for building software to run with CA-821x transceivers
|
I2C Master Hardware Abstraction Layer API Reference. More...
Functions | |
err_t | hal_i2c_master_open (handle_t *handle, bool hal_obj_open_state) |
Open the I2C Master HAL object. More... | |
void | hal_i2c_master_set_slave_address (handle_t *handle, hal_i2c_master_config_t *config) |
Set I2C slave address. More... | |
err_t | hal_i2c_master_write (handle_t handle, uint8_t *write_data_buf, size_t len_write_data) |
Write data to the I2C bus. More... | |
err_t | hal_i2c_master_read (handle_t handle, uint8_t *read_data_buf, size_t len_read_data) |
Read data from the I2C bus. More... | |
err_t | hal_i2c_master_write_then_read (handle_t handle, uint8_t *write_data_buf, size_t len_write_data, uint8_t *read_data_buf, size_t len_read_data) |
Write data followed by read. More... | |
err_t | hal_i2c_master_close (handle_t *handle) |
Closes I2C Master HAL object. More... | |
void | hal_i2c_master_configure_default (hal_i2c_master_config_t *config) |
Configure I2C Master HAL configuration structure. More... | |
err_t | hal_i2c_master_set_speed (handle_t *handle, hal_i2c_master_config_t *config) |
Set I2C master module speed. More... | |
void | hal_i2c_master_set_timeout (handle_t *handle, hal_i2c_master_config_t *config) |
Set I2C master timeout value. More... | |
I2C Master Hardware Abstraction Layer API Reference.
API for configuring and manipulating I2C Master HAL module.
Closes I2C Master HAL object.
De-allocates hardware resources for specific driver object and de-initializes the module on a hardware level, resets pin AF to default values, clears all buffers used by object and disables module clock for lower power consumption.
[in,out] | handle | I2C handle. See hal_i2c_master_t structure definition for detailed explanation. |
Example
void hal_i2c_master_configure_default | ( | hal_i2c_master_config_t * | config | ) |
Configure I2C Master HAL configuration structure.
Configures configuration structure to default initialization values. Take into consideration that this is just structure variable initial values setting. Values need to be redefined by user.
[in,out] | config | I2C Master HAL driver configuration structure. See hal_i2c_master_config_t structure definition for detailed explanation. |
Default values:
Function | Default value |
---|---|
Address | 0 |
SCL pin | 0xFFFFFFFF (invalid pin) |
SDA pin | 0xFFFFFFFF (invalid pin) |
Speed | 100K |
Timeout value | 10000 retries |
Example
Open the I2C Master HAL object.
Opens the I2C Master HAL object on selected pins. Allocates memory and pins for specified object.
[in,out] | handle | I2C Master HAL object. See hal_i2c_master_t structure definition for detailed explanation. |
[in] | hal_obj_open_state | I2C state. Is it open or not. |
Example
Calling sensorif to initalise and enable I2C
Read data from the I2C bus.
Function shall generate a START signal, followed by len_read_data
number of reads from the bus placing the data in read_data_buf
. Ends with a STOP signal.
[in] | handle | I2C handle. See i2c_master_t structure definition for detailed explanation. |
[out] | *read_data_buf | Data buffer. |
[in] | len_read_data | Number of bytes to read from bus. |
Example
void hal_i2c_master_set_slave_address | ( | handle_t * | handle, |
hal_i2c_master_config_t * | config | ||
) |
Set I2C slave address.
Sets I2C Address of the subordinate I2C device to config->address
which is targeted by read and write operations.
[in] | handle | I2C handle. See i2c_master_t structure definition for detailed explanation. |
[in] | config | I2C HAL configuration structure. See hal_i2c_master_config_t structure definition for detailed explanation. |
Example
err_t hal_i2c_master_set_speed | ( | handle_t * | handle, |
hal_i2c_master_config_t * | config | ||
) |
Set I2C master module speed.
Sets I2C module speed to config->speed
value if possible.
[in] | handle | I2C handle. See i2c_master_t structure definition for detailed explanation. |
[in] | config | I2C HAL configuration structure. See hal_i2c_master_config_t structure definition for detailed explanation. |
Example
void hal_i2c_master_set_timeout | ( | handle_t * | handle, |
hal_i2c_master_config_t * | config | ||
) |
Set I2C master timeout value.
Sets I2C module timeout interval to config->timeout_pass_count
value. This means that the module shall retry any given operation config->timeout_pass_count
number of times before exiting with adequate timeout value.
[in] | handle | I2C handle. See i2c_master_t structure definition for detailed explanation. |
[in] | config | I2C HAL configuration structure. See hal_i2c_master_config_t structure definition for detailed explanation. |
Example
Write data to the I2C bus.
Function shall generate a START signal, followed by len_write_data
number of writes from write_data_buf
on the bus. Ends with a STOP signal.
[in] | handle | I2C handle. See i2c_master_t structure definition for detailed explanation. |
[in] | *write_data_buf | Data buffer. |
[in] | len_write_data | Number of bytes to write from data buffer. |
Example
err_t hal_i2c_master_write_then_read | ( | handle_t | handle, |
uint8_t * | write_data_buf, | ||
size_t | len_write_data, | ||
uint8_t * | read_data_buf, | ||
size_t | len_read_data | ||
) |
Write data followed by read.
Function performs a write operation followed by a read operation on the bus. The operation consists of a start signal followed by len_write_data
number of write operations ( data from write_data_buf
), a restart signal followed by len_read_data
number of read operations ( placed in read_data_buf
), finishing the operation with a stop signal.
[in] | handle | I2C handle. See i2c_master_t structure definition for detailed explanation. |
[in] | *write_data_buf | Data buffer. |
[in] | len_write_data | Number of bytes to write from data buffer. |
[out] | *read_data_buf | Data buffer. |
[in] | len_read_data | Number of bytes to read from bus. |
Example