Ejemplo n.º 1
1
/**
  * @brief  Read The Temperature Sensor Status
  * @param  DeviceAddr : Device ID address.
  * @retval Temperature Sensor Status
  */
uint8_t TSENSOR_ReadStatus(uint16_t DeviceAddr)
{
  uint8_t bufferrx[1] = {0};
  uint8_t buffertx[1] = {0};

  /*##-1- Send Status Command ################################################*/
  buffertx[0] = TSENSOR_STATUS;
  if (HAL_SMBUS_Master_Transmit_IT(&SmbusHandle, DeviceAddr, &buffertx[0], sizeof(buffertx), SMBUS_FIRST_AND_LAST_FRAME_NO_PEC) != HAL_OK)
  {
    return TSENSOR_ERROR;
  }
  while(HAL_SMBUS_GetState(&SmbusHandle) != HAL_SMBUS_STATE_READY);
  
  /*##-2- Retrieve Status Data Byte ##########################################*/
  if (HAL_SMBUS_Master_Receive_IT(&SmbusHandle, DeviceAddr, &bufferrx[0], sizeof(buffertx), SMBUS_FIRST_AND_LAST_FRAME_NO_PEC) != HAL_OK)
  {
    return TSENSOR_ERROR;
  }
  while(HAL_SMBUS_GetState(&SmbusHandle) != HAL_SMBUS_STATE_READY);

  /* Return Temperature Sensor Status */
  return (uint8_t)(bufferrx[0]);
}
Ejemplo n.º 2
0
/**
  * @brief  Read temperature value of the Temperature Sensor.
  * @param  DeviceAddr : Device ID address.
  * @retval Temperature measured
  */
uint16_t TSENSOR_ReadTemp(uint16_t DeviceAddr)
{
  uint8_t bufferrx[2] = {0, 0};
  uint8_t buffertx[2] = {TSENSOR_TEMP_VALUE_HIGH_BYTE, TSENSOR_TEMP_VALUE_LOW_BYTE};
  uint16_t tmp = 0;
  uint8_t count = 0;

  for(count = 0; count < 2; count++)
  {
    /*##-1- Send Temperature Read Command ####################################*/
    if (HAL_SMBUS_Master_Transmit_IT(&SmbusHandle, DeviceAddr, &buffertx[count], 1, SMBUS_FIRST_FRAME) != HAL_OK)
    {
      return TSENSOR_ERROR;
    }
    while(HAL_SMBUS_GetState(&SmbusHandle) != HAL_SMBUS_STATE_READY);
    
    /*##-2- Retrieve Temperature Data Byte ###################################*/
    if (HAL_SMBUS_Master_Receive_IT(&SmbusHandle, DeviceAddr, &bufferrx[count], 1, SMBUS_LAST_FRAME_NO_PEC) != HAL_OK)
    {
      return TSENSOR_ERROR;
    }
    while(HAL_SMBUS_GetState(&SmbusHandle) != HAL_SMBUS_STATE_READY);
  }  

  tmp = (uint16_t)(bufferrx[0] << 8);
  tmp |= bufferrx[1];
  
  /* Return Temperature value */
  return (uint16_t)(tmp >> 4);
}
Ejemplo n.º 3
0
/**
  * @brief  Get the address of the Temperature Sensor in alert mode.
  * @param  None
  * @retval Temperature Sensor Address.
  */
uint8_t TSENSOR_AlerteResponseAddressRead(void)
{
  uint8_t bufferrx[1] = {0};

  /*##-1- Retrieve Alert Temperature Sensor Address ##########################*/
  HAL_SMBUS_Master_Receive_IT(&SmbusHandle, 0x18, &bufferrx[0], 1, SMBUS_FIRST_AND_LAST_FRAME_NO_PEC);  
  while(HAL_SMBUS_GetState(&SmbusHandle) != HAL_SMBUS_STATE_READY);
  
  /* Return Temperature Sensor Address */
  return bufferrx[0];
}
Ejemplo n.º 4
0
/**
  * @brief  Set TSENSOR Initialization.
  * @param  DeviceAddr : Device ID address.
  * @param  pInitStruct: pointer to a TSENSOR_InitTypeDef structure 
  *         that contains the configuration setting for the TSENSOR.
  * @retval TSENSOR status
  */
