Functions
IO operation functions
Peripheral Driver » HAL Driver » I2C » Functions

Data transfers functions. More...

## Functions
hal_status_t | hal_i2c_master_transmit (i2c_handle_t *p_i2c, uint16_t dev_address, uint8_t *p_data, uint16_t size, uint32_t timeout)
| Transmits in master mode an amount of data in blocking mode. More...
hal_status_t | hal_i2c_master_receive (i2c_handle_t *p_i2c, uint16_t dev_address, uint8_t *p_data, uint16_t size, uint32_t timeout)
| Receives in master mode an amount of data in blocking mode. More...
hal_status_t | hal_i2c_slave_transmit (i2c_handle_t *p_i2c, uint8_t *p_data, uint16_t size, uint32_t timeout)
| Transmits in slave mode an amount of data in blocking mode. More...
hal_status_t | hal_i2c_slave_receive (i2c_handle_t *p_i2c, uint8_t *p_data, uint16_t size, uint32_t timeout)
| Receive in slave mode an amount of data in blocking mode. More...
hal_status_t | hal_i2c_mem_write (i2c_handle_t *p_i2c, uint16_t dev_address, uint16_t mem_address, uint16_t mem_addr_size, uint8_t *p_data, uint16_t size, uint32_t timeout)
| Write an amount of data in blocking mode to a specific memory address. More...
hal_status_t | hal_i2c_mem_read (i2c_handle_t *p_i2c, uint16_t dev_address, uint16_t mem_address, uint16_t mem_addr_size, uint8_t *p_data, uint16_t size, uint32_t timeout)
| Read an amount of data in blocking mode from a specific memory address. More...
hal_status_t | hal_i2c_master_transmit_it (i2c_handle_t *p_i2c, uint16_t dev_address, uint8_t *p_data, uint16_t size)
| Transmit in master mode an amount of data in non-blocking mode with Interrupt. More...
hal_status_t | hal_i2c_master_receive_it (i2c_handle_t *p_i2c, uint16_t dev_address, uint8_t *p_data, uint16_t size)
| Receive in master mode an amount of data in non-blocking mode with Interrupt. More...
hal_status_t | hal_i2c_slave_transmit_it (i2c_handle_t *p_i2c, uint8_t *p_data, uint16_t size)
| Transmit in slave mode an amount of data in non-blocking mode with Interrupt. More...
hal_status_t | hal_i2c_slave_receive_it (i2c_handle_t *p_i2c, uint8_t *p_data, uint16_t size)
| Receive in slave mode an amount of data in non-blocking mode with Interrupt. More...
hal_status_t | hal_i2c_mem_write_it (i2c_handle_t *p_i2c, uint16_t dev_address, uint16_t mem_address, uint16_t mem_addr_size, uint8_t *p_data, uint16_t size)
| Write an amount of data in non-blocking mode with Interrupt to a specific memory address. More...
hal_status_t | hal_i2c_mem_read_it (i2c_handle_t *p_i2c, uint16_t dev_address, uint16_t mem_address, uint16_t mem_addr_size, uint8_t *p_data, uint16_t size)
| Read an amount of data in non-blocking mode with Interrupt from a specific memory address. More...
hal_status_t | hal_i2c_master_abort_it (i2c_handle_t *p_i2c)
| Abort a master I2C IT or DMA process communication with Interrupt. More...
hal_status_t | hal_i2c_master_transmit_dma (i2c_handle_t *p_i2c, uint16_t dev_address, uint8_t *p_data, uint16_t size)
| Transmit in master mode an amount of data in non-blocking mode with DMA. More...
hal_status_t | hal_i2c_master_receive_dma (i2c_handle_t *p_i2c, uint16_t dev_address, uint8_t *p_data, uint16_t size)
| Receive in master mode an amount of data in non-blocking mode with DMA. More...
hal_status_t | hal_i2c_slave_transmit_dma (i2c_handle_t *p_i2c, uint8_t *p_data, uint16_t size)
| Transmit in slave mode an amount of data in non-blocking mode with DMA. More...
hal_status_t | hal_i2c_slave_receive_dma (i2c_handle_t *p_i2c, uint8_t *p_data, uint16_t size)
| Receive in slave mode an amount of data in non-blocking mode with DMA. More...
hal_status_t | hal_i2c_mem_write_dma (i2c_handle_t *p_i2c, uint16_t dev_address, uint16_t mem_address, uint16_t mem_addr_size, uint8_t *p_data, uint16_t size)
| Write an amount of data in non-blocking mode with DMA to a specific memory address. More...
hal_status_t | hal_i2c_mem_read_dma (i2c_handle_t *p_i2c, uint16_t dev_address, uint16_t mem_address, uint16_t mem_addr_size, uint8_t *p_data, uint16_t size)
| Reads an amount of data in non-blocking mode with DMA from a specific memory address. More...

