STM32L4xx_HAL_Driver  1.14.0
I2C Private Functions

Functions

static void I2C_DMAMasterTransmitCplt (DMA_HandleTypeDef *hdma)
 DMA I2C master transmit process complete callback. More...
 
static void I2C_DMAMasterReceiveCplt (DMA_HandleTypeDef *hdma)
 DMA I2C master receive process complete callback. More...
 
static void I2C_DMASlaveTransmitCplt (DMA_HandleTypeDef *hdma)
 DMA I2C slave transmit process complete callback. More...
 
static void I2C_DMASlaveReceiveCplt (DMA_HandleTypeDef *hdma)
 DMA I2C slave receive process complete callback. More...
 
static void I2C_DMAError (DMA_HandleTypeDef *hdma)
 DMA I2C communication error callback. More...
 
static void I2C_DMAAbort (DMA_HandleTypeDef *hdma)
 DMA I2C communication abort callback (To be called at end of DMA Abort procedure). More...
 
static void I2C_ITAddrCplt (I2C_HandleTypeDef *hi2c, uint32_t ITFlags)
 I2C Address complete process callback. More...
 
static void I2C_ITMasterSeqCplt (I2C_HandleTypeDef *hi2c)
 I2C Master sequential complete process. More...
 
static void I2C_ITSlaveSeqCplt (I2C_HandleTypeDef *hi2c)
 I2C Slave sequential complete process. More...
 
static void I2C_ITMasterCplt (I2C_HandleTypeDef *hi2c, uint32_t ITFlags)
 I2C Master complete process. More...
 
static void I2C_ITSlaveCplt (I2C_HandleTypeDef *hi2c, uint32_t ITFlags)
 I2C Slave complete process. More...
 
static void I2C_ITListenCplt (I2C_HandleTypeDef *hi2c, uint32_t ITFlags)
 I2C Listen complete process. More...
 
static void I2C_ITError (I2C_HandleTypeDef *hi2c, uint32_t ErrorCode)
 I2C interrupts error process. More...
 
static HAL_StatusTypeDef I2C_RequestMemoryWrite (I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint16_t MemAddress, uint16_t MemAddSize, uint32_t Timeout, uint32_t Tickstart)
 Master sends target device address followed by internal memory address for write request. More...
 
static HAL_StatusTypeDef I2C_RequestMemoryRead (I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint16_t MemAddress, uint16_t MemAddSize, uint32_t Timeout, uint32_t Tickstart)
 Master sends target device address followed by internal memory address for read request. More...
 
static HAL_StatusTypeDef I2C_Master_ISR_IT (struct __I2C_HandleTypeDef *hi2c, uint32_t ITFlags, uint32_t ITSources)
 Interrupt Sub-Routine which handle the Interrupt Flags Master Mode with Interrupt. More...
 
static HAL_StatusTypeDef I2C_Slave_ISR_IT (struct __I2C_HandleTypeDef *hi2c, uint32_t ITFlags, uint32_t ITSources)
 Interrupt Sub-Routine which handle the Interrupt Flags Slave Mode with Interrupt. More...
 
static HAL_StatusTypeDef I2C_Master_ISR_DMA (struct __I2C_HandleTypeDef *hi2c, uint32_t ITFlags, uint32_t ITSources)
 Interrupt Sub-Routine which handle the Interrupt Flags Master Mode with DMA. More...
 
static HAL_StatusTypeDef I2C_Slave_ISR_DMA (struct __I2C_HandleTypeDef *hi2c, uint32_t ITFlags, uint32_t ITSources)
 Interrupt Sub-Routine which handle the Interrupt Flags Slave Mode with DMA. More...
 
static HAL_StatusTypeDef I2C_WaitOnFlagUntilTimeout (I2C_HandleTypeDef *hi2c, uint32_t Flag, FlagStatus Status, uint32_t Timeout, uint32_t Tickstart)
 This function handles I2C Communication Timeout. More...
 
static HAL_StatusTypeDef I2C_WaitOnTXISFlagUntilTimeout (I2C_HandleTypeDef *hi2c, uint32_t Timeout, uint32_t Tickstart)
 This function handles I2C Communication Timeout for specific usage of TXIS flag. More...
 
static HAL_StatusTypeDef I2C_WaitOnRXNEFlagUntilTimeout (I2C_HandleTypeDef *hi2c, uint32_t Timeout, uint32_t Tickstart)
 This function handles I2C Communication Timeout for specific usage of RXNE flag. More...
 
static HAL_StatusTypeDef I2C_WaitOnSTOPFlagUntilTimeout (I2C_HandleTypeDef *hi2c, uint32_t Timeout, uint32_t Tickstart)
 This function handles I2C Communication Timeout for specific usage of STOP flag. More...
 
static HAL_StatusTypeDef I2C_IsAcknowledgeFailed (I2C_HandleTypeDef *hi2c, uint32_t Timeout, uint32_t Tickstart)
 This function handles Acknowledge failed detection during an I2C Communication. More...
 
static void I2C_Enable_IRQ (I2C_HandleTypeDef *hi2c, uint16_t InterruptRequest)
 Manage the enabling of Interrupts. More...
 
static void I2C_Disable_IRQ (I2C_HandleTypeDef *hi2c, uint16_t InterruptRequest)
 Manage the disabling of Interrupts. More...
 
static void I2C_Flush_TXDR (I2C_HandleTypeDef *hi2c)
 I2C Tx data register flush process. More...
 
static void I2C_TransferConfig (I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint8_t Size, uint32_t Mode, uint32_t Request)
 Handles I2Cx communication when starting transfer or during transfer (TC or TCR flag are set). More...
 
static void I2C_ConvertOtherXferOptions (I2C_HandleTypeDef *hi2c)
 Convert I2Cx OTHER_xxx XferOptions to functionnal XferOptions. More...
 

Detailed Description

Function Documentation

◆ I2C_ConvertOtherXferOptions()

static void I2C_ConvertOtherXferOptions ( I2C_HandleTypeDef hi2c)
static

Convert I2Cx OTHER_xxx XferOptions to functionnal XferOptions.

Parameters
hi2cI2C handle.
Return values
None

Definition at line 6466 of file stm32l4xx_hal_i2c.c.

6467 {
6468  /* if user set XferOptions to I2C_OTHER_FRAME */
6469  /* it request implicitly to generate a restart condition */
6470  /* set XferOptions to I2C_FIRST_FRAME */
6471  if (hi2c->XferOptions == I2C_OTHER_FRAME)
6472  {
6473  hi2c->XferOptions = I2C_FIRST_FRAME;
6474  }
6475  /* else if user set XferOptions to I2C_OTHER_AND_LAST_FRAME */
6476  /* it request implicitly to generate a restart condition */
6477  /* then generate a stop condition at the end of transfer */
6478  /* set XferOptions to I2C_FIRST_AND_LAST_FRAME */
6479  else if (hi2c->XferOptions == I2C_OTHER_AND_LAST_FRAME)
6480  {
6481  hi2c->XferOptions = I2C_FIRST_AND_LAST_FRAME;
6482  }
6483  else
6484  {
6485  /* Nothing to do */
6486  }
6487 }
__IO uint32_t XferOptions

◆ I2C_Disable_IRQ()

static void I2C_Disable_IRQ ( I2C_HandleTypeDef hi2c,
uint16_t  InterruptRequest 
)
static

Manage the disabling of Interrupts.

Parameters
hi2cPointer to a I2C_HandleTypeDef structure that contains the configuration information for the specified I2C.
InterruptRequestValue of I2C Interrupt configuration definition.
Return values
None

Definition at line 6403 of file stm32l4xx_hal_i2c.c.

6404 {
6405  uint32_t tmpisr = 0U;
6406 
6407  if ((InterruptRequest & I2C_XFER_TX_IT) == I2C_XFER_TX_IT)
6408  {
6409  /* Disable TC and TXI interrupts */
6410  tmpisr |= I2C_IT_TCI | I2C_IT_TXI;
6411 
6412  if (((uint32_t)hi2c->State & (uint32_t)HAL_I2C_STATE_LISTEN) != (uint32_t)HAL_I2C_STATE_LISTEN)
6413  {
6414  /* Disable NACK and STOP interrupts */
6415  tmpisr |= I2C_IT_STOPI | I2C_IT_NACKI | I2C_IT_ERRI;
6416  }
6417  }
6418 
6419  if ((InterruptRequest & I2C_XFER_RX_IT) == I2C_XFER_RX_IT)
6420  {
6421  /* Disable TC and RXI interrupts */
6422  tmpisr |= I2C_IT_TCI | I2C_IT_RXI;
6423 
6424  if (((uint32_t)hi2c->State & (uint32_t)HAL_I2C_STATE_LISTEN) != (uint32_t)HAL_I2C_STATE_LISTEN)
6425  {
6426  /* Disable NACK and STOP interrupts */
6427  tmpisr |= I2C_IT_STOPI | I2C_IT_NACKI | I2C_IT_ERRI;
6428  }
6429  }
6430 
6431  if ((InterruptRequest & I2C_XFER_LISTEN_IT) == I2C_XFER_LISTEN_IT)
6432  {
6433  /* Disable ADDR, NACK and STOP interrupts */
6434  tmpisr |= I2C_IT_ADDRI | I2C_IT_STOPI | I2C_IT_NACKI | I2C_IT_ERRI;
6435  }
6436 
6437  if ((InterruptRequest & I2C_XFER_ERROR_IT) == I2C_XFER_ERROR_IT)
6438  {
6439  /* Enable ERR and NACK interrupts */
6440  tmpisr |= I2C_IT_ERRI | I2C_IT_NACKI;
6441  }
6442 
6443  if ((InterruptRequest & I2C_XFER_CPLT_IT) == I2C_XFER_CPLT_IT)
6444  {
6445  /* Enable STOP interrupts */
6446  tmpisr |= I2C_IT_STOPI;
6447  }
6448 
6449  if ((InterruptRequest & I2C_XFER_RELOAD_IT) == I2C_XFER_RELOAD_IT)
6450  {
6451  /* Enable TC interrupts */
6452  tmpisr |= I2C_IT_TCI;
6453  }
6454 
6455  /* Disable interrupts only at the end */
6456  /* to avoid a breaking situation like at "t" time */
6457  /* all disable interrupts request are not done */
6458  __HAL_I2C_DISABLE_IT(hi2c, tmpisr);
6459 }
__IO HAL_I2C_StateTypeDef State

◆ I2C_DMAAbort()

static void I2C_DMAAbort ( DMA_HandleTypeDef hdma)
static

DMA I2C communication abort callback (To be called at end of DMA Abort procedure).

Parameters
hdmaDMA handle.
Return values
None

Definition at line 6040 of file stm32l4xx_hal_i2c.c.

6041 {
6042  I2C_HandleTypeDef *hi2c = (I2C_HandleTypeDef *)(((DMA_HandleTypeDef *)hdma)->Parent); /* Derogation MISRAC2012-Rule-11.5 */
6043 
6044  /* Reset AbortCpltCallback */
6045  hi2c->hdmatx->XferAbortCallback = NULL;
6046  hi2c->hdmarx->XferAbortCallback = NULL;
6047 
6048  /* Check if come from abort from user */
6049  if (hi2c->State == HAL_I2C_STATE_ABORT)
6050  {
6051  hi2c->State = HAL_I2C_STATE_READY;
6052 
6053  /* Call the corresponding callback to inform upper layer of End of Transfer */
6054 #if (USE_HAL_I2C_REGISTER_CALLBACKS == 1)
6055  hi2c->AbortCpltCallback(hi2c);
6056 #else
6058 #endif /* USE_HAL_I2C_REGISTER_CALLBACKS */
6059  }
6060  else
6061  {
6062  /* Call the corresponding callback to inform upper layer of End of Transfer */
6063 #if (USE_HAL_I2C_REGISTER_CALLBACKS == 1)
6064  hi2c->ErrorCallback(hi2c);
6065 #else
6066  HAL_I2C_ErrorCallback(hi2c);
6067 #endif /* USE_HAL_I2C_REGISTER_CALLBACKS */
6068  }
6069 }
DMA_HandleTypeDef * hdmarx
void HAL_I2C_AbortCpltCallback(I2C_HandleTypeDef *hi2c)
I2C abort callback.
void(* XferAbortCallback)(struct __DMA_HandleTypeDef *hdma)
DMA handle Structure definition.
void(* ErrorCallback)(struct __I2C_HandleTypeDef *hi2c)
void HAL_I2C_ErrorCallback(I2C_HandleTypeDef *hi2c)
I2C error callback.
void(* AbortCpltCallback)(struct __I2C_HandleTypeDef *hi2c)
DMA_HandleTypeDef * hdmatx
__IO HAL_I2C_StateTypeDef State

◆ I2C_DMAError()

static void I2C_DMAError ( DMA_HandleTypeDef hdma)
static

DMA I2C communication error callback.

Parameters
hdmaDMA handle
Return values
None

Definition at line 6023 of file stm32l4xx_hal_i2c.c.

6024 {
6025  I2C_HandleTypeDef *hi2c = (I2C_HandleTypeDef *)(((DMA_HandleTypeDef *)hdma)->Parent); /* Derogation MISRAC2012-Rule-11.5 */
6026 
6027  /* Disable Acknowledge */
6028  hi2c->Instance->CR2 |= I2C_CR2_NACK;
6029 
6030  /* Call the corresponding callback to inform upper layer of End of Transfer */
6031  I2C_ITError(hi2c, HAL_I2C_ERROR_DMA);
6032 }
static void I2C_ITError(I2C_HandleTypeDef *hi2c, uint32_t ErrorCode)
I2C interrupts error process.
DMA handle Structure definition.

◆ I2C_DMAMasterReceiveCplt()

static void I2C_DMAMasterReceiveCplt ( DMA_HandleTypeDef hdma)
static

DMA I2C master receive process complete callback.

Parameters
hdmaDMA handle
Return values
None

Definition at line 5948 of file stm32l4xx_hal_i2c.c.