TSENSOR_StatusTypeDef TSENSOR_Init(uint16_t DeviceAddr, TSENSOR_InitTypeDef *pInitStruct)
{  
  uint8_t buffertx[2] = {0,0};

  /*##-1- Initialise the SMBUS peripheral ####################################*/
  SmbusHandle.Instance                  = TSENSOR_SMBUS;
  
  SmbusHandle.Init.Timing               = TSENSOR_TIMING;
  SmbusHandle.Init.AnalogFilter         = SMBUS_ANALOGFILTER_ENABLED;
  SmbusHandle.Init.OwnAddress1          = 0x00;
  SmbusHandle.Init.AddressingMode       = SMBUS_ADDRESSINGMODE_7BIT;
  SmbusHandle.Init.DualAddressMode      = SMBUS_DUALADDRESS_DISABLED;
  SmbusHandle.Init.OwnAddress2          = 0x00;
  SmbusHandle.Init.GeneralCallMode      = SMBUS_GENERALCALL_DISABLED;
  SmbusHandle.Init.NoStretchMode        = SMBUS_NOSTRETCH_DISABLED;  
  SmbusHandle.Init.PacketErrorCheckMode = SMBUS_PEC_DISABLED;
  SmbusHandle.Init.PeripheralMode       = SMBUS_PERIPHERAL_MODE_SMBUS_HOST;
  SmbusHandle.Init.SMBusTimeout         = 0;
  
  if(HAL_SMBUS_Init(&SmbusHandle) != HAL_OK)
  {
    return TSENSOR_ERROR;
  }

  /*##-2- Verify that Temperature Sensor is ready ############################*/
  if (TSENSOR_IsReady(DeviceAddr, 20) != TSENSOR_OK )
  {
    return TSENSOR_ERROR;
  }

  /*##-3- Set the Configuration Register #####################################*/
  buffertx[0] = TSENSOR_CONFIGURATION;
  buffertx[1] = (uint8_t)(pInitStruct->AlertMode | pInitStruct->ConversionMode | pInitStruct->ConversionResolution);
  if (HAL_SMBUS_Master_Transmit_IT(&SmbusHandle, DeviceAddr, &buffertx[0], sizeof(buffertx), SMBUS_FIRST_AND_LAST_FRAME_NO_PEC) != HAL_OK)
  {
    return TSENSOR_ERROR;
  }
  while(HAL_SMBUS_GetState(&SmbusHandle) != HAL_SMBUS_STATE_READY);
  
  /*##-4- Set the Conversion Rate ############################################*/
  buffertx[0] = TSENSOR_CONVERSION_RATE;
  buffertx[1] = (uint8_t)(pInitStruct->ConversionRate);
  if (HAL_SMBUS_Master_Transmit_IT(&SmbusHandle, DeviceAddr ,&buffertx[0], sizeof(buffertx), SMBUS_FIRST_AND_LAST_FRAME_NO_PEC) != HAL_OK)
  {
    return TSENSOR_ERROR;
  }
  while(HAL_SMBUS_GetState(&SmbusHandle) != HAL_SMBUS_STATE_READY);

  /*##-5- Set the HIGH Limit Temperature #####################################*/
  buffertx[0] = TSENSOR_TEMP_HIGH_LIMIT_HIGH_BYTE;
  buffertx[1] = (uint8_t)(pInitStruct->TemperatureLimitHigh);
  if (HAL_SMBUS_Master_Transmit_IT(&SmbusHandle, DeviceAddr, &buffertx[0], sizeof(buffertx), SMBUS_FIRST_AND_LAST_FRAME_NO_PEC) != HAL_OK)
  {
    return TSENSOR_ERROR;
  }
  while(HAL_SMBUS_GetState(&SmbusHandle) != HAL_SMBUS_STATE_READY);

  /*##-6- Set the low Limit Temperature ######################################*/
  buffertx[0] = TSENSOR_TEMP_LOW_LIMIT_HIGH_BYTE;
  buffertx[1] = (uint8_t)(pInitStruct->TemperatureLimitLow);
  if (HAL_SMBUS_Master_Transmit_IT(&SmbusHandle, DeviceAddr, &buffertx[0], sizeof(buffertx), SMBUS_FIRST_AND_LAST_FRAME_NO_PEC) != HAL_OK)
  {
    return TSENSOR_ERROR;
  }
  while(HAL_SMBUS_GetState(&SmbusHandle) != HAL_SMBUS_STATE_READY);
  
  
  /*##-7- Manage Alert Mode setting ##########################################*/
  /* Clear an old alert if limit status is set */
  /* To clear an alert, need to perform an Alert Response command */
  if(((TSENSOR_ReadStatus(DeviceAddr) & TSENSOR_TEMP_EXCEED_HIGH_LIMIT) == TSENSOR_TEMP_EXCEED_HIGH_LIMIT)
     || ((TSENSOR_ReadStatus(DeviceAddr) & TSENSOR_TEMP_IS_OR_BELOW_LOW_LIMIT) == TSENSOR_TEMP_IS_OR_BELOW_LOW_LIMIT))
  {
    TSENSOR_AlerteResponseAddressRead();
  }

  /* Check Alert Mode requested */
  if(pInitStruct->AlertMode == TSENSOR_ALERT_ENABLE)
  {
    /* Enable SMBUS Alert */
    HAL_SMBUS_EnableAlert_IT(&SmbusHandle);
  }
  
  /* Return status OK*/
  return TSENSOR_OK;
}
Ejemplo n.º 5
0
/**
  * @brief  Set TSENSOR Initialization.
  * @param  DeviceAddr : Device ID address.
  * @param  pInitStruct: pointer to a TSENSOR_InitTypeDef structure 
  *         that contains the configuration setting for the TSENSOR.
  * @retval TSENSOR status
  */