## Detailed Description

Data transfers functions.

     ===============================================================================
                          ##### IO operation functions #####
     ===============================================================================
        [..]
        This subsection provides a set of functions allowing to manage the I2C data
        transfers.

        (#) There are two modes of transfer:
           (++) Blocking mode: The communication is performed in the polling mode.
                The status of all data processing is returned by the same function
                after finishing transfer.
           (++) No-Blocking mode: The communication is performed using Interrupts
                or DMA. These functions return the status of the transfer startup.
                The end of the data processing will be indicated through the
                dedicated I2C IRQ when using Interrupt mode or the DMA IRQ when
                using DMA mode.

        (#) Blocking mode functions are :
            (++) hal_i2c_master_transmit()
            (++) hal_i2c_master_receive()
            (++) hal_i2c_slave_transmit()
            (++) hal_i2c_slave_receive()
            (++) hal_i2c_mem_write()
            (++) hal_i2c_mem_read()
            (++) hal_i2c_is_device_ready()

        (#) No-Blocking mode functions with Interrupt are :
            (++) hal_i2c_master_transmit_it()
            (++) hal_i2c_master_receive_it()
            (++) hal_i2c_slave_transmit_it()
            (++) hal_i2c_slave_receive_it()
            (++) hal_i2c_mem_write_it()
            (++) hal_i2c_mem_read_it()

        (#) No-Blocking mode functions with DMA are :
            (++) hal_i2c_master_transmit_dma()
            (++) hal_i2c_master_recevice_dma()
            (++) hal_i2c_slave_transmit_dma()
            (++) hal_i2c_slave_receive_dma()
            (++) hal_i2c_mem_write_dma()
            (++) hal_i2c_mem_read_dma()

        (#) A set of Transfer Complete Callbacks are provided in non Blocking mode:
            (++) hal_i2c_mem_tx_cplt_callback()
            (++) hal_i2c_mem_rx_cplt_callback()
            (++) hal_i2c_master_tx_cplt_callback()
            (++) hal_i2c_master_rx_cplt_callback()
            (++) hal_i2c_slave_tx_cplt_callback()
            (++) hal_i2c_slave_rx_cplt_callback()()
            (++) hal_i2c_error_callback()

## Function Documentation

## ◆ hal_i2c_master_abort_it()

hal_status_t hal_i2c_master_abort_it | ( | i2c_handle_t * | p_i2c | ) |

Abort a master I2C IT or DMA process communication with Interrupt.

Parameters

  [in] | p_i2c | Pointer to an I2C handle which contains the configuration information for the specified I2C.

Return values

  HAL_OK | Operation is OK.
  HAL_ERROR | Parameter error or operation not supported.
  HAL_BUSY | Driver is busy.
  HAL_TIMEOUT | Timeout occurred.

## ◆ hal_i2c_master_receive()

hal_status_t hal_i2c_master_receive | ( | i2c_handle_t * | p_i2c,
|  | uint16_t | dev_address,
|  | uint8_t * | p_data,
|  | uint16_t | size,
|  | uint32_t | timeout
| ) |  |

Receives in master mode an amount of data in blocking mode.

Parameters

  [in] | p_i2c | Pointer to an I2C handle which contains the configuration information for the specified I2C.
  [in] | dev_address | Target device address: The device 7 bits address value in datasheet must be shifted at right before call interface
  [in] | p_data | Pointer to data buffer
  [in] | size | Amount of data to be sent
  [in] | timeout | Timeout duration

Return values

  HAL_OK | Operation is OK.
  HAL_ERROR | Parameter error or operation not supported.
  HAL_BUSY | Driver is busy.
  HAL_TIMEOUT | Timeout occurred.

Note
  This function will return HAL_OK even if the length of data sent by slave is less than the expected Size.

## ◆ hal_i2c_master_receive_dma()

hal_status_t hal_i2c_master_receive_dma | ( | i2c_handle_t * | p_i2c,
|  | uint16_t | dev_address,
|  | uint8_t * | p_data,
|  | uint16_t | size
| ) |  |

Receive in master mode an amount of data in non-blocking mode with DMA.

Parameters

  [in] | p_i2c | Pointer to an I2C handle which contains the configuration information for the specified I2C.
  [in] | dev_address | Target device address: The device 7 bits address value in datasheet must be shifted at right before call interface.
  [in] | p_data | Pointer to data buffer
  [in] | size | Amount of data to be sent, ranging between 0 and 4095.

Return values

  HAL_OK | Operation is OK.
  HAL_ERROR | Parameter error or operation not supported.
  HAL_BUSY | Driver is busy.
  HAL_TIMEOUT | Timeout occurred.

## ◆ hal_i2c_master_receive_it()

hal_status_t hal_i2c_master_receive_it | ( | i2c_handle_t * | p_i2c,
|  | uint16_t | dev_address,
|  | uint8_t * | p_data,
|  | uint16_t | size
| ) |  |

Receive in master mode an amount of data in non-blocking mode with Interrupt.

Parameters

  [in] | p_i2c | Pointer to an I2C handle which contains the configuration information for the specified I2C.
  [in] | dev_address | Target device address: The device 7 bits address value in datasheet must be shifted at right before call interface
  [in] | p_data | Pointer to data buffer
  [in] | size | Amount of data to be sent

Return values

  HAL_OK | Operation is OK.
  HAL_ERROR | Parameter error or operation not supported.
  HAL_BUSY | Driver is busy.
  HAL_TIMEOUT | Timeout occurred.

## ◆ hal_i2c_master_transmit()

hal_status_t hal_i2c_master_transmit | ( | i2c_handle_t * | p_i2c,
|  | uint16_t | dev_address,
|  | uint8_t * | p_data,
|  | uint16_t | size,
|  | uint32_t | timeout
| ) |  |

Transmits in master mode an amount of data in blocking mode.

Parameters

  [in] | p_i2c | Pointer to an I2C handle which contains the configuration information for the specified I2C.
  [in] | dev_address | Target device address: The device 7 bits address value in datasheet must be shifted at right before call interface
  [in] | p_data | Pointer to data buffer
  [in] | size | Amount of data to be sent
  [in] | timeout | Timeout duration

Return values

  HAL_OK | Operation is OK.
  HAL_ERROR | Parameter error or operation not supported.
  HAL_BUSY | Driver is busy.
  HAL_TIMEOUT | Timeout occurred.

## ◆ hal_i2c_master_transmit_dma()

hal_status_t hal_i2c_master_transmit_dma | ( | i2c_handle_t * | p_i2c,
|  | uint16_t | dev_address,
|  | uint8_t * | p_data,
|  | uint16_t | size
| ) |  |

Transmit in master mode an amount of data in non-blocking mode with DMA.

Parameters

  [in] | p_i2c | Pointer to an I2C handle which contains the configuration information for the specified I2C.
  [in] | dev_address | Target device address: The device 7 bits address value in datasheet must be shifted at right before call interface.
  [in] | p_data | Pointer to data buffer
  [in] | size | Amount of data to be sent, ranging between 0 and 4095.

Return values

  HAL_OK | Operation is OK.
  HAL_ERROR | Parameter error or operation not supported.
  HAL_BUSY | Driver is busy.
  HAL_TIMEOUT | Timeout occurred.

## ◆ hal_i2c_master_transmit_it()

hal_status_t hal_i2c_master_transmit_it | ( | i2c_handle_t * | p_i2c,
|  | uint16_t | dev_address,
|  | uint8_t * | p_data,
|  | uint16_t | size
| ) |  |

Transmit in master mode an amount of data in non-blocking mode with Interrupt.

Parameters

  [in] | p_i2c | Pointer to an I2C handle which contains the configuration information for the specified I2C.
  [in] | dev_address | Target device address: The device 7 bits address value in datasheet must be shifted at right before call interface
  [in] | p_data | Pointer to data buffer
  [in] | size | Amount of data to be sent

Return values

  HAL_OK | Operation is OK.
  HAL_ERROR | Parameter error or operation not supported.
  HAL_BUSY | Driver is busy.
  HAL_TIMEOUT | Timeout occurred.

## ◆ hal_i2c_mem_read()

hal_status_t hal_i2c_mem_read | ( | i2c_handle_t * | p_i2c,
|  | uint16_t | dev_address,
|  | uint16_t | mem_address,
|  | uint16_t | mem_addr_size,
|  | uint8_t * | p_data,
|  | uint16_t | size,
|  | uint32_t | timeout
| ) |  |

Read an amount of data in blocking mode from a specific memory address.

Parameters

  [in] | p_i2c | Pointer to an I2C handle which contains the configuration information for the specified I2C.
  [in] | dev_address | Target device address: The device 7 bits address value in datasheet must be shifted at right before call interface
  [in] | mem_address | Internal memory address
  [in] | mem_addr_size | Size of internal memory address
  [in] | p_data | Pointer to data buffer
  [in] | size | Amount of data to be sent
  [in] | timeout | Timeout duration

Return values

  HAL_OK | Operation is OK.
  HAL_ERROR | Parameter error or operation not supported.
  HAL_BUSY | Driver is busy.
  HAL_TIMEOUT | Timeout occurred.

## ◆ hal_i2c_mem_read_dma()

hal_status_t hal_i2c_mem_read_dma | ( | i2c_handle_t * | p_i2c,
|  | uint16_t | dev_address,
|  | uint16_t | mem_address,
|  | uint16_t | mem_addr_size,
|  | uint8_t * | p_data,
|  | uint16_t | size
| ) |  |

Reads an amount of data in non-blocking mode with DMA from a specific memory address.

Parameters

  [in] | p_i2c | Pointer to an I2C handle which contains the configuration information for the specified I2C.
  [in] | dev_address | Target device address: The device 7 bits address value in datasheet must be shifted at right before call interface
  [in] | mem_address | Internal memory address
  [in] | mem_addr_size | Size of internal memory address
  [in] | p_data | Pointer to data buffer
  [in] | size | Amount of data to be sent, ranging between 0 and 4095.

Return values

  HAL_OK | Operation is OK.
  HAL_ERROR | Parameter error or operation not supported.
  HAL_BUSY | Driver is busy.
  HAL_TIMEOUT | Timeout occurred.

## ◆ hal_i2c_mem_read_it()

hal_status_t hal_i2c_mem_read_it | ( | i2c_handle_t * | p_i2c,
|  | uint16_t | dev_address,
|  | uint16_t | mem_address,
|  | uint16_t | mem_addr_size,
|  | uint8_t * | p_data,
|  | uint16_t | size
| ) |  |

Read an amount of data in non-blocking mode with Interrupt from a specific memory address.

Parameters

  [in] | p_i2c | Pointer to an I2C handle which contains the configuration information for the specified I2C.
  [in] | dev_address | Target device address: The device 7 bits address value in datasheet must be shifted at right before call interface
  [in] | mem_address | Internal memory address
  [in] | mem_addr_size | Size of internal memory address
  [in] | p_data | Pointer to data buffer
  [in] | size | Amount of data to be sent

Return values

  HAL_OK | Operation is OK.
  HAL_ERROR | Parameter error or operation not supported.
  HAL_BUSY | Driver is busy.
  HAL_TIMEOUT | Timeout occurred.

## ◆ hal_i2c_mem_write()

hal_status_t hal_i2c_mem_write | ( | i2c_handle_t * | p_i2c,
|  | uint16_t | dev_address,
|  | uint16_t | mem_address,
|  | uint16_t | mem_addr_size,
|  | uint8_t * | p_data,
|  | uint16_t | size,
|  | uint32_t | timeout
| ) |  |

Write an amount of data in blocking mode to a specific memory address.

Parameters

  [in] | p_i2c | Pointer to an I2C handle which contains the configuration information for the specified I2C.
  [in] | dev_address | Target device address: The device 7 bits address value in datasheet must be shifted at right before call interface
  [in] | mem_address | Internal memory address
  [in] | mem_addr_size | Size of internal memory address
  [in] | p_data | Pointer to data buffer
  [in] | size | Amount of data to be sent
  [in] | timeout | Timeout duration

Return values

  HAL_OK | Operation is OK.
  HAL_ERROR | Parameter error or operation not supported.
  HAL_BUSY | Driver is busy.
  HAL_TIMEOUT | Timeout occurred.

## ◆ hal_i2c_mem_write_dma()

hal_status_t hal_i2c_mem_write_dma | ( | i2c_handle_t * | p_i2c,
|  | uint16_t | dev_address,
|  | uint16_t | mem_address,
|  | uint16_t | mem_addr_size,
|  | uint8_t * | p_data,
|  | uint16_t | size
| ) |  |

Write an amount of data in non-blocking mode with DMA to a specific memory address.

Parameters

  [in] | p_i2c | Pointer to an I2C handle which contains the configuration information for the specified I2C.
  [in] | dev_address | Target device address: The device 7 bits address value in datasheet must be shifted at right before call interface
  [in] | mem_address | Internal memory address
  [in] | mem_addr_size | Size of internal memory address
  [in] | p_data | Pointer to data buffer
  [in] | size | Amount of data to be sent, ranging between 0 and 4095.

Return values

  HAL_OK | Operation is OK.
  HAL_ERROR | Parameter error or operation not supported.
  HAL_BUSY | Driver is busy.
  HAL_TIMEOUT | Timeout occurred.

## ◆ hal_i2c_mem_write_it()

hal_status_t hal_i2c_mem_write_it | ( | i2c_handle_t * | p_i2c,
|  | uint16_t | dev_address,
|  | uint16_t | mem_address,
|  | uint16_t | mem_addr_size,
|  | uint8_t * | p_data,
|  | uint16_t | size
| ) |  |

Write an amount of data in non-blocking mode with Interrupt to a specific memory address.

Parameters

  [in] | p_i2c | Pointer to an I2C handle which contains the configuration information for the specified I2C.
  [in] | dev_address | Target device address: The device 7 bits address value in datasheet must be shifted at right before call interface
  [in] | mem_address | Internal memory address
  [in] | mem_addr_size | Size of internal memory address
  [in] | p_data | Pointer to data buffer
  [in] | size | Amount of data to be sent

Return values

  HAL_OK | Operation is OK.
  HAL_ERROR | Parameter error or operation not supported.
  HAL_BUSY | Driver is busy.
  HAL_TIMEOUT | Timeout occurred.

## ◆ hal_i2c_slave_receive()

hal_status_t hal_i2c_slave_receive | ( | i2c_handle_t * | p_i2c,
|  | uint8_t * | p_data,
|  | uint16_t | size,
|  | uint32_t | timeout
| ) |  |

Receive in slave mode an amount of data in blocking mode.

Parameters

  [in] | p_i2c | Pointer to an I2C handle which contains the configuration information for the specified I2C.
  [in] | p_data | Pointer to data buffer
  [in] | size | Amount of data to be sent
  [in] | timeout | Timeout duration

Return values

  HAL_OK | Operation is OK.
  HAL_ERROR | Parameter error or operation not supported.
  HAL_BUSY | Driver is busy.
  HAL_TIMEOUT | Timeout occurred.

## ◆ hal_i2c_slave_receive_dma()

hal_status_t hal_i2c_slave_receive_dma | ( | i2c_handle_t * | p_i2c,
|  | uint8_t * | p_data,
|  | uint16_t | size
| ) |  |

Receive in slave mode an amount of data in non-blocking mode with DMA.

Parameters

  [in] | p_i2c | Pointer to an I2C handle which contains the configuration information for the specified I2C.
  [in] | p_data | Pointer to data buffer
  [in] | size | Amount of data to be sent, ranging between 0 and 4095.

Return values

  HAL_OK | Operation is OK.
  HAL_ERROR | Parameter error or operation not supported.
  HAL_BUSY | Driver is busy.
  HAL_TIMEOUT | Timeout occurred.

## ◆ hal_i2c_slave_receive_it()

hal_status_t hal_i2c_slave_receive_it | ( | i2c_handle_t * | p_i2c,
|  | uint8_t * | p_data,
|  | uint16_t | size
| ) |  |

Receive in slave mode an amount of data in non-blocking mode with Interrupt.

Parameters

  [in] | p_i2c | Pointer to an I2C handle which contains the configuration information for the specified I2C.
  [in] | p_data | Pointer to data buffer
  [in] | size | Amount of data to be sent

Return values

  HAL_OK | Operation is OK.
  HAL_ERROR | Parameter error or operation not supported.
  HAL_BUSY | Driver is busy.
  HAL_TIMEOUT | Timeout occurred.

## ◆ hal_i2c_slave_transmit()

hal_status_t hal_i2c_slave_transmit | ( | i2c_handle_t * | p_i2c,
|  | uint8_t * | p_data,
|  | uint16_t | size,
|  | uint32_t | timeout
| ) |  |

Transmits in slave mode an amount of data in blocking mode.

Parameters

  [in] | p_i2c | Pointer to an I2C handle which contains the configuration information for the specified I2C.
  [in] | p_data | Pointer to data buffer
  [in] | size | Amount of data to be sent
  [in] | timeout | Timeout duration

Return values

  HAL_OK | Operation is OK.
  HAL_ERROR | Parameter error or operation not supported.
  HAL_BUSY | Driver is busy.
  HAL_TIMEOUT | Timeout occurred.

## ◆ hal_i2c_slave_transmit_dma()

hal_status_t hal_i2c_slave_transmit_dma | ( | i2c_handle_t * | p_i2c,
|  | uint8_t * | p_data,
|  | uint16_t | size
| ) |  |

Transmit in slave mode an amount of data in non-blocking mode with DMA.

Parameters

  [in] | p_i2c | Pointer to an I2C handle which contains the configuration information for the specified I2C.
  [in] | p_data | Pointer to data buffer
  [in] | size | Amount of data to be sent, ranging between 0 and 4095.

Return values

  HAL_OK | Operation is OK.
  HAL_ERROR | Parameter error or operation not supported.
  HAL_BUSY | Driver is busy.
  HAL_TIMEOUT | Timeout occurred.

## ◆ hal_i2c_slave_transmit_it()

hal_status_t hal_i2c_slave_transmit_it | ( | i2c_handle_t * | p_i2c,
|  | uint8_t * | p_data,
|  | uint16_t | size
| ) |  |

Transmit in slave mode an amount of data in non-blocking mode with Interrupt.

Parameters

  [in] | p_i2c | Pointer to an I2C handle which contains the configuration information for the specified I2C.
  [in] | p_data | Pointer to data buffer
  [in] | size | Amount of data to be sent

Return values

  HAL_OK | Operation is OK.
  HAL_ERROR | Parameter error or operation not supported.
  HAL_BUSY | Driver is busy.
  HAL_TIMEOUT | Timeout occurred.