5949 {
5950  I2C_HandleTypeDef *hi2c = (I2C_HandleTypeDef *)(((DMA_HandleTypeDef *)hdma)->Parent); /* Derogation MISRAC2012-Rule-11.5 */
5951 
5952  /* Disable DMA Request */
5953  hi2c->Instance->CR1 &= ~I2C_CR1_RXDMAEN;
5954 
5955  /* If last transfer, enable STOP interrupt */
5956  if (hi2c->XferCount == 0U)
5957  {
5958  /* Enable STOP interrupt */
5959  I2C_Enable_IRQ(hi2c, I2C_XFER_CPLT_IT);
5960  }
5961  /* else prepare a new DMA transfer and enable TCReload interrupt */
5962  else
5963  {
5964  /* Update Buffer pointer */
5965  hi2c->pBuffPtr += hi2c->XferSize;
5966 
5967  /* Set the XferSize to transfer */
5968  if (hi2c->XferCount > MAX_NBYTE_SIZE)
5969  {
5970  hi2c->XferSize = MAX_NBYTE_SIZE;
5971  }
5972  else
5973  {
5974  hi2c->XferSize = hi2c->XferCount;
5975  }
5976 
5977  /* Enable the DMA channel */
5978  if (HAL_DMA_Start_IT(hi2c->hdmarx, (uint32_t)&hi2c->Instance->RXDR, (uint32_t)hi2c->pBuffPtr, hi2c->XferSize) != HAL_OK)
5979  {
5980  /* Call the corresponding callback to inform upper layer of End of Transfer */
5981  I2C_ITError(hi2c, HAL_I2C_ERROR_DMA);
5982  }
5983  else
5984  {
5985  /* Enable TC interrupts */
5986  I2C_Enable_IRQ(hi2c, I2C_XFER_RELOAD_IT);
5987  }
5988  }
5989 }
DMA_HandleTypeDef * hdmarx
static void I2C_ITError(I2C_HandleTypeDef *hi2c, uint32_t ErrorCode)
I2C interrupts error process.
static void I2C_Enable_IRQ(I2C_HandleTypeDef *hi2c, uint16_t InterruptRequest)
Manage the enabling of Interrupts.
DMA handle Structure definition.
HAL_StatusTypeDef HAL_DMA_Start_IT(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t DataLength)
Start the DMA Transfer with interrupt enabled.
return HAL_OK

◆ I2C_DMAMasterTransmitCplt()

static void I2C_DMAMasterTransmitCplt ( DMA_HandleTypeDef hdma)
static

DMA I2C master transmit process complete callback.

Parameters
hdmaDMA handle
Return values
None

Definition at line 5873 of file stm32l4xx_hal_i2c.c.

5874 {
5875  I2C_HandleTypeDef *hi2c = (I2C_HandleTypeDef *)(((DMA_HandleTypeDef *)hdma)->Parent); /* Derogation MISRAC2012-Rule-11.5 */
5876 
5877  /* Disable DMA Request */
5878  hi2c->Instance->CR1 &= ~I2C_CR1_TXDMAEN;
5879 
5880  /* If last transfer, enable STOP interrupt */
5881  if (hi2c->XferCount == 0U)
5882  {
5883  /* Enable STOP interrupt */
5884  I2C_Enable_IRQ(hi2c, I2C_XFER_CPLT_IT);
5885  }
5886  /* else prepare a new DMA transfer and enable TCReload interrupt */
5887  else
5888  {
5889  /* Update Buffer pointer */
5890  hi2c->pBuffPtr += hi2c->XferSize;
5891 
5892  /* Set the XferSize to transfer */
5893  if (hi2c->XferCount > MAX_NBYTE_SIZE)
5894  {
5895  hi2c->XferSize = MAX_NBYTE_SIZE;
5896  }
5897  else
5898  {
5899  hi2c->XferSize = hi2c->XferCount;
5900  }
5901 
5902  /* Enable the DMA channel */
5903  if (HAL_DMA_Start_IT(hi2c->hdmatx, (uint32_t)hi2c->pBuffPtr, (uint32_t)&hi2c->Instance->TXDR, hi2c->XferSize) != HAL_OK)
5904  {
5905  /* Call the corresponding callback to inform upper layer of End of Transfer */
5906  I2C_ITError(hi2c, HAL_I2C_ERROR_DMA);
5907  }
5908  else
5909  {
5910  /* Enable TC interrupts */
5911  I2C_Enable_IRQ(hi2c, I2C_XFER_RELOAD_IT);
5912  }
5913  }
5914 }
static void I2C_ITError(I2C_HandleTypeDef *hi2c, uint32_t ErrorCode)
I2C interrupts error process.
static void I2C_Enable_IRQ(I2C_HandleTypeDef *hi2c, uint16_t InterruptRequest)
Manage the enabling of Interrupts.
DMA handle Structure definition.
HAL_StatusTypeDef HAL_DMA_Start_IT(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t DataLength)
Start the DMA Transfer with interrupt enabled.
return HAL_OK
DMA_HandleTypeDef * hdmatx

◆ I2C_DMASlaveReceiveCplt()

static void I2C_DMASlaveReceiveCplt ( DMA_HandleTypeDef hdma)
static

DMA I2C slave receive process complete callback.

Parameters
hdmaDMA handle
Return values
None

Definition at line 5996 of file stm32l4xx_hal_i2c.c.

5997 {
5998  I2C_HandleTypeDef *hi2c = (I2C_HandleTypeDef *)(((DMA_HandleTypeDef *)hdma)->Parent); /* Derogation MISRAC2012-Rule-11.5 */
5999  uint32_t tmpoptions = hi2c->XferOptions;
6000 
6001  if ((__HAL_DMA_GET_COUNTER(hi2c->hdmarx) == 0U) && \
6002  (tmpoptions != I2C_NO_OPTION_FRAME))
6003  {
6004  /* Disable DMA Request */
6005  hi2c->Instance->CR1 &= ~I2C_CR1_RXDMAEN;
6006 
6007  /* Call I2C Slave Sequential complete process */
6008  I2C_ITSlaveSeqCplt(hi2c);
6009  }
6010  else
6011  {
6012  /* No specific action, Master fully manage the generation of STOP condition */
6013  /* Mean that this generation can arrive at any time, at the end or during DMA process */
6014  /* So STOP condition should be manage through Interrupt treatment */
6015  }
6016 }
DMA_HandleTypeDef * hdmarx
DMA handle Structure definition.
static void I2C_ITSlaveSeqCplt(I2C_HandleTypeDef *hi2c)
I2C Slave sequential complete process.
__IO uint32_t XferOptions

◆ I2C_DMASlaveTransmitCplt()

static void I2C_DMASlaveTransmitCplt ( DMA_HandleTypeDef hdma)
static

DMA I2C slave transmit process complete callback.

Parameters
hdmaDMA handle
Return values
None

Definition at line 5921 of file stm32l4xx_hal_i2c.c.

5922 {
5923  I2C_HandleTypeDef *hi2c = (I2C_HandleTypeDef *)(((DMA_HandleTypeDef *)hdma)->Parent); /* Derogation MISRAC2012-Rule-11.5 */
5924  uint32_t tmpoptions = hi2c->XferOptions;
5925 
5926  if ((tmpoptions == I2C_NEXT_FRAME) || (tmpoptions == I2C_FIRST_FRAME))
5927  {
5928  /* Disable DMA Request */
5929  hi2c->Instance->CR1 &= ~I2C_CR1_TXDMAEN;
5930 
5931  /* Last Byte is Transmitted */
5932  /* Call I2C Slave Sequential complete process */
5933  I2C_ITSlaveSeqCplt(hi2c);
5934  }
5935  else
5936  {
5937  /* No specific action, Master fully manage the generation of STOP condition */
5938  /* Mean that this generation can arrive at any time, at the end or during DMA process */
5939  /* So STOP condition should be manage through Interrupt treatment */
5940  }
5941 }
DMA handle Structure definition.
static void I2C_ITSlaveSeqCplt(I2C_HandleTypeDef *hi2c)
I2C Slave sequential complete process.
__IO uint32_t XferOptions

◆ I2C_Enable_IRQ()

static void I2C_Enable_IRQ ( I2C_HandleTypeDef hi2c,
uint16_t  InterruptRequest 
)
static

Manage the enabling of Interrupts.

Parameters
hi2cPointer to a I2C_HandleTypeDef structure that contains the configuration information for the specified I2C.
InterruptRequestValue of I2C Interrupt configuration definition.
Return values
None

Definition at line 6332 of file stm32l4xx_hal_i2c.c.

6333 {
6334  uint32_t tmpisr = 0U;
6335 
6336  if ((hi2c->XferISR == I2C_Master_ISR_DMA) || \
6337  (hi2c->XferISR == I2C_Slave_ISR_DMA))
6338  {
6339  if ((InterruptRequest & I2C_XFER_LISTEN_IT) == I2C_XFER_LISTEN_IT)
6340  {
6341  /* Enable ERR, STOP, NACK and ADDR interrupts */
6342  tmpisr |= I2C_IT_ADDRI | I2C_IT_STOPI | I2C_IT_NACKI | I2C_IT_ERRI;
6343  }
6344 
6345  if ((InterruptRequest & I2C_XFER_ERROR_IT) == I2C_XFER_ERROR_IT)
6346  {
6347  /* Enable ERR and NACK interrupts */
6348  tmpisr |= I2C_IT_ERRI | I2C_IT_NACKI;
6349  }
6350 
6351  if ((InterruptRequest & I2C_XFER_CPLT_IT) == I2C_XFER_CPLT_IT)
6352  {
6353  /* Enable STOP interrupts */
6354  tmpisr |= I2C_IT_STOPI;
6355  }
6356 
6357  if ((InterruptRequest & I2C_XFER_RELOAD_IT) == I2C_XFER_RELOAD_IT)
6358  {
6359  /* Enable TC interrupts */
6360  tmpisr |= I2C_IT_TCI;
6361  }
6362  }
6363  else
6364  {
6365  if ((InterruptRequest & I2C_XFER_LISTEN_IT) == I2C_XFER_LISTEN_IT)
6366  {
6367  /* Enable ERR, STOP, NACK, and ADDR interrupts */
6368  tmpisr |= I2C_IT_ADDRI | I2C_IT_STOPI | I2C_IT_NACKI | I2C_IT_ERRI;
6369  }
6370 
6371  if ((InterruptRequest & I2C_XFER_TX_IT) == I2C_XFER_TX_IT)
6372  {
6373  /* Enable ERR, TC, STOP, NACK and RXI interrupts */
6374  tmpisr |= I2C_IT_ERRI | I2C_IT_TCI | I2C_IT_STOPI | I2C_IT_NACKI | I2C_IT_TXI;
6375  }
6376 
6377  if ((InterruptRequest & I2C_XFER_RX_IT) == I2C_XFER_RX_IT)
6378  {
6379  /* Enable ERR, TC, STOP, NACK and TXI interrupts */
6380  tmpisr |= I2C_IT_ERRI | I2C_IT_TCI | I2C_IT_STOPI | I2C_IT_NACKI | I2C_IT_RXI;
6381  }
6382 
6383  if ((InterruptRequest & I2C_XFER_CPLT_IT) == I2C_XFER_CPLT_IT)
6384  {
6385  /* Enable STOP interrupts */
6386  tmpisr |= I2C_IT_STOPI;
6387  }
6388  }
6389 
6390  /* Enable interrupts only at the end */
6391  /* to avoid the risk of I2C interrupt handle execution before */
6392  /* all interrupts requested done */
6393  __HAL_I2C_ENABLE_IT(hi2c, tmpisr);
6394 }
static HAL_StatusTypeDef I2C_Slave_ISR_DMA(struct __I2C_HandleTypeDef *hi2c, uint32_t ITFlags, uint32_t ITSources)
Interrupt Sub-Routine which handle the Interrupt Flags Slave Mode with DMA.
HAL_StatusTypeDef(* XferISR)(struct __I2C_HandleTypeDef *hi2c, uint32_t ITFlags, uint32_t ITSources)
static HAL_StatusTypeDef I2C_Master_ISR_DMA(struct __I2C_HandleTypeDef *hi2c, uint32_t ITFlags, uint32_t ITSources)
Interrupt Sub-Routine which handle the Interrupt Flags Master Mode with DMA.

◆ I2C_Flush_TXDR()

static void I2C_Flush_TXDR ( I2C_HandleTypeDef hi2c)
static

I2C Tx data register flush process.

Parameters
hi2cI2C handle.
Return values
None

Definition at line 5852 of file stm32l4xx_hal_i2c.c.

5853 {
5854  /* If a pending TXIS flag is set */
5855  /* Write a dummy data in TXDR to clear it */
5856  if (__HAL_I2C_GET_FLAG(hi2c, I2C_FLAG_TXIS) != RESET)
5857  {
5858  hi2c->Instance->TXDR = 0x00U;
5859  }
5860 
5861  /* Flush TX register if not empty */
5862  if (__HAL_I2C_GET_FLAG(hi2c, I2C_FLAG_TXE) == RESET)
5863  {
5864  __HAL_I2C_CLEAR_FLAG(hi2c, I2C_FLAG_TXE);
5865  }
5866 }

◆ I2C_IsAcknowledgeFailed()

static HAL_StatusTypeDef I2C_IsAcknowledgeFailed ( I2C_HandleTypeDef hi2c,
uint32_t  Timeout,
uint32_t  Tickstart 
)
static

This function handles Acknowledge failed detection during an I2C Communication.

Parameters
hi2cPointer to a I2C_HandleTypeDef structure that contains the configuration information for the specified I2C.
TimeoutTimeout duration
TickstartTick start value
Return values
HALstatus

Definition at line 6245 of file stm32l4xx_hal_i2c.c.

