STM32L4xx_HAL_Driver  1.14.0
Input and Output operation functions

Data transfers functions. More...

Modules

 Blocking mode Polling
 
 Non-Blocking mode Interrupt
 
 IRQ Handler and Callbacks
 
 Peripheral State and Errors functions
 Peripheral State and Errors functions.
 

Functions

HAL_StatusTypeDef HAL_SMBUS_Master_Transmit_IT (SMBUS_HandleTypeDef *hsmbus, uint16_t DevAddress, uint8_t *pData, uint16_t Size, uint32_t XferOptions)
 Transmit in master/host SMBUS mode an amount of data in non-blocking mode with Interrupt. More...
 
HAL_StatusTypeDef HAL_SMBUS_Master_Receive_IT (SMBUS_HandleTypeDef *hsmbus, uint16_t DevAddress, uint8_t *pData, uint16_t Size, uint32_t XferOptions)
 Receive in master/host SMBUS mode an amount of data in non-blocking mode with Interrupt. More...
 
HAL_StatusTypeDef HAL_SMBUS_Master_Abort_IT (SMBUS_HandleTypeDef *hsmbus, uint16_t DevAddress)
 Abort a master/host SMBUS process communication with Interrupt. More...
 
HAL_StatusTypeDef HAL_SMBUS_Slave_Transmit_IT (SMBUS_HandleTypeDef *hsmbus, uint8_t *pData, uint16_t Size, uint32_t XferOptions)
 Transmit in slave/device SMBUS mode an amount of data in non-blocking mode with Interrupt. More...
 
HAL_StatusTypeDef HAL_SMBUS_Slave_Receive_IT (SMBUS_HandleTypeDef *hsmbus, uint8_t *pData, uint16_t Size, uint32_t XferOptions)
 Receive in slave/device SMBUS mode an amount of data in non-blocking mode with Interrupt. More...
 
HAL_StatusTypeDef HAL_SMBUS_EnableListen_IT (SMBUS_HandleTypeDef *hsmbus)
 Enable the Address listen mode with Interrupt. More...
 
HAL_StatusTypeDef HAL_SMBUS_DisableListen_IT (SMBUS_HandleTypeDef *hsmbus)
 Disable the Address listen mode with Interrupt. More...
 
HAL_StatusTypeDef HAL_SMBUS_EnableAlert_IT (SMBUS_HandleTypeDef *hsmbus)
 Enable the SMBUS alert mode with Interrupt. More...
 
HAL_StatusTypeDef HAL_SMBUS_DisableAlert_IT (SMBUS_HandleTypeDef *hsmbus)
 Disable the SMBUS alert mode with Interrupt. More...
 
HAL_StatusTypeDef HAL_SMBUS_IsDeviceReady (SMBUS_HandleTypeDef *hsmbus, uint16_t DevAddress, uint32_t Trials, uint32_t Timeout)
 Check if target device is ready for communication. More...
 

Detailed Description

