![]() |
mikroSDK Reference Manual
|
I2C Master Driver API Reference. More...
Functions list | |
| void | i2c_master_configure_default (i2c_master_config_t *config) |
| Configure I2C Master configuration structure. More... | |
| err_t | i2c_master_open (i2c_master_t *obj, i2c_master_config_t *config) |
| Open the I2C Master driver object. More... | |
| err_t | i2c_master_set_speed (i2c_master_t *obj, uint32_t speed) |
| Set I2C Master module speed. More... | |
| err_t | i2c_master_set_timeout (i2c_master_t *obj, uint16_t timeout_pass_count) |
| Set I2C Master timeout value. More... | |
| err_t | i2c_master_set_slave_address (i2c_master_t *obj, uint8_t address) |
| Set I2C Slave address. More... | |
| err_t | i2c_master_write (i2c_master_t *obj, uint8_t *write_data_buf, size_t len_write_data) |
| Write data to the I2C bus. More... | |
| err_t | i2c_master_read (i2c_master_t *obj, uint8_t *read_data_buf, size_t len_read_data) |
| Read data from the I2C bus. More... | |
| err_t | i2c_master_write_then_read (i2c_master_t *obj, uint8_t *write_data_buf, size_t len_write_data, uint8_t *read_data_buf, size_t len_read_data) |
| Write data to I2C bus followed by read. More... | |
| err_t | i2c_master_close (i2c_master_t *obj) |
| Close I2C Master driver object. More... | |
The I2C Master driver provides standard I2C Master functionality including setting the I2C speed and timeout.
| void i2c_master_configure_default | ( | i2c_master_config_t * | config | ) |
Configures I2C Master 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 driver configuration structure. See 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
| err_t i2c_master_open | ( | i2c_master_t * | obj, |
| i2c_master_config_t * | config | ||
| ) |
Opens the I2C Master driver object on selected pins. Allocates memory and pins for specified object.
| [in,out] | obj | I2C Master driver object. See i2c_master_t structure definition for detailed explanation. |
| [in] | config | I2C Master driver configuration settings. See i2c_master_config_t structure definition for detailed explanation. |
config structure has been adequately populated beforehand. See i2c_master_configure_default definition for detailed explanation. Example
| err_t i2c_master_set_speed | ( | i2c_master_t * | obj, |
| uint32_t | speed | ||
| ) |
Sets I2C Master module speed to speed value if possible.
| [in] | obj | I2C Master driver object. See i2c_master_t structure definition for detailed explanation. |
| [in] | speed | Specified I2C transmission rate. See i2c_master_speed_t for valid values. |
Example
| err_t i2c_master_set_timeout | ( | i2c_master_t * | obj, |
| uint16_t | timeout_pass_count | ||
| ) |
Sets I2C Master module timeout interval to timeout_pass_count value. This means that the module shall retry any given operation timeout_pass_count number of times before exiting with adequate timeout value.
| [in] | obj | I2C Master driver object. See i2c_master_t structure definition for detailed explanation. |
| [in] | timeout_pass_count | Specified I2C master timeout value. |
Example
| err_t i2c_master_set_slave_address | ( | i2c_master_t * | obj, |
| uint8_t | address | ||
| ) |
Sets I2C address of the subordinate I2C device to address which is targeted by read and write operations.
| [in] | obj | I2C Master driver object. See i2c_master_t structure definition for detailed explanation. |
| [in] | address | Specified I2C slave address. |
Example
| err_t i2c_master_write | ( | i2c_master_t * | obj, |
| uint8_t * | write_data_buf, | ||
| size_t | len_write_data | ||
| ) |
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] | obj | I2C master driver object. See i2c_master_t structure definition for detailed explanation. |
| [in] | *write_data_buf | Data transmit buffer. |
| [in] | len_write_data | Number of bytes to write from data transmit buffer. |
Example
| err_t i2c_master_read | ( | i2c_master_t * | obj, |
| uint8_t * | read_data_buf, | ||
| size_t | len_read_data | ||
| ) |
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] | obj | I2C master driver object. See i2c_master_t structure definition for detailed explanation. |
| [out] | *read_data_buf | Data receive buffer. |
| [in] | len_read_data | Number of bytes to read from bus. |
Example
| err_t i2c_master_write_then_read | ( | i2c_master_t * | obj, |
| uint8_t * | write_data_buf, | ||
| size_t | len_write_data, | ||
| uint8_t * | read_data_buf, | ||
| size_t | len_read_data | ||
| ) |
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] | obj | I2C master driver object. See i2c_master_t structure definition for detailed explanation. |
| [in] | *write_data_buf | Data transmit buffer. |
| [in] | len_write_data | Number of bytes to write from data transmit buffer. |
| [out] | *read_data_buf | Data receive buffer. |
| [in] | len_read_data | Number of bytes to read from bus. |
Example
| err_t i2c_master_close | ( | i2c_master_t * | obj | ) |
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] | obj | I2C Master driver object. See i2c_master_t structure definition for detailed explanation. |
Example