6246 {
6247  if (__HAL_I2C_GET_FLAG(hi2c, I2C_FLAG_AF) == SET)
6248  {
6249  /* Wait until STOP Flag is reset */
6250  /* AutoEnd should be initiate after AF */
6251  while (__HAL_I2C_GET_FLAG(hi2c, I2C_FLAG_STOPF) == RESET)
6252  {
6253  /* Check for the Timeout */
6254  if (Timeout != HAL_MAX_DELAY)
6255  {
6256  if (((HAL_GetTick() - Tickstart) > Timeout) || (Timeout == 0U))
6257  {
6258  hi2c->ErrorCode |= HAL_I2C_ERROR_TIMEOUT;
6259  hi2c->State = HAL_I2C_STATE_READY;
6260  hi2c->Mode = HAL_I2C_MODE_NONE;
6261 
6262  /* Process Unlocked */
6263  __HAL_UNLOCK(hi2c);
6264 
6265  return HAL_ERROR;
6266  }
6267  }
6268  }
6269 
6270  /* Clear NACKF Flag */
6271  __HAL_I2C_CLEAR_FLAG(hi2c, I2C_FLAG_AF);
6272 
6273  /* Clear STOP Flag */
6274  __HAL_I2C_CLEAR_FLAG(hi2c, I2C_FLAG_STOPF);
6275 
6276  /* Flush TX register */
6277  I2C_Flush_TXDR(hi2c);
6278 
6279  /* Clear Configuration Register 2 */
6280  I2C_RESET_CR2(hi2c);
6281 
6282  hi2c->ErrorCode |= HAL_I2C_ERROR_AF;
6283  hi2c->State = HAL_I2C_STATE_READY;
6284  hi2c->Mode = HAL_I2C_MODE_NONE;
6285 
6286  /* Process Unlocked */
6287  __HAL_UNLOCK(hi2c);
6288 
6289  return HAL_ERROR;
6290  }
6291  return HAL_OK;
6292 }
uint32_t HAL_GetTick(void)
Provide a tick value in millisecond.
__HAL_UNLOCK(hrtc)
static void I2C_Flush_TXDR(I2C_HandleTypeDef *hi2c)
I2C Tx data register flush process.
return HAL_OK
__IO HAL_I2C_ModeTypeDef Mode
__IO HAL_I2C_StateTypeDef State

◆ I2C_ITAddrCplt()

static void I2C_ITAddrCplt ( I2C_HandleTypeDef hi2c,
uint32_t  ITFlags 
)
static

I2C Address complete process callback.

Parameters
hi2cI2C handle.
ITFlagsInterrupt flags to handle.
Return values
None

Definition at line 5223 of file stm32l4xx_hal_i2c.c.

5224 {
5225  uint8_t transferdirection;
5226  uint16_t slaveaddrcode;
5227  uint16_t ownadd1code;
5228  uint16_t ownadd2code;
5229 
5230  /* Prevent unused argument(s) compilation warning */
5231  UNUSED(ITFlags);
5232 
5233  /* In case of Listen state, need to inform upper layer of address match code event */
5234  if (((uint32_t)hi2c->State & (uint32_t)HAL_I2C_STATE_LISTEN) == (uint32_t)HAL_I2C_STATE_LISTEN)
5235  {
5236  transferdirection = I2C_GET_DIR(hi2c);
5237  slaveaddrcode = I2C_GET_ADDR_MATCH(hi2c);
5238  ownadd1code = I2C_GET_OWN_ADDRESS1(hi2c);
5239  ownadd2code = I2C_GET_OWN_ADDRESS2(hi2c);
5240 
5241  /* If 10bits addressing mode is selected */
5242  if (hi2c->Init.AddressingMode == I2C_ADDRESSINGMODE_10BIT)
5243  {
5244  if ((slaveaddrcode & SlaveAddr_MSK) == ((ownadd1code >> SlaveAddr_SHIFT) & SlaveAddr_MSK))
5245  {
5246  slaveaddrcode = ownadd1code;
5247  hi2c->AddrEventCount++;
5248  if (hi2c->AddrEventCount == 2U)
5249  {
5250  /* Reset Address Event counter */
5251  hi2c->AddrEventCount = 0U;
5252 
5253  /* Clear ADDR flag */
5254  __HAL_I2C_CLEAR_FLAG(hi2c, I2C_FLAG_ADDR);
5255 
5256  /* Process Unlocked */
5257  __HAL_UNLOCK(hi2c);
5258 
5259  /* Call Slave Addr callback */
5260 #if (USE_HAL_I2C_REGISTER_CALLBACKS == 1)
5261  hi2c->AddrCallback(hi2c, transferdirection, slaveaddrcode);
5262 #else
5263  HAL_I2C_AddrCallback(hi2c, transferdirection, slaveaddrcode);
5264 #endif /* USE_HAL_I2C_REGISTER_CALLBACKS */
5265  }
5266  }
5267  else
5268  {
5269  slaveaddrcode = ownadd2code;
5270 
5271  /* Disable ADDR Interrupts */
5272  I2C_Disable_IRQ(hi2c, I2C_XFER_LISTEN_IT);
5273 
5274  /* Process Unlocked */
5275  __HAL_UNLOCK(hi2c);
5276 
5277  /* Call Slave Addr callback */
5278 #if (USE_HAL_I2C_REGISTER_CALLBACKS == 1)
5279  hi2c->AddrCallback(hi2c, transferdirection, slaveaddrcode);
5280 #else
5281  HAL_I2C_AddrCallback(hi2c, transferdirection, slaveaddrcode);
5282 #endif /* USE_HAL_I2C_REGISTER_CALLBACKS */
5283  }
5284  }
5285  /* else 7 bits addressing mode is selected */
5286  else
5287  {
5288  /* Disable ADDR Interrupts */
5289  I2C_Disable_IRQ(hi2c, I2C_XFER_LISTEN_IT);
5290 
5291  /* Process Unlocked */
5292  __HAL_UNLOCK(hi2c);
5293 
5294  /* Call Slave Addr callback */
5295 #if (USE_HAL_I2C_REGISTER_CALLBACKS == 1)
5296  hi2c->AddrCallback(hi2c, transferdirection, slaveaddrcode);
5297 #else
5298  HAL_I2C_AddrCallback(hi2c, transferdirection, slaveaddrcode);
5299 #endif /* USE_HAL_I2C_REGISTER_CALLBACKS */
5300  }
5301  }
5302  /* Else clear address flag only */
5303  else
5304  {
5305  /* Clear ADDR flag */
5306  __HAL_I2C_CLEAR_FLAG(hi2c, I2C_FLAG_ADDR);
5307 
5308  /* Process Unlocked */
5309  __HAL_UNLOCK(hi2c);
5310  }
5311 }
__IO uint32_t AddrEventCount
__HAL_UNLOCK(hrtc)
I2C_InitTypeDef Init
static void I2C_Disable_IRQ(I2C_HandleTypeDef *hi2c, uint16_t InterruptRequest)
Manage the disabling of Interrupts.
__IO HAL_I2C_StateTypeDef State
void HAL_I2C_AddrCallback(I2C_HandleTypeDef *hi2c, uint8_t TransferDirection, uint16_t AddrMatchCode)
Slave Address Match callback.
void(* AddrCallback)(struct __I2C_HandleTypeDef *hi2c, uint8_t TransferDirection, uint16_t AddrMatchCode)

◆ I2C_ITError()

static void I2C_ITError ( I2C_HandleTypeDef hi2c,
uint32_t  ErrorCode 
)
static

I2C interrupts error process.

Parameters
hi2cI2C handle.
ErrorCodeError code to handle.
Return values
None

Definition at line 5734 of file stm32l4xx_hal_i2c.c.

5735 {
5736  HAL_I2C_StateTypeDef tmpstate = hi2c->State;
5737 
5738  /* Reset handle parameters */
5739  hi2c->Mode = HAL_I2C_MODE_NONE;
5740  hi2c->XferOptions = I2C_NO_OPTION_FRAME;
5741  hi2c->XferCount = 0U;
5742 
5743  /* Set new error code */
5744  hi2c->ErrorCode |= ErrorCode;
5745 
5746  /* Disable Interrupts */
5747  if ((tmpstate == HAL_I2C_STATE_LISTEN) ||
5748  (tmpstate == HAL_I2C_STATE_BUSY_TX_LISTEN) ||
5749  (tmpstate == HAL_I2C_STATE_BUSY_RX_LISTEN))
5750  {
5751  /* Disable all interrupts, except interrupts related to LISTEN state */
5752  I2C_Disable_IRQ(hi2c, I2C_XFER_RX_IT | I2C_XFER_TX_IT);
5753 
5754  /* keep HAL_I2C_STATE_LISTEN if set */
5755  hi2c->State = HAL_I2C_STATE_LISTEN;
5756  hi2c->PreviousState = I2C_STATE_NONE;
5757  hi2c->XferISR = I2C_Slave_ISR_IT;
5758  }
5759  else
5760  {
5761  /* Disable all interrupts */
5762  I2C_Disable_IRQ(hi2c, I2C_XFER_LISTEN_IT | I2C_XFER_RX_IT | I2C_XFER_TX_IT);
5763 
5764  /* If state is an abort treatment on goind, don't change state */
5765  /* This change will be do later */
5766  if (hi2c->State != HAL_I2C_STATE_ABORT)
5767  {
5768  /* Set HAL_I2C_STATE_READY */
5769  hi2c->State = HAL_I2C_STATE_READY;
5770  }
5771  hi2c->PreviousState = I2C_STATE_NONE;
5772  hi2c->XferISR = NULL;
5773  }
5774 
5775  /* Abort DMA TX transfer if any */
5776  if ((hi2c->Instance->CR1 & I2C_CR1_TXDMAEN) == I2C_CR1_TXDMAEN)
5777  {
5778  hi2c->Instance->CR1 &= ~I2C_CR1_TXDMAEN;
5779 
5780  if (hi2c->hdmatx != NULL)
5781  {
5782  /* Set the I2C DMA Abort callback :
5783  will lead to call HAL_I2C_ErrorCallback() at end of DMA abort procedure */
5785 
5786  /* Process Unlocked */
5787  __HAL_UNLOCK(hi2c);
5788 
5789  /* Abort DMA TX */
5790  if (HAL_DMA_Abort_IT(hi2c->hdmatx) != HAL_OK)
5791  {
5792  /* Call Directly XferAbortCallback function in case of error */
5793  hi2c->hdmatx->XferAbortCallback(hi2c->hdmatx);
5794  }
5795  }
5796  }
5797  /* Abort DMA RX transfer if any */
5798  else if ((hi2c->Instance->CR1 & I2C_CR1_RXDMAEN) == I2C_CR1_RXDMAEN)
5799  {
5800  hi2c->Instance->CR1 &= ~I2C_CR1_RXDMAEN;
5801 
5802  if (hi2c->hdmarx != NULL)
5803  {
5804  /* Set the I2C DMA Abort callback :
5805  will lead to call HAL_I2C_ErrorCallback() at end of DMA abort procedure */
5807 
5808  /* Process Unlocked */
5809  __HAL_UNLOCK(hi2c);
5810 
5811  /* Abort DMA RX */
5812  if (HAL_DMA_Abort_IT(hi2c->hdmarx) != HAL_OK)
5813  {
5814  /* Call Directly hi2c->hdmarx->XferAbortCallback function in case of error */
5815  hi2c->hdmarx->XferAbortCallback(hi2c->hdmarx);
5816  }
5817  }
5818  }
5819  else if (hi2c->State == HAL_I2C_STATE_ABORT)
5820  {
5821  hi2c->State = HAL_I2C_STATE_READY;
5822 
5823  /* Process Unlocked */
5824  __HAL_UNLOCK(hi2c);
5825 
5826  /* Call the corresponding callback to inform upper layer of End of Transfer */
5827 #if (USE_HAL_I2C_REGISTER_CALLBACKS == 1)
5828  hi2c->AbortCpltCallback(hi2c);
5829 #else
5831 #endif /* USE_HAL_I2C_REGISTER_CALLBACKS */
5832  }
5833  else
5834  {
5835  /* Process Unlocked */
5836  __HAL_UNLOCK(hi2c);
5837 
5838  /* Call the corresponding callback to inform upper layer of End of Transfer */
5839 #if (USE_HAL_I2C_REGISTER_CALLBACKS == 1)
5840  hi2c->ErrorCallback(hi2c);
5841 #else
5842  HAL_I2C_ErrorCallback(hi2c);
5843 #endif /* USE_HAL_I2C_REGISTER_CALLBACKS */
5844  }
5845 }
DMA_HandleTypeDef * hdmarx
void HAL_I2C_AbortCpltCallback(I2C_HandleTypeDef *hi2c)
I2C abort callback.
void(* XferAbortCallback)(struct __DMA_HandleTypeDef *hdma)
void(* ErrorCallback)(struct __I2C_HandleTypeDef *hi2c)
void HAL_I2C_ErrorCallback(I2C_HandleTypeDef *hi2c)
I2C error callback.
static HAL_StatusTypeDef I2C_Slave_ISR_IT(struct __I2C_HandleTypeDef *hi2c, uint32_t ITFlags, uint32_t ITSources)
Interrupt Sub-Routine which handle the Interrupt Flags Slave Mode with Interrupt. ...
HAL_I2C_StateTypeDef
HAL_StatusTypeDef HAL_DMA_Abort_IT(DMA_HandleTypeDef *hdma)
Aborts the DMA Transfer in Interrupt mode.
__HAL_UNLOCK(hrtc)
return HAL_OK
void(* AbortCpltCallback)(struct __I2C_HandleTypeDef *hi2c)
__IO HAL_I2C_ModeTypeDef Mode
__IO uint32_t PreviousState
DMA_HandleTypeDef * hdmatx
static void I2C_Disable_IRQ(I2C_HandleTypeDef *hi2c, uint16_t InterruptRequest)
Manage the disabling of Interrupts.
HAL_StatusTypeDef(* XferISR)(struct __I2C_HandleTypeDef *hi2c, uint32_t ITFlags, uint32_t ITSources)
__IO HAL_I2C_StateTypeDef State
__IO uint32_t XferOptions
static void I2C_DMAAbort(DMA_HandleTypeDef *hdma)
DMA I2C communication abort callback (To be called at end of DMA Abort procedure).

◆ I2C_ITListenCplt()

