* @file Max31855.c
* @brief Max31855����ģ��
* @version 1.0
* @date 2014�� 5�� 9 ��
* @author ����ƽ
**
**--------------��ǰ�汾��------------------------------------------------------------------------------
** ����:
** �ա���:
** �衡��:
**
**------------------------------------------------------------------------------------------------------
**************************************************************************************************************/
/** @addtogroup Max31855
* @{
*/
#include "../include/Max31855.h"
Max31855_DATA ChipOut;
/*********************************************************************//**
* @fun readdata
* @brief ��ȡMAX31855��ѹֵ
* @param None
* @return �������
***********************************************************************/
static uint8_t readdata(uint32_t *pData)
{
uint8_t i;
uint32_t tmp;
static uint16_t timesticke = 0;
if(timesticke < 2000)
{
timesticke++;
return 0;
}
else
{
tmp = 0;
MAX31855_CLK = LVAR;
MAX31855_CS = LVAR;
for(i = 0; i < 32; i++)
{
asm("nop;");
MAX31855_CLK = HVAR;
tmp = tmp<<1;
if(MAX31855_DATA == HVAR)
tmp |= 1;
else
tmp &= ~1;
MAX31855_CLK = LVAR;
asm("nop;");
asm("nop;");
asm("nop;");
}
MAX31855_CLK = LVAR;
MAX31855_CS = HVAR;
*pData = tmp;
timesticke = 0;
return 1;
}
}
/*********************************************************************//**
* @fun Max31855_GetTemperatureValue
* @brief ��ȡ�ȵ�ż�¶�ֵ
* @param None
* @return �ȵ�ż�¶�ֵ
***********************************************************************/
int32_t Max31855_GetTemperatureValue(void)
{
int32_t retHTe;
uint32_t temp;
if(readdata(&temp))
{
ChipOut.all = temp;
}
retHTe = ChipOut.bit.HTemperature;
return retHTe;
}
/*********************************************************************//**
* @fun GetMax31855Fault
* @brief ��ȡ�ȵ�ż�������
* @param None
* @return 0:���� 1:��· 2: �ڵض�· 3:��VCC��·
***********************************************************************/
uint8_t GetMax31855Fault(void)
{
if(ChipOut.bit.Fault**)
{
if(ChipOut.bit.OC)
return 1;
if(ChipOut.bit.SCG)
return 2;
if(ChipOut.bit.SCV)
return 3;
}
return 0;
}
/**
* @}
*/
|