Data transfers functions.

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

    (#) Blocking mode function to check if device is ready for usage is :
        (++) HAL_SMBUS_IsDeviceReady()

    (#) There is only one mode of transfer:
       (++) Non-Blocking mode : The communication is performed using Interrupts.
            These functions return the status of the transfer startup.
            The end of the data processing will be indicated through the
            dedicated SMBUS IRQ when using Interrupt mode.

    (#) Non-Blocking mode functions with Interrupt are :
        (++) HAL_SMBUS_Master_Transmit_IT()
        (++) HAL_SMBUS_Master_Receive_IT()
        (++) HAL_SMBUS_Slave_Transmit_IT()
        (++) HAL_SMBUS_Slave_Receive_IT()
        (++) HAL_SMBUS_EnableListen_IT() or alias HAL_SMBUS_EnableListen_IT()
        (++) HAL_SMBUS_DisableListen_IT()
        (++) HAL_SMBUS_EnableAlert_IT()
        (++) HAL_SMBUS_DisableAlert_IT()

    (#) A set of Transfer Complete Callbacks are provided in non-Blocking mode:
        (++) HAL_SMBUS_MasterTxCpltCallback()
        (++) HAL_SMBUS_MasterRxCpltCallback()
        (++) HAL_SMBUS_SlaveTxCpltCallback()
        (++) HAL_SMBUS_SlaveRxCpltCallback()
        (++) HAL_SMBUS_AddrCallback()
        (++) HAL_SMBUS_ListenCpltCallback()
        (++) HAL_SMBUS_ErrorCallback()

Function Documentation

◆ HAL_SMBUS_DisableAlert_IT()

HAL_StatusTypeDef HAL_SMBUS_DisableAlert_IT ( SMBUS_HandleTypeDef hsmbus)

Disable the SMBUS alert mode with Interrupt.

Parameters
hsmbusPointer to a SMBUS_HandleTypeDef structure that contains the configuration information for the specified SMBUSx peripheral.
Return values
HALstatus

Definition at line 1399 of file stm32l4xx_hal_smbus.c.

1400 {
1401  /* Enable SMBus alert */
1402  hsmbus->Instance->CR1 &= ~I2C_CR1_ALERTEN;
1403 
1404  /* Disable Alert Interrupt */
1405  SMBUS_Disable_IRQ(hsmbus, SMBUS_IT_ALERT);
1406 
1407  return HAL_OK;
1408 }
return HAL_OK
static void SMBUS_Disable_IRQ(struct __SMBUS_HandleTypeDef *hsmbus, uint32_t InterruptRequest)
Manage the disabling of Interrupts.

◆ HAL_SMBUS_DisableListen_IT()

HAL_StatusTypeDef HAL_SMBUS_DisableListen_IT ( SMBUS_HandleTypeDef hsmbus)

Disable the Address listen mode with Interrupt.

Parameters
hsmbusPointer to a SMBUS_HandleTypeDef structure that contains the configuration information for the specified SMBUS.
Return values
HALstatus

Definition at line 1356 of file stm32l4xx_hal_smbus.c.

1357 {
1358  /* Disable Address listen mode only if a transfer is not ongoing */
1359  if (hsmbus->State == HAL_SMBUS_STATE_LISTEN)
1360  {
1361  hsmbus->State = HAL_SMBUS_STATE_READY;
1362 
1363  /* Disable the Address Match interrupt */
1364  SMBUS_Disable_IRQ(hsmbus, SMBUS_IT_ADDR);
1365 
1366  return HAL_OK;
1367  }
1368  else
1369  {
1370  return HAL_BUSY;
1371  }
1372 }
return HAL_OK
static void SMBUS_Disable_IRQ(struct __SMBUS_HandleTypeDef *hsmbus, uint32_t InterruptRequest)
Manage the disabling of Interrupts.

◆ HAL_SMBUS_EnableAlert_IT()

HAL_StatusTypeDef HAL_SMBUS_EnableAlert_IT ( SMBUS_HandleTypeDef hsmbus)

Enable the SMBUS alert mode with Interrupt.

Parameters
hsmbusPointer to a SMBUS_HandleTypeDef structure that contains the configuration information for the specified SMBUSx peripheral.
Return values
HALstatus

Definition at line 1380 of file stm32l4xx_hal_smbus.c.

1381 {
1382  /* Enable SMBus alert */
1383  hsmbus->Instance->CR1 |= I2C_CR1_ALERTEN;
1384 
1385  /* Clear ALERT flag */
1386  __HAL_SMBUS_CLEAR_FLAG(hsmbus, SMBUS_FLAG_ALERT);
1387 
1388  /* Enable Alert Interrupt */
1389  SMBUS_Enable_IRQ(hsmbus, SMBUS_IT_ALERT);
1390 
1391  return HAL_OK;
1392 }
return HAL_OK
static void SMBUS_Enable_IRQ(struct __SMBUS_HandleTypeDef *hsmbus, uint32_t InterruptRequest)
Manage the enabling of Interrupts.

◆ HAL_SMBUS_EnableListen_IT()

HAL_StatusTypeDef HAL_SMBUS_EnableListen_IT ( SMBUS_HandleTypeDef hsmbus)

Enable the Address listen mode with Interrupt.

Parameters
hsmbusPointer to a SMBUS_HandleTypeDef structure that contains the configuration information for the specified SMBUS.
Return values
HALstatus

Definition at line 1340 of file stm32l4xx_hal_smbus.c.

1341 {
1342  hsmbus->State = HAL_SMBUS_STATE_LISTEN;
1343 
1344  /* Enable the Address Match interrupt */
1345  SMBUS_Enable_IRQ(hsmbus, SMBUS_IT_ADDR);
1346 
1347  return HAL_OK;
1348 }
return HAL_OK
static void SMBUS_Enable_IRQ(struct __SMBUS_HandleTypeDef *hsmbus, uint32_t InterruptRequest)
Manage the enabling of Interrupts.

◆ HAL_SMBUS_IsDeviceReady()

HAL_StatusTypeDef HAL_SMBUS_IsDeviceReady ( SMBUS_HandleTypeDef hsmbus,
uint16_t  DevAddress,
uint32_t  Trials,
uint32_t  Timeout 
)

Check if target device is ready for communication.

Parameters
hsmbusPointer to a SMBUS_HandleTypeDef structure that contains the configuration information for the specified SMBUS.
DevAddressTarget device address: The device 7 bits address value in datasheet must be shifted to the left before calling the interface
TrialsNumber of trials
TimeoutTimeout duration
Return values
HALstatus

Definition at line 1420 of file stm32l4xx_hal_smbus.c.

1421 {
1422  uint32_t tickstart;
1423 
1424  __IO uint32_t SMBUS_Trials = 0UL;
1425 
1426  FlagStatus tmp1;
1427  FlagStatus tmp2;
1428 
1429  if (hsmbus->State == HAL_SMBUS_STATE_READY)
1430  {
1431  if (__HAL_SMBUS_GET_FLAG(hsmbus, SMBUS_FLAG_BUSY) != RESET)
1432  {
1433  return HAL_BUSY;
1434  }
1435 
1436  /* Process Locked */
1437  __HAL_LOCK(hsmbus);
1438 
1439  hsmbus->State = HAL_SMBUS_STATE_BUSY;
1440  hsmbus->ErrorCode = HAL_SMBUS_ERROR_NONE;
1441 
1442  do
1443  {
1444  /* Generate Start */
1445  hsmbus->Instance->CR2 = SMBUS_GENERATE_START(hsmbus->Init.AddressingMode, DevAddress);
1446 
1447  /* No need to Check TC flag, with AUTOEND mode the stop is automatically generated */
1448  /* Wait until STOPF flag is set or a NACK flag is set*/
1449  tickstart = HAL_GetTick();
1450 
1451  tmp1 = __HAL_SMBUS_GET_FLAG(hsmbus, SMBUS_FLAG_STOPF);
1452  tmp2 = __HAL_SMBUS_GET_FLAG(hsmbus, SMBUS_FLAG_AF);
1453 
1454  while ((tmp1 == RESET) && (tmp2 == RESET))
1455  {
1456  if (Timeout != HAL_MAX_DELAY)
1457  {
1458  if (((HAL_GetTick() - tickstart) > Timeout) || (Timeout == 0UL))
1459  {
1460  /* Device is ready */
1461  hsmbus->State = HAL_SMBUS_STATE_READY;
1462 
1463  /* Update SMBUS error code */
1464  hsmbus->ErrorCode |= HAL_SMBUS_ERROR_HALTIMEOUT;
1465 
1466  /* Process Unlocked */
1467  __HAL_UNLOCK(hsmbus);
1468  return HAL_ERROR;
1469  }
1470  }
1471 
1472  tmp1 = __HAL_SMBUS_GET_FLAG(hsmbus, SMBUS_FLAG_STOPF);
1473  tmp2 = __HAL_SMBUS_GET_FLAG(hsmbus, SMBUS_FLAG_AF);
1474  }
1475 
1476  /* Check if the NACKF flag has not been set */
1477  if (__HAL_SMBUS_GET_FLAG(hsmbus, SMBUS_FLAG_AF) == RESET)
1478  {
1479  /* Wait until STOPF flag is reset */
1480  if (SMBUS_WaitOnFlagUntilTimeout(hsmbus, SMBUS_FLAG_STOPF, RESET, Timeout) != HAL_OK)
1481  {
1482  return HAL_ERROR;
1483  }
1484 
1485  /* Clear STOP Flag */
1486  __HAL_SMBUS_CLEAR_FLAG(hsmbus, SMBUS_FLAG_STOPF);
1487 
1488  /* Device is ready */
1489  hsmbus->State = HAL_SMBUS_STATE_READY;
1490 
1491  /* Process Unlocked */
1492  __HAL_UNLOCK(hsmbus);
1493 
1494  return HAL_OK;
1495  }
1496  else
1497  {
1498  /* Wait until STOPF flag is reset */
1499  if (SMBUS_WaitOnFlagUntilTimeout(hsmbus, SMBUS_FLAG_STOPF, RESET, Timeout) != HAL_OK)
1500  {
1501  return HAL_ERROR;
1502  }
1503 
1504  /* Clear NACK Flag */
1505  __HAL_SMBUS_CLEAR_FLAG(hsmbus, SMBUS_FLAG_AF);
1506 
1507  /* Clear STOP Flag, auto generated with autoend*/
1508  __HAL_SMBUS_CLEAR_FLAG(hsmbus, SMBUS_FLAG_STOPF);
1509  }
1510 
1511  /* Check if the maximum allowed number of trials has been reached */
1512  if (SMBUS_Trials == Trials)
1513  {
1514  /* Generate Stop */
1515  hsmbus->Instance->CR2 |= I2C_CR2_STOP;
1516 
1517  /* Wait until STOPF flag is reset */
1518  if (SMBUS_WaitOnFlagUntilTimeout(hsmbus, SMBUS_FLAG_STOPF, RESET, Timeout) != HAL_OK)
1519  {
1520  return HAL_ERROR;
1521  }
1522 
1523  /* Clear STOP Flag */
1524  __HAL_SMBUS_CLEAR_FLAG(hsmbus, SMBUS_FLAG_STOPF);
1525  }
1526 
1527  /* Increment Trials */
1528  SMBUS_Trials++;
1529  }
1530  while (SMBUS_Trials < Trials);
1531 
1532  hsmbus->State = HAL_SMBUS_STATE_READY;
1533 
1534  /* Update SMBUS error code */
1535  hsmbus->ErrorCode |= HAL_SMBUS_ERROR_HALTIMEOUT;
1536 
1537  /* Process Unlocked */
1538  __HAL_UNLOCK(hsmbus);
1539 
1540  return HAL_ERROR;
1541  }
1542  else
1543  {
1544  return HAL_BUSY;
1545  }
1546 }
uint32_t HAL_GetTick(void)
Provide a tick value in millisecond.
__HAL_UNLOCK(hrtc)
__HAL_LOCK(hrtc)
return HAL_OK
static HAL_StatusTypeDef SMBUS_WaitOnFlagUntilTimeout(struct __SMBUS_HandleTypeDef *hsmbus, uint32_t Flag, FlagStatus Status, uint32_t Timeout)
Handle SMBUS Communication Timeout.

◆ HAL_SMBUS_Master_Abort_IT()

HAL_StatusTypeDef HAL_SMBUS_Master_Abort_IT ( SMBUS_HandleTypeDef hsmbus,
uint16_t  DevAddress 
)

Abort a master/host SMBUS process communication with Interrupt.

Note
This abort can be called only if state is ready
Parameters
hsmbusPointer to a SMBUS_HandleTypeDef structure that contains the configuration information for the specified SMBUS.
DevAddressTarget device address: The device 7 bits address value in datasheet must be shifted to the left before calling the interface
Return values
HALstatus

Definition at line 1103 of file stm32l4xx_hal_smbus.c.

1104 {
1105  if (hsmbus->State == HAL_SMBUS_STATE_READY)
1106  {
1107  /* Process Locked */
1108  __HAL_LOCK(hsmbus);
1109 
1110  /* Keep the same state as previous */
1111  /* to perform as well the call of the corresponding end of transfer callback */
1112  if (hsmbus->PreviousState == HAL_SMBUS_STATE_MASTER_BUSY_TX)
1113  {
1114  hsmbus->State = HAL_SMBUS_STATE_MASTER_BUSY_TX;
1115  }
1116  else if (hsmbus->PreviousState == HAL_SMBUS_STATE_MASTER_BUSY_RX)
1117  {
1118  hsmbus->State = HAL_SMBUS_STATE_MASTER_BUSY_RX;
1119  }
1120  else
1121  {
1122  /* Wrong usage of abort function */
1123  /* This function should be used only in case of abort monitored by master device */
1124  return HAL_ERROR;
1125  }
1126  hsmbus->ErrorCode = HAL_SMBUS_ERROR_NONE;
1127 
1128  /* Set NBYTES to 1 to generate a dummy read on SMBUS peripheral */
1129  /* Set AUTOEND mode, this will generate a NACK then STOP condition to abort the current transfer */
1130  SMBUS_TransferConfig(hsmbus, DevAddress, 1, SMBUS_AUTOEND_MODE, SMBUS_NO_STARTSTOP);
1131 
1132  /* Process Unlocked */
1133  __HAL_UNLOCK(hsmbus);
1134 
1135  /* Note : The SMBUS interrupts must be enabled after unlocking current process
1136  to avoid the risk of SMBUS interrupt handle execution before current
1137  process unlock */
1138  if (hsmbus->State == HAL_SMBUS_STATE_MASTER_BUSY_TX)
1139  {
1140  SMBUS_Enable_IRQ(hsmbus, SMBUS_IT_TX);
1141  }
1142  else if (hsmbus->State == HAL_SMBUS_STATE_MASTER_BUSY_RX)
1143  {
1144  SMBUS_Enable_IRQ(hsmbus, SMBUS_IT_RX);
1145  }
1146  else
1147  {
1148  /* Nothing to do */
1149  }
1150 
1151  return HAL_OK;
1152  }
1153  else
1154  {
1155  return HAL_BUSY;
1156  }
1157 }
static void SMBUS_TransferConfig(struct __SMBUS_HandleTypeDef *hsmbus, uint16_t DevAddress, uint8_t Size, uint32_t Mode, uint32_t Request)
Handle SMBUSx communication when starting transfer or during transfer (TC or TCR flag are set)...
__HAL_UNLOCK(hrtc)
__HAL_LOCK(hrtc)
return HAL_OK
static void SMBUS_Enable_IRQ(struct __SMBUS_HandleTypeDef *hsmbus, uint32_t InterruptRequest)
Manage the enabling of Interrupts.

◆ HAL_SMBUS_Master_Receive_IT()

HAL_StatusTypeDef HAL_SMBUS_Master_Receive_IT ( SMBUS_HandleTypeDef hsmbus,
uint16_t  DevAddress,
uint8_t *  pData,
uint16_t  Size,
uint32_t  XferOptions 
)

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

Parameters
hsmbusPointer to a SMBUS_HandleTypeDef structure that contains the configuration information for the specified SMBUS.
DevAddressTarget device address: The device 7 bits address value in datasheet must be shifted to the left before calling the interface
pDataPointer to data buffer
SizeAmount of data to be sent
XferOptionsOptions of Transfer, value of SMBUS XferOptions definition
Return values
HALstatus

Definition at line 1013 of file stm32l4xx_hal_smbus.c.

1014 {
1015  uint32_t tmp;
1016 
1017  /* Check the parameters */
1018  assert_param(IS_SMBUS_TRANSFER_OPTIONS_REQUEST(XferOptions));
1019 
1020  if (hsmbus->State == HAL_SMBUS_STATE_READY)
1021  {
1022  /* Process Locked */
1023  __HAL_LOCK(hsmbus);
1024 
1025  hsmbus->State = HAL_SMBUS_STATE_MASTER_BUSY_RX;
1026  hsmbus->ErrorCode = HAL_SMBUS_ERROR_NONE;
1027 
1028  /* Prepare transfer parameters */
1029  hsmbus->pBuffPtr = pData;
1030  hsmbus->XferCount = Size;
1031  hsmbus->XferOptions = XferOptions;
1032 
1033  /* In case of Quick command, remove autoend mode */
1034  /* Manage the stop generation by software */
1035  if (hsmbus->pBuffPtr == NULL)
1036  {
1037  hsmbus->XferOptions &= ~SMBUS_AUTOEND_MODE;
1038  }
1039 
1040  if (Size > MAX_NBYTE_SIZE)
1041  {
1042  hsmbus->XferSize = MAX_NBYTE_SIZE;
1043  }
1044  else
1045  {
1046  hsmbus->XferSize = Size;
1047  }
1048 
1049  /* Send Slave Address */
1050  /* Set NBYTES to write and reload if size > MAX_NBYTE_SIZE and generate RESTART */
1051  if ((hsmbus->XferSize < hsmbus->XferCount) && (hsmbus->XferSize == MAX_NBYTE_SIZE))
1052  {
1053  SMBUS_TransferConfig(hsmbus, DevAddress, (uint8_t)hsmbus->XferSize, SMBUS_RELOAD_MODE | (hsmbus->XferOptions & SMBUS_SENDPEC_MODE), SMBUS_GENERATE_START_READ);
1054  }
1055  else
1056  {
1057  /* If transfer direction not change, do not generate Restart Condition */
1058  /* Mean Previous state is same as current state */
1059 
1060  /* Store current volatile XferOptions, Misra rule */
1061  tmp = hsmbus->XferOptions;
1062 
1063  if ((hsmbus->PreviousState == HAL_SMBUS_STATE_MASTER_BUSY_RX) && (IS_SMBUS_TRANSFER_OTHER_OPTIONS_REQUEST(tmp) == 0))
1064  {
1065  SMBUS_TransferConfig(hsmbus, DevAddress, (uint8_t)hsmbus->XferSize, hsmbus->XferOptions, SMBUS_NO_STARTSTOP);
1066  }
1067  /* Else transfer direction change, so generate Restart with new transfer direction */
1068  else
1069  {
1070  /* Convert OTHER_xxx XferOptions if any */
1072 
1073  /* Handle Transfer */
1074  SMBUS_TransferConfig(hsmbus, DevAddress, (uint8_t)hsmbus->XferSize, hsmbus->XferOptions, SMBUS_GENERATE_START_READ);
1075  }
1076  }
1077 
1078  /* Process Unlocked */
1079  __HAL_UNLOCK(hsmbus);
1080 
1081  /* Note : The SMBUS interrupts must be enabled after unlocking current process
1082  to avoid the risk of SMBUS interrupt handle execution before current
1083  process unlock */
1084  SMBUS_Enable_IRQ(hsmbus, SMBUS_IT_RX);
1085 
1086  return HAL_OK;
1087  }
1088  else
1089  {
1090  return HAL_BUSY;
1091  }
1092 }
static void SMBUS_TransferConfig(struct __SMBUS_HandleTypeDef *hsmbus, uint16_t DevAddress, uint8_t Size, uint32_t Mode, uint32_t Request)
Handle SMBUSx communication when starting transfer or during transfer (TC or TCR flag are set)...
__HAL_UNLOCK(hrtc)
__HAL_LOCK(hrtc)
return HAL_OK
static void SMBUS_Enable_IRQ(struct __SMBUS_HandleTypeDef *hsmbus, uint32_t InterruptRequest)
Manage the enabling of Interrupts.
static void SMBUS_ConvertOtherXferOptions(struct __SMBUS_HandleTypeDef *hsmbus)
Convert SMBUSx OTHER_xxx XferOptions to functionnal XferOptions.
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))

◆ HAL_SMBUS_Master_Transmit_IT()

HAL_StatusTypeDef HAL_SMBUS_Master_Transmit_IT ( SMBUS_HandleTypeDef hsmbus,
uint16_t  DevAddress,
uint8_t *  pData,
uint16_t  Size,
uint32_t  XferOptions 
)

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

Parameters
hsmbusPointer to a SMBUS_HandleTypeDef structure that contains the configuration information for the specified SMBUS.
DevAddressTarget device address: The device 7 bits address value in datasheet must be shifted to the left before calling the interface
pDataPointer to data buffer
SizeAmount of data to be sent
XferOptionsOptions of Transfer, value of SMBUS XferOptions definition
Return values
HALstatus

Definition at line 914 of file stm32l4xx_hal_smbus.c.

915 {
916  uint32_t tmp;
917 
918  /* Check the parameters */
919  assert_param(IS_SMBUS_TRANSFER_OPTIONS_REQUEST(XferOptions));
920 
921  if (hsmbus->State == HAL_SMBUS_STATE_READY)
922  {
923  /* Process Locked */
924  __HAL_LOCK(hsmbus);
925 
926  hsmbus->State = HAL_SMBUS_STATE_MASTER_BUSY_TX;
927  hsmbus->ErrorCode = HAL_SMBUS_ERROR_NONE;
928  /* Prepare transfer parameters */
929  hsmbus->pBuffPtr = pData;
930  hsmbus->XferCount = Size;
931  hsmbus->XferOptions = XferOptions;
932 
933  /* In case of Quick command, remove autoend mode */
934  /* Manage the stop generation by software */
935  if (hsmbus->pBuffPtr == NULL)
936  {
937  hsmbus->XferOptions &= ~SMBUS_AUTOEND_MODE;
938  }
939 
940  if (Size > MAX_NBYTE_SIZE)
941  {
942  hsmbus->XferSize = MAX_NBYTE_SIZE;
943  }
944  else
945  {
946  hsmbus->XferSize = Size;
947  }
948 
949  /* Send Slave Address */
950  /* Set NBYTES to write and reload if size > MAX_NBYTE_SIZE and generate RESTART */
951  if ((hsmbus->XferSize < hsmbus->XferCount) && (hsmbus->XferSize == MAX_NBYTE_SIZE))
952  {
953  SMBUS_TransferConfig(hsmbus, DevAddress, (uint8_t)hsmbus->XferSize, SMBUS_RELOAD_MODE | (hsmbus->XferOptions & SMBUS_SENDPEC_MODE), SMBUS_GENERATE_START_WRITE);
954  }
955  else
956  {
957  /* If transfer direction not change, do not generate Restart Condition */
958  /* Mean Previous state is same as current state */
959 
960  /* Store current volatile XferOptions, misra rule */
961  tmp = hsmbus->XferOptions;
962 
963  if ((hsmbus->PreviousState == HAL_SMBUS_STATE_MASTER_BUSY_TX) && (IS_SMBUS_TRANSFER_OTHER_OPTIONS_REQUEST(tmp) == 0))
964  {
965  SMBUS_TransferConfig(hsmbus, DevAddress, (uint8_t)hsmbus->XferSize, hsmbus->XferOptions, SMBUS_NO_STARTSTOP);
966  }
967  /* Else transfer direction change, so generate Restart with new transfer direction */
968  else
969  {
970  /* Convert OTHER_xxx XferOptions if any */
972 
973  /* Handle Transfer */
974  SMBUS_TransferConfig(hsmbus, DevAddress, (uint8_t)hsmbus->XferSize, hsmbus->XferOptions, SMBUS_GENERATE_START_WRITE);
975  }
976 
977  /* If PEC mode is enable, size to transmit manage by SW part should be Size-1 byte, corresponding to PEC byte */
978  /* PEC byte is automatically sent by HW block, no need to manage it in Transmit process */
979  if (SMBUS_GET_PEC_MODE(hsmbus) != 0UL)
980  {
981  hsmbus->XferSize--;
982  hsmbus->XferCount--;
983  }
984  }
985 
986  /* Process Unlocked */
987  __HAL_UNLOCK(hsmbus);
988 
989  /* Note : The SMBUS interrupts must be enabled after unlocking current process
990  to avoid the risk of SMBUS interrupt handle execution before current
991  process unlock */
992  SMBUS_Enable_IRQ(hsmbus, SMBUS_IT_TX);
993 
994  return HAL_OK;
995  }
996  else
997  {
998  return HAL_BUSY;
999  }
1000 }
static void SMBUS_TransferConfig(struct __SMBUS_HandleTypeDef *hsmbus, uint16_t DevAddress, uint8_t Size, uint32_t Mode, uint32_t Request)
Handle SMBUSx communication when starting transfer or during transfer (TC or TCR flag are set)...
__HAL_UNLOCK(hrtc)
__HAL_LOCK(hrtc)
return HAL_OK
static void SMBUS_Enable_IRQ(struct __SMBUS_HandleTypeDef *hsmbus, uint32_t InterruptRequest)
Manage the enabling of Interrupts.
static void SMBUS_ConvertOtherXferOptions(struct __SMBUS_HandleTypeDef *hsmbus)
Convert SMBUSx OTHER_xxx XferOptions to functionnal XferOptions.
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))