static void I2C_ITListenCplt ( I2C_HandleTypeDef hi2c,
uint32_t  ITFlags 
)
static

I2C Listen complete process.

Parameters
hi2cI2C handle.
ITFlagsInterrupt flags to handle.
Return values
None

Definition at line 5683 of file stm32l4xx_hal_i2c.c.

5684 {
5685  /* Reset handle parameters */
5686  hi2c->XferOptions = I2C_NO_OPTION_FRAME;
5687  hi2c->PreviousState = I2C_STATE_NONE;
5688  hi2c->State = HAL_I2C_STATE_READY;
5689  hi2c->Mode = HAL_I2C_MODE_NONE;
5690  hi2c->XferISR = NULL;
5691 
5692  /* Store Last receive data if any */
5693  if (I2C_CHECK_FLAG(ITFlags, I2C_FLAG_RXNE) != RESET)
5694  {
5695  /* Read data from RXDR */
5696  *hi2c->pBuffPtr = (uint8_t)hi2c->Instance->RXDR;
5697 
5698  /* Increment Buffer pointer */
5699  hi2c->pBuffPtr++;
5700 
5701  if ((hi2c->XferSize > 0U))
5702  {
5703  hi2c->XferSize--;
5704  hi2c->XferCount--;
5705 
5706  /* Set ErrorCode corresponding to a Non-Acknowledge */
5707  hi2c->ErrorCode |= HAL_I2C_ERROR_AF;
5708  }
5709  }
5710 
5711  /* Disable all Interrupts*/
5712  I2C_Disable_IRQ(hi2c, I2C_XFER_LISTEN_IT | I2C_XFER_RX_IT | I2C_XFER_TX_IT);
5713 
5714  /* Clear NACK Flag */
5715  __HAL_I2C_CLEAR_FLAG(hi2c, I2C_FLAG_AF);
5716 
5717  /* Process Unlocked */
5718  __HAL_UNLOCK(hi2c);
5719 
5720  /* Call the Listen Complete callback, to inform upper layer of the end of Listen usecase */
5721 #if (USE_HAL_I2C_REGISTER_CALLBACKS == 1)
5722  hi2c->ListenCpltCallback(hi2c);
5723 #else
5725 #endif /* USE_HAL_I2C_REGISTER_CALLBACKS */
5726 }
if(lpuartdiv >=LPUART_BRR_MIN_VALUE)
__HAL_UNLOCK(hrtc)
void(* ListenCpltCallback)(struct __I2C_HandleTypeDef *hi2c)
void HAL_I2C_ListenCpltCallback(I2C_HandleTypeDef *hi2c)
Listen Complete callback.
__IO HAL_I2C_ModeTypeDef Mode
__IO uint32_t PreviousState
static void I2C_Disable_IRQ(I2C_HandleTypeDef *hi2c, uint16_t InterruptRequest)
Manage the disabling of Interrupts.
HAL_StatusTypeDef(* XferISR)(struct __I2C_HandleTypeDef *hi2c, uint32_t ITFlags, uint32_t ITSources)
__IO HAL_I2C_StateTypeDef State
__IO uint32_t XferOptions

◆ I2C_ITMasterCplt()

static void I2C_ITMasterCplt ( I2C_HandleTypeDef hi2c,
uint32_t  ITFlags 
)
static

I2C Master complete process.

Parameters
hi2cI2C handle.
ITFlagsInterrupt flags to handle.
Return values
None

Definition at line 5427 of file stm32l4xx_hal_i2c.c.

5428 {
5429  uint32_t tmperror;
5430 
5431  /* Clear STOP Flag */
5432  __HAL_I2C_CLEAR_FLAG(hi2c, I2C_FLAG_STOPF);
5433 
5434  /* Clear Configuration Register 2 */
5435  I2C_RESET_CR2(hi2c);
5436 
5437  /* Reset handle parameters */
5438  hi2c->PreviousState = I2C_STATE_NONE;
5439  hi2c->XferISR = NULL;
5440  hi2c->XferOptions = I2C_NO_OPTION_FRAME;
5441 
5442  if (I2C_CHECK_FLAG(ITFlags, I2C_FLAG_AF) != RESET)
5443  {
5444  /* Clear NACK Flag */
5445  __HAL_I2C_CLEAR_FLAG(hi2c, I2C_FLAG_AF);
5446 
5447  /* Set acknowledge error code */
5448  hi2c->ErrorCode |= HAL_I2C_ERROR_AF;
5449  }
5450 
5451  /* Flush TX register */
5452  I2C_Flush_TXDR(hi2c);
5453 
5454  /* Disable Interrupts */
5455  I2C_Disable_IRQ(hi2c, I2C_XFER_TX_IT | I2C_XFER_RX_IT);
5456 
5457  /* Store current volatile hi2c->ErrorCode, misra rule */
5458  tmperror = hi2c->ErrorCode;
5459 
5460  /* Call the corresponding callback to inform upper layer of End of Transfer */
5461  if ((hi2c->State == HAL_I2C_STATE_ABORT) || (tmperror != HAL_I2C_ERROR_NONE))
5462  {
5463  /* Call the corresponding callback to inform upper layer of End of Transfer */
5464  I2C_ITError(hi2c, hi2c->ErrorCode);
5465  }
5466  /* hi2c->State == HAL_I2C_STATE_BUSY_TX */
5467  else if (hi2c->State == HAL_I2C_STATE_BUSY_TX)
5468  {
5469  hi2c->State = HAL_I2C_STATE_READY;
5470 
5471  if (hi2c->Mode == HAL_I2C_MODE_MEM)
5472  {
5473  hi2c->Mode = HAL_I2C_MODE_NONE;
5474 
5475  /* Process Unlocked */
5476  __HAL_UNLOCK(hi2c);
5477 
5478  /* Call the corresponding callback to inform upper layer of End of Transfer */
5479 #if (USE_HAL_I2C_REGISTER_CALLBACKS == 1)
5480  hi2c->MemTxCpltCallback(hi2c);
5481 #else
5483 #endif /* USE_HAL_I2C_REGISTER_CALLBACKS */
5484  }
5485  else
5486  {
5487  hi2c->Mode = HAL_I2C_MODE_NONE;
5488 
5489  /* Process Unlocked */
5490  __HAL_UNLOCK(hi2c);
5491 
5492  /* Call the corresponding callback to inform upper layer of End of Transfer */
5493 #if (USE_HAL_I2C_REGISTER_CALLBACKS == 1)
5494  hi2c->MasterTxCpltCallback(hi2c);
5495 #else
5497 #endif /* USE_HAL_I2C_REGISTER_CALLBACKS */
5498  }
5499  }
5500  /* hi2c->State == HAL_I2C_STATE_BUSY_RX */
5501  else if (hi2c->State == HAL_I2C_STATE_BUSY_RX)
5502  {
5503  hi2c->State = HAL_I2C_STATE_READY;
5504 
5505  if (hi2c->Mode == HAL_I2C_MODE_MEM)
5506  {
5507  hi2c->Mode = HAL_I2C_MODE_NONE;
5508 
5509  /* Process Unlocked */
5510  __HAL_UNLOCK(hi2c);
5511 
5512  /* Call the corresponding callback to inform upper layer of End of Transfer */
5513 #if (USE_HAL_I2C_REGISTER_CALLBACKS == 1)
5514  hi2c->MemRxCpltCallback(hi2c);
5515 #else
5517 #endif /* USE_HAL_I2C_REGISTER_CALLBACKS */
5518  }
5519  else
5520  {
5521  hi2c->Mode = HAL_I2C_MODE_NONE;
5522 
5523  /* Process Unlocked */
5524  __HAL_UNLOCK(hi2c);
5525 
5526  /* Call the corresponding callback to inform upper layer of End of Transfer */
5527 #if (USE_HAL_I2C_REGISTER_CALLBACKS == 1)
5528  hi2c->MasterRxCpltCallback(hi2c);
5529 #else
5531 #endif /* USE_HAL_I2C_REGISTER_CALLBACKS */
5532  }
5533  }
5534  else
5535  {
5536  /* Nothing to do */
5537  }
5538 }
static void I2C_ITError(I2C_HandleTypeDef *hi2c, uint32_t ErrorCode)
I2C interrupts error process.
void HAL_I2C_MasterRxCpltCallback(I2C_HandleTypeDef *hi2c)
Master Rx Transfer completed callback.
__HAL_UNLOCK(hrtc)
void(* MemTxCpltCallback)(struct __I2C_HandleTypeDef *hi2c)
void(* MemRxCpltCallback)(struct __I2C_HandleTypeDef *hi2c)
void HAL_I2C_MemTxCpltCallback(I2C_HandleTypeDef *hi2c)
Memory Tx Transfer completed callback.
static void I2C_Flush_TXDR(I2C_HandleTypeDef *hi2c)
I2C Tx data register flush process.
void(* MasterTxCpltCallback)(struct __I2C_HandleTypeDef *hi2c)
__IO HAL_I2C_ModeTypeDef Mode
__IO uint32_t PreviousState
static void I2C_Disable_IRQ(I2C_HandleTypeDef *hi2c, uint16_t InterruptRequest)
Manage the disabling of Interrupts.
HAL_StatusTypeDef(* XferISR)(struct __I2C_HandleTypeDef *hi2c, uint32_t ITFlags, uint32_t ITSources)
__IO HAL_I2C_StateTypeDef State
__IO uint32_t XferOptions
void HAL_I2C_MasterTxCpltCallback(I2C_HandleTypeDef *hi2c)
Master Tx Transfer completed callback.
void HAL_I2C_MemRxCpltCallback(I2C_HandleTypeDef *hi2c)
Memory Rx Transfer completed callback.
void(* MasterRxCpltCallback)(struct __I2C_HandleTypeDef *hi2c)

◆ I2C_ITMasterSeqCplt()

static void I2C_ITMasterSeqCplt ( I2C_HandleTypeDef hi2c)
static

I2C Master sequential complete process.

Parameters
hi2cI2C handle.
Return values
None

Definition at line 5318 of file stm32l4xx_hal_i2c.c.

5319 {
5320  /* Reset I2C handle mode */
5321  hi2c->Mode = HAL_I2C_MODE_NONE;
5322 
5323  /* No Generate Stop, to permit restart mode */
5324  /* The stop will be done at the end of transfer, when I2C_AUTOEND_MODE enable */
5325  if (hi2c->State == HAL_I2C_STATE_BUSY_TX)
5326  {
5327  hi2c->State = HAL_I2C_STATE_READY;
5328  hi2c->PreviousState = I2C_STATE_MASTER_BUSY_TX;
5329  hi2c->XferISR = NULL;
5330 
5331  /* Disable Interrupts */
5332  I2C_Disable_IRQ(hi2c, I2C_XFER_TX_IT);
5333 
5334  /* Process Unlocked */
5335  __HAL_UNLOCK(hi2c);
5336 
5337  /* Call the corresponding callback to inform upper layer of End of Transfer */
5338 #if (USE_HAL_I2C_REGISTER_CALLBACKS == 1)
5339  hi2c->MasterTxCpltCallback(hi2c);
5340 #else
5342 #endif /* USE_HAL_I2C_REGISTER_CALLBACKS */
5343  }
5344  /* hi2c->State == HAL_I2C_STATE_BUSY_RX */
5345  else
5346  {
5347  hi2c->State = HAL_I2C_STATE_READY;
5348  hi2c->PreviousState = I2C_STATE_MASTER_BUSY_RX;
5349  hi2c->XferISR = NULL;
5350 
5351  /* Disable Interrupts */
5352  I2C_Disable_IRQ(hi2c, I2C_XFER_RX_IT);
5353 
5354  /* Process Unlocked */
5355  __HAL_UNLOCK(hi2c);
5356 
5357  /* Call the corresponding callback to inform upper layer of End of Transfer */
5358 #if (USE_HAL_I2C_REGISTER_CALLBACKS == 1)
5359  hi2c->MasterRxCpltCallback(hi2c);
5360 #else
5362 #endif /* USE_HAL_I2C_REGISTER_CALLBACKS */
5363  }
5364 }
void HAL_I2C_MasterRxCpltCallback(I2C_HandleTypeDef *hi2c)
Master Rx Transfer completed callback.
__HAL_UNLOCK(hrtc)
void(* MasterTxCpltCallback)(struct __I2C_HandleTypeDef *hi2c)
__IO HAL_I2C_ModeTypeDef Mode
__IO uint32_t PreviousState
static void I2C_Disable_IRQ(I2C_HandleTypeDef *hi2c, uint16_t InterruptRequest)
Manage the disabling of Interrupts.
HAL_StatusTypeDef(* XferISR)(struct __I2C_HandleTypeDef *hi2c, uint32_t ITFlags, uint32_t ITSources)
__IO HAL_I2C_StateTypeDef State
void HAL_I2C_MasterTxCpltCallback(I2C_HandleTypeDef *hi2c)
Master Tx Transfer completed callback.
void(* MasterRxCpltCallback)(struct __I2C_HandleTypeDef *hi2c)

◆ I2C_ITSlaveCplt()

static void I2C_ITSlaveCplt ( I2C_HandleTypeDef hi2c,
uint32_t  ITFlags 
)
static

I2C Slave complete process.

Parameters
hi2cI2C handle.
ITFlagsInterrupt flags to handle.
Return values
None

Definition at line 5546 of file stm32l4xx_hal_i2c.c.