TSENSOR_StatusTypeDef TSENSOR_Init(uint16_t DeviceAddr, TSENSOR_InitTypeDef *pInitStruct)
{  
  uint8_t buffertx[3] = {0,0,0};

  /*##-1- Initialise the SMBUS peripheral ####################################*/
  SmbusHandle.Instance                  = TSENSOR_SMBUS;
  
  SmbusHandle.Init.Timing               = TSENSOR_TIMING;
  SmbusHandle.Init.AnalogFilter         = SMBUS_ANALOGFILTER_ENABLE;
  SmbusHandle.Init.OwnAddress1          = 0x00;
  SmbusHandle.Init.AddressingMode       = SMBUS_ADDRESSINGMODE_7BIT;
  SmbusHandle.Init.DualAddressMode      = SMBUS_DUALADDRESS_DISABLE;
  SmbusHandle.Init.OwnAddress2          = 0x00;
  SmbusHandle.Init.GeneralCallMode      = SMBUS_GENERALCALL_DISABLE;
  SmbusHandle.Init.NoStretchMode        = SMBUS_NOSTRETCH_DISABLE;  
  SmbusHandle.Init.PacketErrorCheckMode = SMBUS_PEC_DISABLE;
  SmbusHandle.Init.PeripheralMode       = SMBUS_PERIPHERAL_MODE_SMBUS_HOST;
  SmbusHandle.Init.SMBusTimeout         = 0;
  
  if(HAL_SMBUS_Init(&SmbusHandle) != HAL_OK)
  {
    return TSENSOR_ERROR;
  }

  /*##-2- Verify that Temperature Sensor is ready ############################*/
  if (TSENSOR_IsReady(DeviceAddr, 20) != TSENSOR_OK )
  {
    return TSENSOR_ERROR;
  }

  /*##-3- Set the Configuration Register #####################################*/
  buffertx[0] = TSENSOR_REG_CONF;
  buffertx[1] = (uint8_t)(pInitStruct->AlertMode | pInitStruct->ConversionMode);
  if (HAL_SMBUS_Master_Transmit_IT(&SmbusHandle, DeviceAddr, &buffertx[0], /*sizeof(buffertx)*/2, SMBUS_FIRST_AND_LAST_FRAME_NO_PEC) != HAL_OK)
  {
    return TSENSOR_ERROR;
  }
  while(HAL_SMBUS_GetState(&SmbusHandle) != HAL_SMBUS_STATE_READY);
  
  /*##-4- Set the HIGH Limit Temperature #####################################*/
  buffertx[0] = TSENSOR_REG_TOS;
  buffertx[1] = (uint8_t)(pInitStruct->TemperatureLimitHigh);
  buffertx[2] = 0;

  if (HAL_SMBUS_Master_Transmit_IT(&SmbusHandle, DeviceAddr, &buffertx[0], /*sizeof(buffertx)*/3, SMBUS_FIRST_AND_LAST_FRAME_NO_PEC) != HAL_OK)
  {
    return TSENSOR_ERROR;
  }
  while(HAL_SMBUS_GetState(&SmbusHandle) != HAL_SMBUS_STATE_READY);

  /*##-5- Set the low Limit Temperature ######################################*/
  buffertx[0] = TSENSOR_REG_THYS;
  buffertx[1] = (uint8_t)(pInitStruct->TemperatureLimitLow);
  buffertx[2] = 0;
  
  if (HAL_SMBUS_Master_Transmit_IT(&SmbusHandle, DeviceAddr, &buffertx[0], /*sizeof(buffertx)*/3, SMBUS_FIRST_AND_LAST_FRAME_NO_PEC) != HAL_OK)
  {
    return TSENSOR_ERROR;
  }
  while(HAL_SMBUS_GetState(&SmbusHandle) != HAL_SMBUS_STATE_READY);
  
  /*##-6- Check Alert Mode requested #########################################*/
  if(pInitStruct->AlertMode == TSENSOR_INTERRUPT_MODE)
  {
    /* Enable SMBUS Alert */
    HAL_SMBUS_EnableAlert_IT(&SmbusHandle);
  }

  /* Return status OK*/
  return TSENSOR_OK;
}