◆ HAL_SMBUS_Slave_Receive_IT()

HAL_StatusTypeDef HAL_SMBUS_Slave_Receive_IT ( SMBUS_HandleTypeDef hsmbus,
uint8_t *  pData,
uint16_t  Size,
uint32_t  XferOptions 
)

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

Parameters
hsmbusPointer to a SMBUS_HandleTypeDef structure that contains the configuration information for the specified SMBUS.
pDataPointer to data buffer
SizeAmount of data to be sent
XferOptionsOptions of Transfer, value of SMBUS XferOptions definition
Return values
HALstatus

Definition at line 1262 of file stm32l4xx_hal_smbus.c.

1263 {
1264  /* Check the parameters */
1265  assert_param(IS_SMBUS_TRANSFER_OPTIONS_REQUEST(XferOptions));
1266 
1267  if ((hsmbus->State & HAL_SMBUS_STATE_LISTEN) == HAL_SMBUS_STATE_LISTEN)
1268  {
1269  if ((pData == NULL) || (Size == 0UL))
1270  {
1271  hsmbus->ErrorCode = HAL_SMBUS_ERROR_INVALID_PARAM;
1272  return HAL_ERROR;
1273  }
1274 
1275  /* Disable Interrupts, to prevent preemption during treatment in case of multicall */
1276  SMBUS_Disable_IRQ(hsmbus, SMBUS_IT_ADDR | SMBUS_IT_RX);
1277 
1278  /* Process Locked */
1279  __HAL_LOCK(hsmbus);
1280 
1281  hsmbus->State = (HAL_SMBUS_STATE_SLAVE_BUSY_RX | HAL_SMBUS_STATE_LISTEN);
1282  hsmbus->ErrorCode = HAL_SMBUS_ERROR_NONE;
1283 
1284  /* Set SBC bit to manage Acknowledge at each bit */
1285  hsmbus->Instance->CR1 |= I2C_CR1_SBC;
1286 
1287  /* Enable Address Acknowledge */
1288  hsmbus->Instance->CR2 &= ~I2C_CR2_NACK;
1289 
1290  /* Prepare transfer parameters */
1291  hsmbus->pBuffPtr = pData;
1292  hsmbus->XferSize = Size;
1293  hsmbus->XferCount = Size;
1294  hsmbus->XferOptions = XferOptions;
1295 
1296  /* Convert OTHER_xxx XferOptions if any */
1298 
1299  /* Set NBYTE to receive */
1300  /* If XferSize equal "1", or XferSize equal "2" with PEC requested (mean 1 data byte + 1 PEC byte */
1301  /* no need to set RELOAD bit mode, a ACK will be automatically generated in that case */
1302  /* else need to set RELOAD bit mode to generate an automatic ACK at each byte Received */
1303  /* This RELOAD bit will be reset for last BYTE to be receive in SMBUS_Slave_ISR */
1304  if (((SMBUS_GET_PEC_MODE(hsmbus) != 0UL) && (hsmbus->XferSize == 2U)) || (hsmbus->XferSize == 1U))
1305  {
1306  SMBUS_TransferConfig(hsmbus, 0, (uint8_t)hsmbus->XferSize, hsmbus->XferOptions, SMBUS_NO_STARTSTOP);
1307  }
1308  else
1309  {
1310  SMBUS_TransferConfig(hsmbus, 0, 1, hsmbus->XferOptions | SMBUS_RELOAD_MODE, SMBUS_NO_STARTSTOP);
1311  }
1312 
1313  /* Clear ADDR flag after prepare the transfer parameters */
1314  /* This action will generate an acknowledge to the HOST */
1315  __HAL_SMBUS_CLEAR_FLAG(hsmbus, SMBUS_FLAG_ADDR);
1316 
1317  /* Process Unlocked */
1318  __HAL_UNLOCK(hsmbus);
1319 
1320  /* Note : The SMBUS interrupts must be enabled after unlocking current process
1321  to avoid the risk of SMBUS interrupt handle execution before current
1322  process unlock */
1323  /* REnable ADDR interrupt */
1324  SMBUS_Enable_IRQ(hsmbus, SMBUS_IT_RX | SMBUS_IT_ADDR);
1325 
1326  return HAL_OK;
1327  }
1328  else
1329  {
1330  return HAL_BUSY;
1331  }
1332 }
static void SMBUS_TransferConfig(struct __SMBUS_HandleTypeDef *hsmbus, uint16_t DevAddress, uint8_t Size, uint32_t Mode, uint32_t Request)
Handle SMBUSx communication when starting transfer or during transfer (TC or TCR flag are set)...
__HAL_UNLOCK(hrtc)
__HAL_LOCK(hrtc)
return HAL_OK
static void SMBUS_Enable_IRQ(struct __SMBUS_HandleTypeDef *hsmbus, uint32_t InterruptRequest)
Manage the enabling of Interrupts.
static void SMBUS_Disable_IRQ(struct __SMBUS_HandleTypeDef *hsmbus, uint32_t InterruptRequest)
Manage the disabling of Interrupts.
static void SMBUS_ConvertOtherXferOptions(struct __SMBUS_HandleTypeDef *hsmbus)
Convert SMBUSx OTHER_xxx XferOptions to functionnal XferOptions.
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))