5547 {
5548  uint32_t tmpcr1value = READ_REG(hi2c->Instance->CR1);
5549  uint32_t tmpITFlags = ITFlags;
5550 
5551  /* Clear STOP Flag */
5552  __HAL_I2C_CLEAR_FLAG(hi2c, I2C_FLAG_STOPF);
5553 
5554  /* Disable all interrupts */
5555  I2C_Disable_IRQ(hi2c, I2C_XFER_LISTEN_IT | I2C_XFER_TX_IT | I2C_XFER_RX_IT);
5556 
5557  /* Disable Address Acknowledge */
5558  hi2c->Instance->CR2 |= I2C_CR2_NACK;
5559 
5560  /* Clear Configuration Register 2 */
5561  I2C_RESET_CR2(hi2c);
5562 
5563  /* Flush TX register */
5564  I2C_Flush_TXDR(hi2c);
5565 
5566  /* If a DMA is ongoing, Update handle size context */
5567  if (I2C_CHECK_IT_SOURCE(tmpcr1value, I2C_CR1_TXDMAEN) != RESET)
5568  {
5569  if (hi2c->hdmatx != NULL)
5570  {
5571  hi2c->XferCount = (uint16_t)__HAL_DMA_GET_COUNTER(hi2c->hdmatx);
5572  }
5573  }
5574  else if (I2C_CHECK_IT_SOURCE(tmpcr1value, I2C_CR1_RXDMAEN) != RESET)
5575  {
5576  if (hi2c->hdmarx != NULL)
5577  {
5578  hi2c->XferCount = (uint16_t)__HAL_DMA_GET_COUNTER(hi2c->hdmarx);
5579  }
5580  }
5581  else
5582  {
5583  /* Do nothing */
5584  }
5585 
5586  /* Store Last receive data if any */
5587  if (I2C_CHECK_FLAG(tmpITFlags, I2C_FLAG_RXNE) != RESET)
5588  {
5589  /* Remove RXNE flag on temporary variable as read done */
5590  tmpITFlags &= ~I2C_FLAG_RXNE;
5591 
5592  /* Read data from RXDR */
5593  *hi2c->pBuffPtr = (uint8_t)hi2c->Instance->RXDR;
5594 
5595  /* Increment Buffer pointer */
5596  hi2c->pBuffPtr++;
5597 
5598  if ((hi2c->XferSize > 0U))
5599  {
5600  hi2c->XferSize--;
5601  hi2c->XferCount--;
5602  }
5603  }
5604 
5605  /* All data are not transferred, so set error code accordingly */
5606  if (hi2c->XferCount != 0U)
5607  {
5608  /* Set ErrorCode corresponding to a Non-Acknowledge */
5609  hi2c->ErrorCode |= HAL_I2C_ERROR_AF;
5610  }
5611 
5612  hi2c->PreviousState = I2C_STATE_NONE;
5613  hi2c->Mode = HAL_I2C_MODE_NONE;
5614  hi2c->XferISR = NULL;
5615 
5616  if (hi2c->ErrorCode != HAL_I2C_ERROR_NONE)
5617  {
5618  /* Call the corresponding callback to inform upper layer of End of Transfer */
5619  I2C_ITError(hi2c, hi2c->ErrorCode);
5620 
5621  /* Call the Listen Complete callback, to inform upper layer of the end of Listen usecase */
5622  if (hi2c->State == HAL_I2C_STATE_LISTEN)
5623  {
5624  /* Call I2C Listen complete process */
5625  I2C_ITListenCplt(hi2c, tmpITFlags);
5626  }
5627  }
5628  else if (hi2c->XferOptions != I2C_NO_OPTION_FRAME)
5629  {
5630  /* Call the Sequential Complete callback, to inform upper layer of the end of Tranfer */
5631  I2C_ITSlaveSeqCplt(hi2c);
5632 
5633  hi2c->XferOptions = I2C_NO_OPTION_FRAME;
5634  hi2c->State = HAL_I2C_STATE_READY;
5635 
5636  /* Process Unlocked */
5637  __HAL_UNLOCK(hi2c);
5638 
5639  /* Call the Listen Complete callback, to inform upper layer of the end of Listen usecase */
5640 #if (USE_HAL_I2C_REGISTER_CALLBACKS == 1)
5641  hi2c->ListenCpltCallback(hi2c);
5642 #else
5644 #endif /* USE_HAL_I2C_REGISTER_CALLBACKS */
5645  }
5646  /* Call the corresponding callback to inform upper layer of End of Transfer */
5647  else if (hi2c->State == HAL_I2C_STATE_BUSY_RX)
5648  {
5649  hi2c->State = HAL_I2C_STATE_READY;
5650 
5651  /* Process Unlocked */
5652  __HAL_UNLOCK(hi2c);
5653 
5654  /* Call the corresponding callback to inform upper layer of End of Transfer */
5655 #if (USE_HAL_I2C_REGISTER_CALLBACKS == 1)
5656  hi2c->SlaveRxCpltCallback(hi2c);
5657 #else
5659 #endif /* USE_HAL_I2C_REGISTER_CALLBACKS */
5660  }
5661  else
5662  {
5663  hi2c->State = HAL_I2C_STATE_READY;
5664 
5665  /* Process Unlocked */
5666  __HAL_UNLOCK(hi2c);
5667 
5668  /* Call the corresponding callback to inform upper layer of End of Transfer */
5669 #if (USE_HAL_I2C_REGISTER_CALLBACKS == 1)
5670  hi2c->SlaveTxCpltCallback(hi2c);
5671 #else
5673 #endif /* USE_HAL_I2C_REGISTER_CALLBACKS */
5674  }
5675 }
DMA_HandleTypeDef * hdmarx
void HAL_I2C_SlaveRxCpltCallback(I2C_HandleTypeDef *hi2c)
Slave Rx Transfer completed callback.
void(* SlaveRxCpltCallback)(struct __I2C_HandleTypeDef *hi2c)
static void I2C_ITError(I2C_HandleTypeDef *hi2c, uint32_t ErrorCode)
I2C interrupts error process.
static void I2C_ITSlaveSeqCplt(I2C_HandleTypeDef *hi2c)
I2C Slave sequential complete process.
if(lpuartdiv >=LPUART_BRR_MIN_VALUE)
void HAL_I2C_SlaveTxCpltCallback(I2C_HandleTypeDef *hi2c)
Slave Tx Transfer completed callback.
static void I2C_ITListenCplt(I2C_HandleTypeDef *hi2c, uint32_t ITFlags)
I2C Listen complete process.
__HAL_UNLOCK(hrtc)
void(* ListenCpltCallback)(struct __I2C_HandleTypeDef *hi2c)
void HAL_I2C_ListenCpltCallback(I2C_HandleTypeDef *hi2c)
Listen Complete callback.
static void I2C_Flush_TXDR(I2C_HandleTypeDef *hi2c)
I2C Tx data register flush process.
void(* SlaveTxCpltCallback)(struct __I2C_HandleTypeDef *hi2c)
__IO HAL_I2C_ModeTypeDef Mode
__IO uint32_t PreviousState
DMA_HandleTypeDef * hdmatx
static void I2C_Disable_IRQ(I2C_HandleTypeDef *hi2c, uint16_t InterruptRequest)
Manage the disabling of Interrupts.
HAL_StatusTypeDef(* XferISR)(struct __I2C_HandleTypeDef *hi2c, uint32_t ITFlags, uint32_t ITSources)
__IO HAL_I2C_StateTypeDef State
__IO uint32_t XferOptions

◆ I2C_ITSlaveSeqCplt()

static void I2C_ITSlaveSeqCplt ( I2C_HandleTypeDef hi2c)
static

I2C Slave sequential complete process.

Parameters
hi2cI2C handle.
Return values
None

Definition at line 5371 of file stm32l4xx_hal_i2c.c.

5372 {
5373  /* Reset I2C handle mode */
5374  hi2c->Mode = HAL_I2C_MODE_NONE;
5375 
5376  if (hi2c->State == HAL_I2C_STATE_BUSY_TX_LISTEN)
5377  {
5378  /* Remove HAL_I2C_STATE_SLAVE_BUSY_TX, keep only HAL_I2C_STATE_LISTEN */
5379  hi2c->State = HAL_I2C_STATE_LISTEN;
5380  hi2c->PreviousState = I2C_STATE_SLAVE_BUSY_TX;
5381 
5382  /* Disable Interrupts */
5383  I2C_Disable_IRQ(hi2c, I2C_XFER_TX_IT);
5384 
5385  /* Process Unlocked */
5386  __HAL_UNLOCK(hi2c);
5387 
5388  /* Call the corresponding callback to inform upper layer of End of Transfer */
5389 #if (USE_HAL_I2C_REGISTER_CALLBACKS == 1)
5390  hi2c->SlaveTxCpltCallback(hi2c);
5391 #else
5393 #endif /* USE_HAL_I2C_REGISTER_CALLBACKS */
5394  }
5395 
5396  else if (hi2c->State == HAL_I2C_STATE_BUSY_RX_LISTEN)
5397  {
5398  /* Remove HAL_I2C_STATE_SLAVE_BUSY_RX, keep only HAL_I2C_STATE_LISTEN */
5399  hi2c->State = HAL_I2C_STATE_LISTEN;
5400  hi2c->PreviousState = I2C_STATE_SLAVE_BUSY_RX;
5401 
5402  /* Disable Interrupts */
5403  I2C_Disable_IRQ(hi2c, I2C_XFER_RX_IT);
5404 
5405  /* Process Unlocked */
5406  __HAL_UNLOCK(hi2c);
5407 
5408  /* Call the corresponding callback to inform upper layer of End of Transfer */
5409 #if (USE_HAL_I2C_REGISTER_CALLBACKS == 1)
5410  hi2c->SlaveRxCpltCallback(hi2c);
5411 #else
5413 #endif /* USE_HAL_I2C_REGISTER_CALLBACKS */
5414  }
5415  else
5416  {
5417  /* Nothing to do */
5418  }
5419 }
void HAL_I2C_SlaveRxCpltCallback(I2C_HandleTypeDef *hi2c)
Slave Rx Transfer completed callback.
void(* SlaveRxCpltCallback)(struct __I2C_HandleTypeDef *hi2c)
void HAL_I2C_SlaveTxCpltCallback(I2C_HandleTypeDef *hi2c)
Slave Tx Transfer completed callback.
__HAL_UNLOCK(hrtc)
void(* SlaveTxCpltCallback)(struct __I2C_HandleTypeDef *hi2c)
__IO HAL_I2C_ModeTypeDef Mode
__IO uint32_t PreviousState
static void I2C_Disable_IRQ(I2C_HandleTypeDef *hi2c, uint16_t InterruptRequest)
Manage the disabling of Interrupts.
__IO HAL_I2C_StateTypeDef State

◆ I2C_Master_ISR_DMA()

static HAL_StatusTypeDef I2C_Master_ISR_DMA ( struct __I2C_HandleTypeDef hi2c,
uint32_t  ITFlags,
uint32_t  ITSources 
)
static

Interrupt Sub-Routine which handle the Interrupt Flags Master Mode with DMA.

Parameters
hi2cPointer to a I2C_HandleTypeDef structure that contains the configuration information for the specified I2C.
ITFlagsInterrupt flags to handle.
ITSourcesInterrupt sources enabled.
Return values
HALstatus

Definition at line 4868 of file stm32l4xx_hal_i2c.c.

4869 {
4870  uint16_t devaddress;
4871  uint32_t xfermode;
4872 
4873  /* Process Locked */
4874  __HAL_LOCK(hi2c);
4875 
4876  if ((I2C_CHECK_FLAG(ITFlags, I2C_FLAG_AF) != RESET) && (I2C_CHECK_IT_SOURCE(ITSources, I2C_IT_NACKI) != RESET))
4877  {
4878  /* Clear NACK Flag */
4879  __HAL_I2C_CLEAR_FLAG(hi2c, I2C_FLAG_AF);
4880 
4881  /* Set corresponding Error Code */
4882  hi2c->ErrorCode |= HAL_I2C_ERROR_AF;
4883 
4884  /* No need to generate STOP, it is automatically done */
4885  /* But enable STOP interrupt, to treat it */
4886  /* Error callback will be send during stop flag treatment */
4887  I2C_Enable_IRQ(hi2c, I2C_XFER_CPLT_IT);
4888 
4889  /* Flush TX register */
4890  I2C_Flush_TXDR(hi2c);
4891  }
4892  else if ((I2C_CHECK_FLAG(ITFlags, I2C_FLAG_TCR) != RESET) && (I2C_CHECK_IT_SOURCE(ITSources, I2C_IT_TCI) != RESET))
4893  {
4894  /* Disable TC interrupt */
4895  __HAL_I2C_DISABLE_IT(hi2c, I2C_IT_TCI);
4896 
4897  if (hi2c->XferCount != 0U)
4898  {
4899  /* Recover Slave address */
4900  devaddress = (uint16_t)(hi2c->Instance->CR2 & I2C_CR2_SADD);
4901 
4902  /* Prepare the new XferSize to transfer */
4903  if (hi2c->XferCount > MAX_NBYTE_SIZE)
4904  {
4905  hi2c->XferSize = MAX_NBYTE_SIZE;
4906  xfermode = I2C_RELOAD_MODE;
4907  }
4908  else
4909  {
4910  hi2c->XferSize = hi2c->XferCount;
4911  if (hi2c->XferOptions != I2C_NO_OPTION_FRAME)
4912  {
4913  xfermode = hi2c->XferOptions;
4914  }
4915  else
4916  {
4917  xfermode = I2C_AUTOEND_MODE;
4918  }
4919  }
4920 
4921  /* Set the new XferSize in Nbytes register */
4922  I2C_TransferConfig(hi2c, devaddress, (uint8_t)hi2c->XferSize, xfermode, I2C_NO_STARTSTOP);
4923 
4924  /* Update XferCount value */
4925  hi2c->XferCount -= hi2c->XferSize;
4926 
4927  /* Enable DMA Request */
4928  if (hi2c->State == HAL_I2C_STATE_BUSY_RX)
4929  {
4930  hi2c->Instance->CR1 |= I2C_CR1_RXDMAEN;
4931  }
4932  else
4933  {
4934  hi2c->Instance->CR1 |= I2C_CR1_TXDMAEN;
4935  }
4936  }
4937  else
4938  {
4939  /* Call TxCpltCallback() if no stop mode is set */
4940  if (I2C_GET_STOP_MODE(hi2c) != I2C_AUTOEND_MODE)
4941  {
4942  /* Call I2C Master Sequential complete process */
4943  I2C_ITMasterSeqCplt(hi2c);
4944  }
4945  else
4946  {
4947  /* Wrong size Status regarding TCR flag event */
4948  /* Call the corresponding callback to inform upper layer of End of Transfer */
4949  I2C_ITError(hi2c, HAL_I2C_ERROR_SIZE);
4950  }
4951  }
4952  }
4953  else if ((I2C_CHECK_FLAG(ITFlags, I2C_FLAG_TC) != RESET) && (I2C_CHECK_IT_SOURCE(ITSources, I2C_IT_TCI) != RESET))
4954  {
4955  if (hi2c->XferCount == 0U)
4956  {
4957  if (I2C_GET_STOP_MODE(hi2c) != I2C_AUTOEND_MODE)
4958  {
4959  /* Generate a stop condition in case of no transfer option */
4960  if (hi2c->XferOptions == I2C_NO_OPTION_FRAME)
4961  {
4962  /* Generate Stop */
4963  hi2c->Instance->CR2 |= I2C_CR2_STOP;
4964  }
4965  else
4966  {
4967  /* Call I2C Master Sequential complete process */
4968  I2C_ITMasterSeqCplt(hi2c);
4969  }
4970  }
4971  }
4972  else
4973  {
4974  /* Wrong size Status regarding TC flag event */
4975  /* Call the corresponding callback to inform upper layer of End of Transfer */
4976  I2C_ITError(hi2c, HAL_I2C_ERROR_SIZE);
4977  }
4978  }
4979  else if ((I2C_CHECK_FLAG(ITFlags, I2C_FLAG_STOPF) != RESET) && (I2C_CHECK_IT_SOURCE(ITSources, I2C_IT_STOPI) != RESET))
4980  {
4981  /* Call I2C Master complete process */
4982  I2C_ITMasterCplt(hi2c, ITFlags);
4983  }
4984  else
4985  {
4986  /* Nothing to do */
4987  }
4988 
4989  /* Process Unlocked */
4990  __HAL_UNLOCK(hi2c);
4991 
4992  return HAL_OK;
4993 }
static void I2C_ITError(I2C_HandleTypeDef *hi2c, uint32_t ErrorCode)
I2C interrupts error process.
static void I2C_Enable_IRQ(I2C_HandleTypeDef *hi2c, uint16_t InterruptRequest)
Manage the enabling of Interrupts.
__HAL_UNLOCK(hrtc)
__HAL_LOCK(hrtc)
static void I2C_Flush_TXDR(I2C_HandleTypeDef *hi2c)
I2C Tx data register flush process.
return HAL_OK
static void I2C_ITMasterSeqCplt(I2C_HandleTypeDef *hi2c)
I2C Master sequential complete process.
static void I2C_TransferConfig(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint8_t Size, uint32_t Mode, uint32_t Request)
Handles I2Cx communication when starting transfer or during transfer (TC or TCR flag are set)...
static void I2C_ITMasterCplt(I2C_HandleTypeDef *hi2c, uint32_t ITFlags)
I2C Master complete process.
__IO HAL_I2C_StateTypeDef State
__IO uint32_t XferOptions

