Cortex-M4 I²C HAL interface. More...


Go to the source code of this file.
Classes | |
| struct | hal_i2c_config_t |
| I²C configuration structure. More... | |
Macros | |
| #define | I2C_MASTER 0 |
| #define | GPIO_FUNC_I2C GPIO_AF04 |
Enumerations | |
| enum | hal_i2c_status_t { HAL_I2C_OK = 0 , HAL_I2C_ERR_TIMEOUT , HAL_I2C_ERR_BUS , HAL_I2C_ERR_NACK , HAL_I2C_ERR_REINIT } |
| I²C operation status codes. More... | |
| enum | hal_i2c_bus_t { I2C1 = 0 , I2C2 = 1 , I2C3 = 2 } |
| Supported I²C bus instances. More... | |
| enum | hal_i2c_speed_t { STANDARD_MODE = 0 , FAST_MODE = 1 } |
| I²C speed modes. More... | |
Functions | |
| hal_i2c_status_t | hal_i2c_init (hal_i2c_bus_t bus, hal_i2c_config_t *config) |
| Initialize the I²C peripheral. | |
| hal_i2c_status_t | hal_i2c_write (uint8_t bus, uint8_t dev_addr, const uint8_t *data, uint16_t len) |
| Write data to an I²C device. | |
| hal_i2c_status_t | hal_i2c_read (uint8_t bus, uint8_t dev_addr, uint8_t *data, uint16_t len) |
| Read data from an I²C device. | |
| hal_i2c_status_t | hal_i2c_write_read (uint8_t bus, uint8_t dev_addr, const uint8_t *tx_data, uint16_t tx_len, uint8_t *rx_data, uint16_t rx_len) |
| Write to a device register and read back data. | |
| uint8_t | hal_i2c_get_init_status (void) |
| Get the initialization status of the I²C peripheral. | |
Cortex-M4 I²C HAL interface.
This header defines types, structures, and function prototypes for I²C communication on Cortex-M4 microcontrollers. It provides functions for initializing the I²C peripheral, reading/writing data, and performing combined write-read transactions.
Supported features:
| #define GPIO_FUNC_I2C GPIO_AF04 |
GPIO alternate function for I²C pins
| #define I2C_MASTER 0 |
Master mode identifier
| enum hal_i2c_bus_t |
| enum hal_i2c_speed_t |
| enum hal_i2c_status_t |
| uint8_t hal_i2c_get_init_status | ( | void | ) |
Get the initialization status of the I²C peripheral.
Get the initialization status of the I²C peripheral.
| Bit | 0: I2C1 status |
| Bit | 1: I2C2 status |
| Bit | 2: I2C3 status |
| hal_i2c_status_t hal_i2c_init | ( | hal_i2c_bus_t | bus, |
| hal_i2c_config_t * | config ) |
Initialize the I²C peripheral.
| bus | The I²C bus instance to initialize. |
| config | Pointer to the configuration structure. |
Initialize the I²C peripheral.
| [in] | bus | I2C bus identifier (I2C1, I2C2, I2C3) |
| [in] | config | Pointer to configuration structure |
| HAL_I2C_OK | Initialization successful |
| HAL_I2C_ERR_REINIT | Bus already initialized |
| HAL_I2C_ERR_BUS | Unsupported mode (slave not implemented) |
Configures the specified I2C bus with:
< I²C base address
| hal_i2c_status_t hal_i2c_read | ( | uint8_t | bus, |
| uint8_t | dev_addr, | ||
| uint8_t * | data, | ||
| uint16_t | len ) |
Read data from an I²C device.
| bus | The I²C bus instance. |
| dev_addr | The 7-bit address of the target device. |
| data | Pointer to buffer for received data. |
| len | Number of bytes to read. |
Read data from an I²C device.
| [in] | bus | I2C bus identifier |
| [in] | dev_addr | 7-bit device address |
| [out] | data | Pointer to receive buffer |
| [in] | len | Number of bytes to receive |
| HAL_I2C_OK | Reception successful |
| HAL_I2C_ERR_TIMEOUT | Bus timeout occurred |
| HAL_I2C_ERR_BUS | Invalid parameters |
Performs complete I2C read transaction:
< I²C base address
| hal_i2c_status_t hal_i2c_write | ( | uint8_t | bus, |
| uint8_t | dev_addr, | ||
| const uint8_t * | data, | ||
| uint16_t | len ) |
Write data to an I²C device.
| bus | The I²C bus instance. |
| dev_addr | The 7-bit address of the target device. |
| data | Pointer to data buffer to transmit. |
| len | Number of bytes to transmit. |
Write data to an I²C device.
| [in] | bus | I2C bus identifier |
| [in] | dev_addr | 7-bit device address |
| [in] | data | Pointer to transmit buffer |
| [in] | len | Number of bytes to transmit |
| HAL_I2C_OK | Transmission successful |
| HAL_I2C_ERR_TIMEOUT | Bus timeout occurred |
Performs complete I2C write transaction:
| hal_i2c_status_t hal_i2c_write_read | ( | uint8_t | bus, |
| uint8_t | dev_addr, | ||
| const uint8_t * | tx_data, | ||
| uint16_t | tx_len, | ||
| uint8_t * | rx_data, | ||
| uint16_t | rx_len ) |
Write to a device register and read back data.
| bus | The I²C bus instance. |
| dev_addr | The 7-bit address of the target device. |
| tx_data | Pointer to data to write. |
| tx_len | Number of bytes to write. |
| rx_data | Pointer to buffer for received data. |
| rx_len | Number of bytes to read. |
Write to a device register and read back data.
| [in] | bus | I2C bus identifier |
| [in] | dev_addr | 7-bit device address |
| [in] | tx_data | Pointer to transmit buffer |
| [in] | tx_len | Number of bytes to transmit |
| [out] | rx_data | Pointer to receive buffer |
| [in] | rx_len | Number of bytes to receive |
| HAL_I2C_OK | Operation successful |
| HAL_I2C_ERR_TIMEOUT | Bus timeout occurred |
| HAL_I2C_ERR_BUS | Invalid parameters |
Performs combined I2C transaction:
< I²C base address