◆ HAL_SMBUS_Slave_Transmit_IT()

HAL_StatusTypeDef HAL_SMBUS_Slave_Transmit_IT ( SMBUS_HandleTypeDef hsmbus,
uint8_t *  pData,
uint16_t  Size,
uint32_t  XferOptions 
)

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

Parameters
hsmbusPointer to a SMBUS_HandleTypeDef structure that contains the configuration information for the specified SMBUS.
pDataPointer to data buffer
SizeAmount of data to be sent
XferOptionsOptions of Transfer, value of SMBUS XferOptions definition
Return values
HALstatus

Definition at line 1168 of file stm32l4xx_hal_smbus.c.

1169 {
1170  /* Check the parameters */
1171  assert_param(IS_SMBUS_TRANSFER_OPTIONS_REQUEST(XferOptions));
1172 
1173  if ((hsmbus->State & HAL_SMBUS_STATE_LISTEN) == HAL_SMBUS_STATE_LISTEN)
1174  {
1175  if ((pData == NULL) || (Size == 0UL))
1176  {
1177  hsmbus->ErrorCode = HAL_SMBUS_ERROR_INVALID_PARAM;
1178  return HAL_ERROR;
1179  }
1180 
1181  /* Disable Interrupts, to prevent preemption during treatment in case of multicall */
1182  SMBUS_Disable_IRQ(hsmbus, SMBUS_IT_ADDR | SMBUS_IT_TX);
1183 
1184  /* Process Locked */
1185  __HAL_LOCK(hsmbus);
1186 
1187  hsmbus->State = (HAL_SMBUS_STATE_SLAVE_BUSY_TX | HAL_SMBUS_STATE_LISTEN);
1188  hsmbus->ErrorCode = HAL_SMBUS_ERROR_NONE;
1189 
1190  /* Set SBC bit to manage Acknowledge at each bit */
1191  hsmbus->Instance->CR1 |= I2C_CR1_SBC;
1192 
1193  /* Enable Address Acknowledge */
1194  hsmbus->Instance->CR2 &= ~I2C_CR2_NACK;
1195 
1196  /* Prepare transfer parameters */
1197  hsmbus->pBuffPtr = pData;
1198  hsmbus->XferCount = Size;
1199  hsmbus->XferOptions = XferOptions;
1200 
1201  /* Convert OTHER_xxx XferOptions if any */
1203 
1204  if (Size > MAX_NBYTE_SIZE)
1205  {
1206  hsmbus->XferSize = MAX_NBYTE_SIZE;
1207  }
1208  else
1209  {
1210  hsmbus->XferSize = Size;
1211  }
1212 
1213  /* Set NBYTES to write and reload if size > MAX_NBYTE_SIZE and generate RESTART */
1214  if ((hsmbus->XferSize < hsmbus->XferCount) && (hsmbus->XferSize == MAX_NBYTE_SIZE))
1215  {
1216  SMBUS_TransferConfig(hsmbus, 0, (uint8_t)hsmbus->XferSize, SMBUS_RELOAD_MODE | (hsmbus->XferOptions & SMBUS_SENDPEC_MODE), SMBUS_NO_STARTSTOP);
1217  }
1218  else
1219  {
1220  /* Set NBYTE to transmit */
1221  SMBUS_TransferConfig(hsmbus, 0, (uint8_t)hsmbus->XferSize, hsmbus->XferOptions, SMBUS_NO_STARTSTOP);
1222 
1223  /* If PEC mode is enable, size to transmit should be Size-1 byte, corresponding to PEC byte */
1224  /* PEC byte is automatically sent by HW block, no need to manage it in Transmit process */
1225  if (SMBUS_GET_PEC_MODE(hsmbus) != 0UL)
1226  {
1227  hsmbus->XferSize--;
1228  hsmbus->XferCount--;
1229  }
1230  }
1231 
1232  /* Clear ADDR flag after prepare the transfer parameters */
1233  /* This action will generate an acknowledge to the HOST */
1234  __HAL_SMBUS_CLEAR_FLAG(hsmbus, SMBUS_FLAG_ADDR);
1235 
1236  /* Process Unlocked */
1237  __HAL_UNLOCK(hsmbus);
1238 
1239  /* Note : The SMBUS interrupts must be enabled after unlocking current process
1240  to avoid the risk of SMBUS interrupt handle execution before current
1241  process unlock */
1242  /* REnable ADDR interrupt */
1243  SMBUS_Enable_IRQ(hsmbus, SMBUS_IT_TX | SMBUS_IT_ADDR);
1244 
1245  return HAL_OK;
1246  }
1247  else
1248  {
1249  return HAL_BUSY;
1250  }
1251 }
static void SMBUS_TransferConfig(struct __SMBUS_HandleTypeDef *hsmbus, uint16_t DevAddress, uint8_t Size, uint32_t Mode, uint32_t Request)
Handle SMBUSx communication when starting transfer or during transfer (TC or TCR flag are set)...
__HAL_UNLOCK(hrtc)
__HAL_LOCK(hrtc)
return HAL_OK
static void SMBUS_Enable_IRQ(struct __SMBUS_HandleTypeDef *hsmbus, uint32_t InterruptRequest)
Manage the enabling of Interrupts.
static void SMBUS_Disable_IRQ(struct __SMBUS_HandleTypeDef *hsmbus, uint32_t InterruptRequest)
Manage the disabling of Interrupts.
static void SMBUS_ConvertOtherXferOptions(struct __SMBUS_HandleTypeDef *hsmbus)
Convert SMBUSx OTHER_xxx XferOptions to functionnal XferOptions.
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))