◆ I2C_Master_ISR_IT()

static HAL_StatusTypeDef I2C_Master_ISR_IT ( struct __I2C_HandleTypeDef hi2c,
uint32_t  ITFlags,
uint32_t  ITSources 
)
static

Interrupt Sub-Routine which handle the Interrupt Flags Master Mode with Interrupt.

Parameters
hi2cPointer to a I2C_HandleTypeDef structure that contains the configuration information for the specified I2C.
ITFlagsInterrupt flags to handle.
ITSourcesInterrupt sources enabled.
Return values
HALstatus

Definition at line 4595 of file stm32l4xx_hal_i2c.c.

4596 {
4597  uint16_t devaddress;
4598  uint32_t tmpITFlags = ITFlags;
4599 
4600  /* Process Locked */
4601  __HAL_LOCK(hi2c);
4602 
4603  if ((I2C_CHECK_FLAG(tmpITFlags, I2C_FLAG_AF) != RESET) && (I2C_CHECK_IT_SOURCE(ITSources, I2C_IT_NACKI) != RESET))
4604  {
4605  /* Clear NACK Flag */
4606  __HAL_I2C_CLEAR_FLAG(hi2c, I2C_FLAG_AF);
4607 
4608  /* Set corresponding Error Code */
4609  /* No need to generate STOP, it is automatically done */
4610  /* Error callback will be send during stop flag treatment */
4611  hi2c->ErrorCode |= HAL_I2C_ERROR_AF;
4612 
4613  /* Flush TX register */
4614  I2C_Flush_TXDR(hi2c);
4615  }
4616  else if ((I2C_CHECK_FLAG(tmpITFlags, I2C_FLAG_RXNE) != RESET) && (I2C_CHECK_IT_SOURCE(ITSources, I2C_IT_RXI) != RESET))
4617  {
4618  /* Remove RXNE flag on temporary variable as read done */
4619  tmpITFlags &= ~I2C_FLAG_RXNE;
4620 
4621  /* Read data from RXDR */
4622  *hi2c->pBuffPtr = (uint8_t)hi2c->Instance->RXDR;
4623 
4624  /* Increment Buffer pointer */
4625  hi2c->pBuffPtr++;
4626 
4627  hi2c->XferSize--;
4628  hi2c->XferCount--;
4629  }
4630  else if ((I2C_CHECK_FLAG(tmpITFlags, I2C_FLAG_TXIS) != RESET) && (I2C_CHECK_IT_SOURCE(ITSources, I2C_IT_TXI) != RESET))
4631  {
4632  /* Write data to TXDR */
4633  hi2c->Instance->TXDR = *hi2c->pBuffPtr;
4634 
4635  /* Increment Buffer pointer */
4636  hi2c->pBuffPtr++;
4637 
4638  hi2c->XferSize--;
4639  hi2c->XferCount--;
4640  }
4641  else if ((I2C_CHECK_FLAG(tmpITFlags, I2C_FLAG_TCR) != RESET) && (I2C_CHECK_IT_SOURCE(ITSources, I2C_IT_TCI) != RESET))
4642  {
4643  if ((hi2c->XferCount != 0U) && (hi2c->XferSize == 0U))
4644  {
4645  devaddress = (uint16_t)(hi2c->Instance->CR2 & I2C_CR2_SADD);
4646 
4647  if (hi2c->XferCount > MAX_NBYTE_SIZE)
4648  {
4649  hi2c->XferSize = MAX_NBYTE_SIZE;
4650  I2C_TransferConfig(hi2c, devaddress, (uint8_t)hi2c->XferSize, I2C_RELOAD_MODE, I2C_NO_STARTSTOP);
4651  }
4652  else
4653  {
4654  hi2c->XferSize = hi2c->XferCount;
4655  if (hi2c->XferOptions != I2C_NO_OPTION_FRAME)
4656  {
4657  I2C_TransferConfig(hi2c, devaddress, (uint8_t)hi2c->XferSize, hi2c->XferOptions, I2C_NO_STARTSTOP);
4658  }
4659  else
4660  {
4661  I2C_TransferConfig(hi2c, devaddress, (uint8_t)hi2c->XferSize, I2C_AUTOEND_MODE, I2C_NO_STARTSTOP);
4662  }
4663  }
4664  }
4665  else
4666  {
4667  /* Call TxCpltCallback() if no stop mode is set */
4668  if (I2C_GET_STOP_MODE(hi2c) != I2C_AUTOEND_MODE)
4669  {
4670  /* Call I2C Master Sequential complete process */
4671  I2C_ITMasterSeqCplt(hi2c);
4672  }
4673  else
4674  {
4675  /* Wrong size Status regarding TCR flag event */
4676  /* Call the corresponding callback to inform upper layer of End of Transfer */
4677  I2C_ITError(hi2c, HAL_I2C_ERROR_SIZE);
4678  }
4679  }
4680  }
4681  else if ((I2C_CHECK_FLAG(tmpITFlags, I2C_FLAG_TC) != RESET) && (I2C_CHECK_IT_SOURCE(ITSources, I2C_IT_TCI) != RESET))
4682  {
4683  if (hi2c->XferCount == 0U)
4684  {
4685  if (I2C_GET_STOP_MODE(hi2c) != I2C_AUTOEND_MODE)
4686  {
4687  /* Generate a stop condition in case of no transfer option */
4688  if (hi2c->XferOptions == I2C_NO_OPTION_FRAME)
4689  {
4690  /* Generate Stop */
4691  hi2c->Instance->CR2 |= I2C_CR2_STOP;
4692  }
4693  else
4694  {
4695  /* Call I2C Master Sequential complete process */
4696  I2C_ITMasterSeqCplt(hi2c);
4697  }
4698  }
4699  }
4700  else
4701  {
4702  /* Wrong size Status regarding TC flag event */
4703  /* Call the corresponding callback to inform upper layer of End of Transfer */
4704  I2C_ITError(hi2c, HAL_I2C_ERROR_SIZE);
4705  }
4706  }
4707  else
4708  {
4709  /* Nothing to do */
4710  }
4711 
4712  if ((I2C_CHECK_FLAG(tmpITFlags, I2C_FLAG_STOPF) != RESET) && (I2C_CHECK_IT_SOURCE(ITSources, I2C_IT_STOPI) != RESET))
4713  {
4714  /* Call I2C Master complete process */
4715  I2C_ITMasterCplt(hi2c, tmpITFlags);
4716  }
4717 
4718  /* Process Unlocked */
4719  __HAL_UNLOCK(hi2c);
4720 
4721  return HAL_OK;
4722 }
static void I2C_ITError(I2C_HandleTypeDef *hi2c, uint32_t ErrorCode)
I2C interrupts error process.
__HAL_UNLOCK(hrtc)
__HAL_LOCK(hrtc)
static void I2C_Flush_TXDR(I2C_HandleTypeDef *hi2c)
I2C Tx data register flush process.
return HAL_OK
static void I2C_ITMasterSeqCplt(I2C_HandleTypeDef *hi2c)
I2C Master sequential complete process.
static void I2C_TransferConfig(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint8_t Size, uint32_t Mode, uint32_t Request)
Handles I2Cx communication when starting transfer or during transfer (TC or TCR flag are set)...
static void I2C_ITMasterCplt(I2C_HandleTypeDef *hi2c, uint32_t ITFlags)
I2C Master complete process.
__IO uint32_t XferOptions

◆ I2C_RequestMemoryRead()

static HAL_StatusTypeDef I2C_RequestMemoryRead ( I2C_HandleTypeDef hi2c,
uint16_t  DevAddress,
uint16_t  MemAddress,
uint16_t  MemAddSize,
uint32_t  Timeout,
uint32_t  Tickstart 
)
static

Master sends target device address followed by internal memory address for read request.

Parameters
hi2cPointer to a I2C_HandleTypeDef structure that contains the configuration information for the specified I2C.
DevAddressTarget device address: The device 7 bits address value in datasheet must be shifted to the left before calling the interface
MemAddressInternal memory address
MemAddSizeSize of internal memory address
TimeoutTimeout duration
TickstartTick start value
Return values
HALstatus

Definition at line 5176 of file stm32l4xx_hal_i2c.c.

5177 {
5178  I2C_TransferConfig(hi2c, DevAddress, (uint8_t)MemAddSize, I2C_SOFTEND_MODE, I2C_GENERATE_START_WRITE);
5179 
5180  /* Wait until TXIS flag is set */
5181  if (I2C_WaitOnTXISFlagUntilTimeout(hi2c, Timeout, Tickstart) != HAL_OK)
5182  {
5183  return HAL_ERROR;
5184  }
5185 
5186  /* If Memory address size is 8Bit */
5187  if (MemAddSize == I2C_MEMADD_SIZE_8BIT)
5188  {
5189  /* Send Memory Address */
5190  hi2c->Instance->TXDR = I2C_MEM_ADD_LSB(MemAddress);
5191  }
5192  /* If Memory address size is 16Bit */
5193  else
5194  {
5195  /* Send MSB of Memory Address */
5196  hi2c->Instance->TXDR = I2C_MEM_ADD_MSB(MemAddress);
5197 
5198  /* Wait until TXIS flag is set */
5199  if (I2C_WaitOnTXISFlagUntilTimeout(hi2c, Timeout, Tickstart) != HAL_OK)
5200  {
5201  return HAL_ERROR;
5202  }
5203 
5204  /* Send LSB of Memory Address */
5205  hi2c->Instance->TXDR = I2C_MEM_ADD_LSB(MemAddress);
5206  }
5207 
5208  /* Wait until TC flag is set */
5209  if (I2C_WaitOnFlagUntilTimeout(hi2c, I2C_FLAG_TC, RESET, Timeout, Tickstart) != HAL_OK)
5210  {
5211  return HAL_ERROR;
5212  }
5213 
5214  return HAL_OK;
5215 }
static HAL_StatusTypeDef I2C_WaitOnTXISFlagUntilTimeout(I2C_HandleTypeDef *hi2c, uint32_t Timeout, uint32_t Tickstart)
This function handles I2C Communication Timeout for specific usage of TXIS flag.
return HAL_OK
static void I2C_TransferConfig(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint8_t Size, uint32_t Mode, uint32_t Request)
Handles I2Cx communication when starting transfer or during transfer (TC or TCR flag are set)...
static HAL_StatusTypeDef I2C_WaitOnFlagUntilTimeout(I2C_HandleTypeDef *hi2c, uint32_t Flag, FlagStatus Status, uint32_t Timeout, uint32_t Tickstart)
This function handles I2C Communication Timeout.

◆ I2C_RequestMemoryWrite()

static HAL_StatusTypeDef I2C_RequestMemoryWrite ( I2C_HandleTypeDef hi2c,
uint16_t  DevAddress,
uint16_t  MemAddress,
uint16_t  MemAddSize,
uint32_t  Timeout,
uint32_t  Tickstart 
)
static

Master sends target device address followed by internal memory address for write request.

Parameters
hi2cPointer to a I2C_HandleTypeDef structure that contains the configuration information for the specified I2C.
DevAddressTarget device address: The device 7 bits address value in datasheet must be shifted to the left before calling the interface
MemAddressInternal memory address
MemAddSizeSize of internal memory address
TimeoutTimeout duration
TickstartTick start value
Return values
HALstatus

Definition at line 5123 of file stm32l4xx_hal_i2c.c.

5124 {
5125  I2C_TransferConfig(hi2c, DevAddress, (uint8_t)MemAddSize, I2C_RELOAD_MODE, I2C_GENERATE_START_WRITE);
5126 
5127  /* Wait until TXIS flag is set */
5128  if (I2C_WaitOnTXISFlagUntilTimeout(hi2c, Timeout, Tickstart) != HAL_OK)
5129  {
5130  return HAL_ERROR;
5131  }
5132 
5133  /* If Memory address size is 8Bit */
5134  if (MemAddSize == I2C_MEMADD_SIZE_8BIT)
5135  {
5136  /* Send Memory Address */
5137  hi2c->Instance->TXDR = I2C_MEM_ADD_LSB(MemAddress);
5138  }
5139  /* If Memory address size is 16Bit */
5140  else
5141  {
5142  /* Send MSB of Memory Address */
5143  hi2c->Instance->TXDR = I2C_MEM_ADD_MSB(MemAddress);
5144 
5145  /* Wait until TXIS flag is set */
5146  if (I2C_WaitOnTXISFlagUntilTimeout(hi2c, Timeout, Tickstart) != HAL_OK)
5147  {
5148  return HAL_ERROR;
5149  }
5150 
5151  /* Send LSB of Memory Address */
5152  hi2c->Instance->TXDR = I2C_MEM_ADD_LSB(MemAddress);
5153  }
5154 
5155  /* Wait until TCR flag is set */
5156  if (I2C_WaitOnFlagUntilTimeout(hi2c, I2C_FLAG_TCR, RESET, Timeout, Tickstart) != HAL_OK)
5157  {
5158  return HAL_ERROR;
5159  }
5160 
5161  return HAL_OK;
5162 }
static HAL_StatusTypeDef I2C_WaitOnTXISFlagUntilTimeout(I2C_HandleTypeDef *hi2c, uint32_t Timeout, uint32_t Tickstart)
This function handles I2C Communication Timeout for specific usage of TXIS flag.
return HAL_OK
static void I2C_TransferConfig(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint8_t Size, uint32_t Mode, uint32_t Request)
Handles I2Cx communication when starting transfer or during transfer (TC or TCR flag are set)...
static HAL_StatusTypeDef I2C_WaitOnFlagUntilTimeout(I2C_HandleTypeDef *hi2c, uint32_t Flag, FlagStatus Status, uint32_t Timeout, uint32_t Tickstart)
This function handles I2C Communication Timeout.

◆ I2C_Slave_ISR_DMA()

static HAL_StatusTypeDef I2C_Slave_ISR_DMA ( struct __I2C_HandleTypeDef hi2c,
uint32_t  ITFlags,
uint32_t  ITSources 
)
static

Interrupt Sub-Routine which handle the Interrupt Flags Slave Mode with DMA.

Parameters
hi2cPointer to a I2C_HandleTypeDef structure that contains the configuration information for the specified I2C.
ITFlagsInterrupt flags to handle.
ITSourcesInterrupt sources enabled.
Return values
HALstatus

Definition at line 5003 of file stm32l4xx_hal_i2c.c.

5004 {
5005  uint32_t tmpoptions = hi2c->XferOptions;
5006  uint32_t treatdmanack = 0U;
5007 
5008  /* Process locked */
5009  __HAL_LOCK(hi2c);
5010 
5011  if ((I2C_CHECK_FLAG(ITFlags, I2C_FLAG_AF) != RESET) && (I2C_CHECK_IT_SOURCE(ITSources, I2C_IT_NACKI) != RESET))
5012  {
5013  /* Check that I2C transfer finished */
5014  /* if yes, normal use case, a NACK is sent by the MASTER when Transfer is finished */
5015  /* Mean XferCount == 0 */
5016  /* So clear Flag NACKF only */
5017  if ((I2C_CHECK_IT_SOURCE(ITSources, I2C_CR1_TXDMAEN) != RESET) ||
5018  (I2C_CHECK_IT_SOURCE(ITSources, I2C_CR1_RXDMAEN) != RESET))
5019  {
5020  /* Split check of hdmarx, for MISRA compliance */
5021  if (hi2c->hdmarx != NULL)
5022  {
5023  if (I2C_CHECK_IT_SOURCE(ITSources, I2C_CR1_RXDMAEN) != RESET)
5024  {
5025  if (__HAL_DMA_GET_COUNTER(hi2c->hdmarx) == 0U)
5026  {
5027  treatdmanack = 1U;
5028  }
5029  }
5030  }
5031 
5032  /* Split check of hdmatx, for MISRA compliance */
5033  if (hi2c->hdmatx != NULL)
5034  {
5035  if (I2C_CHECK_IT_SOURCE(ITSources, I2C_CR1_TXDMAEN) != RESET)
5036  {
5037  if (__HAL_DMA_GET_COUNTER(hi2c->hdmatx) == 0U)
5038  {
5039  treatdmanack = 1U;
5040  }
5041  }
5042  }
5043 
5044  if (treatdmanack == 1U)
5045  {
5046  if ((hi2c->State == HAL_I2C_STATE_LISTEN) && (tmpoptions == I2C_FIRST_AND_LAST_FRAME)) /* Same action must be done for (tmpoptions == I2C_LAST_FRAME) which removed for Warning[Pa134]: left and right operands are identical */
5047  {
5048  /* Call I2C Listen complete process */
5049  I2C_ITListenCplt(hi2c, ITFlags);
5050  }
5051  else if ((hi2c->State == HAL_I2C_STATE_BUSY_TX_LISTEN) && (tmpoptions != I2C_NO_OPTION_FRAME))
5052  {
5053  /* Clear NACK Flag */
5054  __HAL_I2C_CLEAR_FLAG(hi2c, I2C_FLAG_AF);
5055 
5056  /* Flush TX register */
5057  I2C_Flush_TXDR(hi2c);
5058 
5059  /* Last Byte is Transmitted */
5060  /* Call I2C Slave Sequential complete process */
5061  I2C_ITSlaveSeqCplt(hi2c);
5062  }
5063  else
5064  {
5065  /* Clear NACK Flag */
5066  __HAL_I2C_CLEAR_FLAG(hi2c, I2C_FLAG_AF);
5067  }
5068  }
5069  else
5070  {
5071  /* if no, error use case, a Non-Acknowledge of last Data is generated by the MASTER*/
5072  /* Clear NACK Flag */
5073  __HAL_I2C_CLEAR_FLAG(hi2c, I2C_FLAG_AF);
5074 
5075  /* Set ErrorCode corresponding to a Non-Acknowledge */
5076  hi2c->ErrorCode |= HAL_I2C_ERROR_AF;
5077 
5078  if ((tmpoptions == I2C_FIRST_FRAME) || (tmpoptions == I2C_NEXT_FRAME))
5079  {
5080  /* Call the corresponding callback to inform upper layer of End of Transfer */
5081  I2C_ITError(hi2c, hi2c->ErrorCode);
5082  }
5083  }
5084  }
5085  else
5086  {
5087  /* Only Clear NACK Flag, no DMA treatment is pending */
5088  __HAL_I2C_CLEAR_FLAG(hi2c, I2C_FLAG_AF);
5089  }
5090  }
5091  else if ((I2C_CHECK_FLAG(ITFlags, I2C_FLAG_ADDR) != RESET) && (I2C_CHECK_IT_SOURCE(ITSources, I2C_IT_ADDRI) != RESET))
5092  {
5093  I2C_ITAddrCplt(hi2c, ITFlags);
5094  }
5095  else if ((I2C_CHECK_FLAG(ITFlags, I2C_FLAG_STOPF) != RESET) && (I2C_CHECK_IT_SOURCE(ITSources, I2C_IT_STOPI) != RESET))
5096  {
5097  /* Call I2C Slave complete process */
5098  I2C_ITSlaveCplt(hi2c, ITFlags);
5099  }
5100  else
5101  {
5102  /* Nothing to do */
5103  }
5104 
5105  /* Process Unlocked */
5106  __HAL_UNLOCK(hi2c);
5107 
5108  return HAL_OK;
5109 }
DMA_HandleTypeDef * hdmarx
static void I2C_ITError(I2C_HandleTypeDef *hi2c, uint32_t ErrorCode)
I2C interrupts error process.
static void I2C_ITSlaveSeqCplt(I2C_HandleTypeDef *hi2c)
I2C Slave sequential complete process.
static void I2C_ITSlaveCplt(I2C_HandleTypeDef *hi2c, uint32_t ITFlags)
I2C Slave complete process.
static void I2C_ITListenCplt(I2C_HandleTypeDef *hi2c, uint32_t ITFlags)
I2C Listen complete process.
__HAL_UNLOCK(hrtc)
__HAL_LOCK(hrtc)
static void I2C_Flush_TXDR(I2C_HandleTypeDef *hi2c)
I2C Tx data register flush process.
return HAL_OK
DMA_HandleTypeDef * hdmatx
static void I2C_ITAddrCplt(I2C_HandleTypeDef *hi2c, uint32_t ITFlags)
I2C Address complete process callback.
__IO HAL_I2C_StateTypeDef State
__IO uint32_t XferOptions

◆ I2C_Slave_ISR_IT()

static HAL_StatusTypeDef I2C_Slave_ISR_IT ( struct __I2C_HandleTypeDef hi2c,
uint32_t  ITFlags,
uint32_t  ITSources 
)
static

Interrupt Sub-Routine which handle the Interrupt Flags Slave Mode with Interrupt.

Parameters
hi2cPointer to a I2C_HandleTypeDef structure that contains the configuration information for the specified I2C.
ITFlagsInterrupt flags to handle.
ITSourcesInterrupt sources enabled.
Return values
HALstatus

Definition at line 4732 of file stm32l4xx_hal_i2c.c.

4733 {
4734  uint32_t tmpoptions = hi2c->XferOptions;
4735  uint32_t tmpITFlags = ITFlags;
4736 
4737  /* Process locked */
4738  __HAL_LOCK(hi2c);
4739 
4740  if ((I2C_CHECK_FLAG(tmpITFlags, I2C_FLAG_AF) != RESET) && (I2C_CHECK_IT_SOURCE(ITSources, I2C_IT_NACKI) != RESET))
4741  {
4742  /* Check that I2C transfer finished */
4743  /* if yes, normal use case, a NACK is sent by the MASTER when Transfer is finished */
4744  /* Mean XferCount == 0*/
4745  /* So clear Flag NACKF only */
4746  if (hi2c->XferCount == 0U)
4747  {
4748  if ((hi2c->State == HAL_I2C_STATE_LISTEN) && (tmpoptions == I2C_FIRST_AND_LAST_FRAME)) /* Same action must be done for (tmpoptions == I2C_LAST_FRAME) which removed for Warning[Pa134]: left and right operands are identical */
4749  {
4750  /* Call I2C Listen complete process */
4751  I2C_ITListenCplt(hi2c, tmpITFlags);
4752  }
4753  else if ((hi2c->State == HAL_I2C_STATE_BUSY_TX_LISTEN) && (tmpoptions != I2C_NO_OPTION_FRAME))
4754  {
4755  /* Clear NACK Flag */
4756  __HAL_I2C_CLEAR_FLAG(hi2c, I2C_FLAG_AF);
4757 
4758  /* Flush TX register */
4759  I2C_Flush_TXDR(hi2c);
4760 
4761  /* Last Byte is Transmitted */
4762  /* Call I2C Slave Sequential complete process */
4763  I2C_ITSlaveSeqCplt(hi2c);
4764  }
4765  else
4766  {
4767  /* Clear NACK Flag */
4768  __HAL_I2C_CLEAR_FLAG(hi2c, I2C_FLAG_AF);
4769  }
4770  }
4771  else
4772  {
4773  /* if no, error use case, a Non-Acknowledge of last Data is generated by the MASTER*/
4774  /* Clear NACK Flag */
4775  __HAL_I2C_CLEAR_FLAG(hi2c, I2C_FLAG_AF);
4776 
4777  /* Set ErrorCode corresponding to a Non-Acknowledge */
4778  hi2c->ErrorCode |= HAL_I2C_ERROR_AF;
4779 
4780  if ((tmpoptions == I2C_FIRST_FRAME) || (tmpoptions == I2C_NEXT_FRAME))
4781  {
4782  /* Call the corresponding callback to inform upper layer of End of Transfer */
4783  I2C_ITError(hi2c, hi2c->ErrorCode);
4784  }
4785  }
4786  }
4787  else if ((I2C_CHECK_FLAG(tmpITFlags, I2C_FLAG_RXNE) != RESET) && (I2C_CHECK_IT_SOURCE(ITSources, I2C_IT_RXI) != RESET))
4788  {
4789  if (hi2c->XferCount > 0U)
4790  {
4791  /* Remove RXNE flag on temporary variable as read done */
4792  tmpITFlags &= ~I2C_FLAG_RXNE;
4793 
4794  /* Read data from RXDR */
4795  *hi2c->pBuffPtr = (uint8_t)hi2c->Instance->RXDR;
4796 
4797  /* Increment Buffer pointer */
4798  hi2c->pBuffPtr++;
4799 
4800  hi2c->XferSize--;
4801  hi2c->XferCount--;
4802  }
4803 
4804  if ((hi2c->XferCount == 0U) && \
4805  (tmpoptions != I2C_NO_OPTION_FRAME))
4806  {
4807  /* Call I2C Slave Sequential complete process */
4808  I2C_ITSlaveSeqCplt(hi2c);
4809  }
4810  }
4811  else if ((I2C_CHECK_FLAG(tmpITFlags, I2C_FLAG_ADDR) != RESET) && (I2C_CHECK_IT_SOURCE(ITSources, I2C_IT_ADDRI) != RESET))
4812  {
4813  I2C_ITAddrCplt(hi2c, tmpITFlags);
4814  }
4815  else if ((I2C_CHECK_FLAG(tmpITFlags, I2C_FLAG_TXIS) != RESET) && (I2C_CHECK_IT_SOURCE(ITSources, I2C_IT_TXI) != RESET))
4816  {
4817  /* Write data to TXDR only if XferCount not reach "0" */
4818  /* A TXIS flag can be set, during STOP treatment */
4819  /* Check if all Datas have already been sent */
4820  /* If it is the case, this last write in TXDR is not sent, correspond to a dummy TXIS event */
4821  if (hi2c->XferCount > 0U)
4822  {
4823  /* Write data to TXDR */
4824  hi2c->Instance->TXDR = *hi2c->pBuffPtr;
4825 
4826  /* Increment Buffer pointer */
4827  hi2c->pBuffPtr++;
4828 
4829  hi2c->XferCount--;
4830  hi2c->XferSize--;
4831  }
4832  else
4833  {
4834  if ((tmpoptions == I2C_NEXT_FRAME) || (tmpoptions == I2C_FIRST_FRAME))
4835  {
4836  /* Last Byte is Transmitted */
4837  /* Call I2C Slave Sequential complete process */
4838  I2C_ITSlaveSeqCplt(hi2c);
4839  }
4840  }
4841  }
4842  else
4843  {
4844  /* Nothing to do */
4845  }
4846 
4847  /* Check if STOPF is set */
4848  if ((I2C_CHECK_FLAG(tmpITFlags, I2C_FLAG_STOPF) != RESET) && (I2C_CHECK_IT_SOURCE(ITSources, I2C_IT_STOPI) != RESET))
4849  {
4850  /* Call I2C Slave complete process */
4851  I2C_ITSlaveCplt(hi2c, tmpITFlags);
4852  }
4853 
4854  /* Process Unlocked */
4855  __HAL_UNLOCK(hi2c);
4856 
4857  return HAL_OK;
4858 }
static void I2C_ITError(I2C_HandleTypeDef *hi2c, uint32_t ErrorCode)
I2C interrupts error process.
static void I2C_ITSlaveSeqCplt(I2C_HandleTypeDef *hi2c)
I2C Slave sequential complete process.
static void I2C_ITSlaveCplt(I2C_HandleTypeDef *hi2c, uint32_t ITFlags)
I2C Slave complete process.
static void I2C_ITListenCplt(I2C_HandleTypeDef *hi2c, uint32_t ITFlags)
I2C Listen complete process.
__HAL_UNLOCK(hrtc)
__HAL_LOCK(hrtc)
static void I2C_Flush_TXDR(I2C_HandleTypeDef *hi2c)
I2C Tx data register flush process.
return HAL_OK
static void I2C_ITAddrCplt(I2C_HandleTypeDef *hi2c, uint32_t ITFlags)
I2C Address complete process callback.
__IO HAL_I2C_StateTypeDef State
__IO uint32_t XferOptions

◆ I2C_TransferConfig()

static void I2C_TransferConfig ( I2C_HandleTypeDef hi2c,
uint16_t  DevAddress,
uint8_t  Size,
uint32_t  Mode,
uint32_t  Request 
)
static

Handles I2Cx communication when starting transfer or during transfer (TC or TCR flag are set).

Parameters
hi2cI2C handle.
DevAddressSpecifies the slave address to be programmed.
SizeSpecifies the number of bytes to be programmed. This parameter must be a value between 0 and 255.
ModeNew state of the I2C START condition generation. This parameter can be one of the following values:
  • I2C_RELOAD_MODE Enable Reload mode .
  • I2C_AUTOEND_MODE Enable Automatic end mode.
  • I2C_SOFTEND_MODE Enable Software end mode.
RequestNew state of the I2C START condition generation. This parameter can be one of the following values:
  • I2C_NO_STARTSTOP Don't Generate stop and start condition.
  • I2C_GENERATE_STOP Generate stop condition (Size should be set to 0).
  • I2C_GENERATE_START_READ Generate Restart for read request.
  • I2C_GENERATE_START_WRITE Generate Restart for write request.
Return values
None

Definition at line 6313 of file stm32l4xx_hal_i2c.c.

6314 {
6315  /* Check the parameters */
6316  assert_param(IS_I2C_ALL_INSTANCE(hi2c->Instance));
6317  assert_param(IS_TRANSFER_MODE(Mode));
6318  assert_param(IS_TRANSFER_REQUEST(Request));
6319 
6320  /* update CR2 register */
6321  MODIFY_REG(hi2c->Instance->CR2, ((I2C_CR2_SADD | I2C_CR2_NBYTES | I2C_CR2_RELOAD | I2C_CR2_AUTOEND | (I2C_CR2_RD_WRN & (uint32_t)(Request >> (31U - I2C_CR2_RD_WRN_Pos))) | I2C_CR2_START | I2C_CR2_STOP)), \
6322  (uint32_t)(((uint32_t)DevAddress & I2C_CR2_SADD) | (((uint32_t)Size << I2C_CR2_NBYTES_Pos) & I2C_CR2_NBYTES) | (uint32_t)Mode | (uint32_t)Request));
6323 }
MODIFY_REG(hrtc->Instance->CR, RTC_CR_WUCKSEL,(uint32_t) WakeUpClock)
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))

◆ I2C_WaitOnFlagUntilTimeout()

static HAL_StatusTypeDef I2C_WaitOnFlagUntilTimeout ( I2C_HandleTypeDef hi2c,
uint32_t  Flag,
FlagStatus  Status,
uint32_t  Timeout,
uint32_t  Tickstart 
)
static

This function handles I2C Communication Timeout.

Parameters
hi2cPointer to a I2C_HandleTypeDef structure that contains the configuration information for the specified I2C.
FlagSpecifies the I2C flag to check.
StatusThe new Flag status (SET or RESET).
TimeoutTimeout duration
TickstartTick start value
Return values
HALstatus

Definition at line 6081 of file stm32l4xx_hal_i2c.c.

6082 {
6083  while (__HAL_I2C_GET_FLAG(hi2c, Flag) == Status)
6084  {
6085  /* Check for the Timeout */
6086  if (Timeout != HAL_MAX_DELAY)
6087  {
6088  if (((HAL_GetTick() - Tickstart) > Timeout) || (Timeout == 0U))
6089  {
6090  hi2c->ErrorCode |= HAL_I2C_ERROR_TIMEOUT;
6091  hi2c->State = HAL_I2C_STATE_READY;
6092  hi2c->Mode = HAL_I2C_MODE_NONE;
6093 
6094  /* Process Unlocked */
6095  __HAL_UNLOCK(hi2c);
6096  return HAL_ERROR;
6097  }
6098  }
6099  }
6100  return HAL_OK;
6101 }
uint32_t HAL_GetTick(void)
Provide a tick value in millisecond.
__HAL_UNLOCK(hrtc)
return HAL_OK
__IO HAL_I2C_ModeTypeDef Mode
__IO HAL_I2C_StateTypeDef State

◆ I2C_WaitOnRXNEFlagUntilTimeout()

static HAL_StatusTypeDef I2C_WaitOnRXNEFlagUntilTimeout ( I2C_HandleTypeDef hi2c,
uint32_t  Timeout,
uint32_t  Tickstart 
)
static

This function handles I2C Communication Timeout for specific usage of RXNE flag.

Parameters
hi2cPointer to a I2C_HandleTypeDef structure that contains the configuration information for the specified I2C.
TimeoutTimeout duration
TickstartTick start value
Return values
HALstatus

Definition at line 6182 of file stm32l4xx_hal_i2c.c.

6183 {
6184  while (__HAL_I2C_GET_FLAG(hi2c, I2C_FLAG_RXNE) == RESET)
6185  {
6186  /* Check if a NACK is detected */
6187  if (I2C_IsAcknowledgeFailed(hi2c, Timeout, Tickstart) != HAL_OK)
6188  {
6189  return HAL_ERROR;
6190  }
6191 
6192  /* Check if a STOPF is detected */
6193  if (__HAL_I2C_GET_FLAG(hi2c, I2C_FLAG_STOPF) == SET)
6194  {
6195  /* Check if an RXNE is pending */
6196  /* Store Last receive data if any */
6197  if ((__HAL_I2C_GET_FLAG(hi2c, I2C_FLAG_RXNE) == SET) && (hi2c->XferSize > 0U))
6198  {
6199  /* Return HAL_OK */
6200  /* The Reading of data from RXDR will be done in caller function */
6201  return HAL_OK;
6202  }
6203  else
6204  {
6205  /* Clear STOP Flag */
6206  __HAL_I2C_CLEAR_FLAG(hi2c, I2C_FLAG_STOPF);
6207 
6208  /* Clear Configuration Register 2 */
6209  I2C_RESET_CR2(hi2c);
6210 
6211  hi2c->ErrorCode = HAL_I2C_ERROR_NONE;
6212  hi2c->State = HAL_I2C_STATE_READY;
6213  hi2c->Mode = HAL_I2C_MODE_NONE;
6214 
6215  /* Process Unlocked */
6216  __HAL_UNLOCK(hi2c);
6217 
6218  return HAL_ERROR;
6219  }
6220  }
6221 
6222  /* Check for the Timeout */
6223  if (((HAL_GetTick() - Tickstart) > Timeout) || (Timeout == 0U))
6224  {
6225  hi2c->ErrorCode |= HAL_I2C_ERROR_TIMEOUT;
6226  hi2c->State = HAL_I2C_STATE_READY;
6227 
6228  /* Process Unlocked */
6229  __HAL_UNLOCK(hi2c);
6230 
6231  return HAL_ERROR;
6232  }
6233  }
6234  return HAL_OK;
6235 }
uint32_t HAL_GetTick(void)
Provide a tick value in millisecond.
__HAL_UNLOCK(hrtc)
return HAL_OK
__IO HAL_I2C_ModeTypeDef Mode
__IO HAL_I2C_StateTypeDef State
static HAL_StatusTypeDef I2C_IsAcknowledgeFailed(I2C_HandleTypeDef *hi2c, uint32_t Timeout, uint32_t Tickstart)
This function handles Acknowledge failed detection during an I2C Communication.

◆ I2C_WaitOnSTOPFlagUntilTimeout()

static HAL_StatusTypeDef I2C_WaitOnSTOPFlagUntilTimeout ( I2C_HandleTypeDef hi2c,
uint32_t  Timeout,
uint32_t  Tickstart 
)
static

This function handles I2C Communication Timeout for specific usage of STOP flag.

Parameters
hi2cPointer to a I2C_HandleTypeDef structure that contains the configuration information for the specified I2C.
TimeoutTimeout duration
TickstartTick start value
Return values
HALstatus

Definition at line 6148 of file stm32l4xx_hal_i2c.c.

6149 {
6150  while (__HAL_I2C_GET_FLAG(hi2c, I2C_FLAG_STOPF) == RESET)
6151  {
6152  /* Check if a NACK is detected */
6153  if (I2C_IsAcknowledgeFailed(hi2c, Timeout, Tickstart) != HAL_OK)
6154  {
6155  return HAL_ERROR;
6156  }
6157 
6158  /* Check for the Timeout */
6159  if (((HAL_GetTick() - Tickstart) > Timeout) || (Timeout == 0U))
6160  {
6161  hi2c->ErrorCode |= HAL_I2C_ERROR_TIMEOUT;
6162  hi2c->State = HAL_I2C_STATE_READY;
6163  hi2c->Mode = HAL_I2C_MODE_NONE;
6164 
6165  /* Process Unlocked */
6166  __HAL_UNLOCK(hi2c);
6167 
6168  return HAL_ERROR;
6169  }
6170  }
6171  return HAL_OK;
6172 }
uint32_t HAL_GetTick(void)
Provide a tick value in millisecond.
__HAL_UNLOCK(hrtc)
return HAL_OK
__IO HAL_I2C_ModeTypeDef Mode
__IO HAL_I2C_StateTypeDef State
static HAL_StatusTypeDef I2C_IsAcknowledgeFailed(I2C_HandleTypeDef *hi2c, uint32_t Timeout, uint32_t Tickstart)
This function handles Acknowledge failed detection during an I2C Communication.

◆ I2C_WaitOnTXISFlagUntilTimeout()

static HAL_StatusTypeDef I2C_WaitOnTXISFlagUntilTimeout ( I2C_HandleTypeDef hi2c,
uint32_t  Timeout,
uint32_t  Tickstart 
)
static

This function handles I2C Communication Timeout for specific usage of TXIS flag.

Parameters
hi2cPointer to a I2C_HandleTypeDef structure that contains the configuration information for the specified I2C.
TimeoutTimeout duration
TickstartTick start value
Return values
HALstatus

Definition at line 6111 of file stm32l4xx_hal_i2c.c.

6112 {
6113  while (__HAL_I2C_GET_FLAG(hi2c, I2C_FLAG_TXIS) == RESET)
6114  {
6115  /* Check if a NACK is detected */
6116  if (I2C_IsAcknowledgeFailed(hi2c, Timeout, Tickstart) != HAL_OK)
6117  {
6118  return HAL_ERROR;
6119  }
6120 
6121  /* Check for the Timeout */
6122  if (Timeout != HAL_MAX_DELAY)
6123  {
6124  if (((HAL_GetTick() - Tickstart) > Timeout) || (Timeout == 0U))
6125  {
6126  hi2c->ErrorCode |= HAL_I2C_ERROR_TIMEOUT;
6127  hi2c->State = HAL_I2C_STATE_READY;
6128  hi2c->Mode = HAL_I2C_MODE_NONE;
6129 
6130  /* Process Unlocked */
6131  __HAL_UNLOCK(hi2c);
6132 
6133  return HAL_ERROR;
6134  }
6135  }
6136  }
6137  return HAL_OK;
6138 }
uint32_t HAL_GetTick(void)
Provide a tick value in millisecond.
__HAL_UNLOCK(hrtc)
return HAL_OK
__IO HAL_I2C_ModeTypeDef Mode
__IO HAL_I2C_StateTypeDef State
static HAL_StatusTypeDef I2C_IsAcknowledgeFailed(I2C_HandleTypeDef *hi2c, uint32_t Timeout, uint32_t Tickstart)
This function handles Acknowledge failed detection during an I2C Communication.