/home/daqweb/fgddaq/c8051/Devices/ADT7486A_tsensor.h File Reference


Defines

#define Ping   0x00, 0x00, 0x00, 0x00, 0x00
#define GetIntTemp   0x00, 0x01, 0x02, 0x00, 0x00
#define GetExt1Temp   0x01, 0x01, 0x02, 0x00, 0x00
#define GetExt2Temp   0x02, 0x01, 0x02, 0x00, 0x00
#define GetAllTemps   0x00, 0x01, 0x06
#define SetExt1Offset   0xE0, 0x03, 0x00
#define GetExt1Offset   0xE0, 0x01, 0x02, 0x00, 0x00
#define SetExt2Offset   0xE1, 0x03, 0x00
#define GetExt2Offset   0xE1, 0x01, 0x02, 0x00, 0x00
#define ResetDevice   0xF6, 0x01, 0x00
#define GetDIB_8bytes   0xF7, 0x01, 0x10, 0x00, 0x00
#define DONT_READ_DATA   (unsigned char) 0xff
#define READ_DATA   (unsigned char) 0x00
#define AVG_COUNT   1
#define ADT7486A_CONVERSION_TIME   30
#define SET_OFFSET_WL   (unsigned char) 0x03
#define PING_WL   0x00
#define GET_CMD_WL   0x01
#define GET_CMD_RL   0x02
#define RESET_CMD   0xF6
#define SUCCESS   0
#define FCS_WERROR   -1
#define FCS_RERROR   -2
#define CLIENT_ABORT   -3
#define PING_OFFSET_RESET_CMD   1
#define INVALID_TEMP   -5
#define OUT_OF_RANGE   -6
#define N_TEMP_TRIALS   20
#define CONVERSION_FACTOR1   0.9294f
#define CONVERSION_FACTOR2   0.8569f

Functions

void ADT7486A_Init (int SST_LINE)
signed char ADT7486A_Cmd (unsigned char addr, unsigned char command, unsigned char writeLength, unsigned char readLength, unsigned char datMSB, unsigned char datLSB, int SST_LINE, float *fdata)
signed char ADT7486A_Read (unsigned char writeFCS_Originator, unsigned char cmdflag, int SST_LINE, float *temperature)

Define Documentation

#define ADT7486A_CONVERSION_TIME   30

#define AVG_COUNT   1

#define CLIENT_ABORT   -3

#define CONVERSION_FACTOR1   0.9294f

#define CONVERSION_FACTOR2   0.8569f

#define DONT_READ_DATA   (unsigned char) 0xff

#define FCS_RERROR   -2

#define FCS_WERROR   -1

#define GET_CMD_RL   0x02

#define GET_CMD_WL   0x01

#define GetAllTemps   0x00, 0x01, 0x06

#define GetDIB_8bytes   0xF7, 0x01, 0x10, 0x00, 0x00

#define GetExt1Offset   0xE0, 0x01, 0x02, 0x00, 0x00

#define GetExt1Temp   0x01, 0x01, 0x02, 0x00, 0x00

#define GetExt2Offset   0xE1, 0x01, 0x02, 0x00, 0x00

#define GetExt2Temp   0x02, 0x01, 0x02, 0x00, 0x00

#define GetIntTemp   0x00, 0x01, 0x02, 0x00, 0x00

#define INVALID_TEMP   -5

#define N_TEMP_TRIALS   20

#define OUT_OF_RANGE   -6

#define Ping   0x00, 0x00, 0x00, 0x00, 0x00

#define PING_OFFSET_RESET_CMD   1

#define PING_WL   0x00

#define READ_DATA   (unsigned char) 0x00

#define RESET_CMD   0xF6

#define ResetDevice   0xF6, 0x01, 0x00

#define SET_OFFSET_WL   (unsigned char) 0x03

#define SetExt1Offset   0xE0, 0x03, 0x00

#define SetExt2Offset   0xE1, 0x03, 0x00

#define SUCCESS   0


Function Documentation

signed char ADT7486A_Cmd ( unsigned char  addr,
unsigned char  command,
unsigned char  writeLength,
unsigned char  readLength,
unsigned char  datMSB,
unsigned char  datLSB,
int  SST_LINE,
float *  fdata 
)

Sends commands to the device. Not all the functions are currently implemented Ths is the cmd list...

test purpose.
temp.jpg

Attention:
Conversion time 12,38,38ms round-robin for all 3 channels of the device. Internal averaging, doesn't require one at this level. If anyway desided >100ms< needs to be added if polling on single channel!
Parameters:
addr Address of the client which Originator wants to talk to
command Command (see ADT7486A_tsensor.h file or ADT7486A manual)
writeLength Length of the data Originator wants to send
readLength Length of the data Originator wants to receive
datMSB Most Significant byte of the temperature offset value (for SetExt1OffSet() and SetExt2OffSet() commands)
datLSB Least Significant byte of the temperature offset value
*fdata Temperature
Returns:
SUCCESS, status from ADT7486A_Read()
00056                                                                                                                        {
00057         signed char k, status, ntry;                                                    
00058         unsigned char xdata writeFCS_Org;                        // Originator's side write FCS 
00059         float xdata tempsum = 0.0f;                      // Read sum for average        
00060 
00061         //Calculate originator's side write FCS
00062         writeFCS_Org = FCS_Step(command
00063                 , FCS_Step(readLength
00064                 , FCS_Step(writeLength
00065                 , FCS_Step(addr
00066                 , 0x00)))); 
00067 
00068         // setOffSet commands, add the 2 bytes of data
00069         if(writeLength == SET_OFFSET_WL) {
00070                 writeFCS_Org = FCS_Step(writeFCS_Org
00071                         , FCS_Step(datMSB
00072                         , FCS_Step(datLSB
00073                         , 0x00)));
00074         }
00075 
00076         k        = AVG_COUNT;
00077         ntry = N_TEMP_TRIALS; 
00078  
00079         //Run averaging and max tries
00080         while(k && ntry) {
00081 
00082                 //Start the message
00083                 SST_DrvLow(SST_LINE);                                            // Sending two zero (the address timing negotiation bits)
00084                 SST_DrvLow(SST_LINE);
00085                 SST_WriteByte(addr,SST_LINE);            // Target address
00086                 SST_DrvLow(SST_LINE);                    // Send the message timing negotiation bit
00087                 SST_WriteByte(writeLength,SST_LINE);  // WriteLength
00088                 SST_WriteByte(readLength,SST_LINE);      // ReadLength
00089                 if(writeLength == PING_WL) {
00090                         // PING
00091                         return ADT7486A_Read(writeFCS_Org, DONT_READ_DATA, SST_LINE, fdata);
00092                 }
00093 
00094                 // Send CMD
00095                 SST_WriteByte(command,SST_LINE);        //Optional : sending the commands
00096 
00097                 // RESET
00098                 if(command == RESET_CMD) {
00099                         return ADT7486A_Read(writeFCS_Org, DONT_READ_DATA, SST_LINE, fdata);
00100                 }
00101                 // SET
00102                 if(writeLength == SET_OFFSET_WL) {
00103                         //Send the data in little endian format
00104                         SST_WriteByte(datLSB,SST_LINE);
00105                         SST_WriteByte(datMSB,SST_LINE);
00106                         return ADT7486A_Read(writeFCS_Org, DONT_READ_DATA, SST_LINE,fdata);                     
00107                 }
00108                 // GET 
00109                 if((writeLength == GET_CMD_WL) && (readLength == GET_CMD_RL)) {
00110                         if(k) {
00111                                 status = ADT7486A_Read(writeFCS_Org, READ_DATA, SST_LINE, fdata);
00112                                 if (status == SUCCESS) {
00113                                         tempsum += *fdata;
00114                                         k--;
00115                                 }
00116                         } 
00117                 if (k == 0) {   
00118                                 *fdata = tempsum / AVG_COUNT;
00119                 return SUCCESS;
00120                         }       
00121                 }
00122 
00123                 //Clear for the next msg and delay for conversion to finish
00124                 if (AVG_COUNT > 1) {
00125                 SST_Clear(SST_LINE);
00126                         delay_ms(ADT7486A_CONVERSION_TIME);
00127         }
00128         ntry--;
00129         } // out of while (ntry done with error) 
00130 
00131         return status;  
00132 }

void ADT7486A_Init ( int  SST_LINE  ) 

Initialize the SST communication protocol

00027                                  {      
00028         SST_Init(SST_LINE);
00029 }

signed char ADT7486A_Read ( unsigned char  writeFCS_Originator,
unsigned char  cmdFlag,
int  SST_LINE,
float *  temperature 
)

Reads 2 bytes of info which are Internal Temp, External Temp1,External Temp2, GetExt1Offset and GetExt2Offset.

Parameters:
writeFCS_Originator Originator's writeFCS
cmdFlag Flag used to distinguish if the command is a Ping/Reset or not.
*temperature Single temperature read
Returns:
SUCCESS, INVALID_TEMP, FCS_WERROR, CLIENT_ABORT, OUT_OF_RANGE
00147                                                                                            {    
00148 
00149         //Declare local variables
00150         unsigned char LSB_Received;     
00151         unsigned char MSB_Received;             
00152         signed  short xdata itemperature;
00153         unsigned char writeFCS_Client = 0x00;    // client write FCS
00154         unsigned char readFCS_Client    = 0x00;  // client read FCS     (rm var once debugged)
00155 
00156         // Get the client FCS to compare against the originator
00157         writeFCS_Client = SST_ReadByte(SST_LINE);
00158 
00159         //WriteFCS check (needs to match to continue)
00160         if(writeFCS_Originator != writeFCS_Client)
00161                 return FCS_WERROR;
00162 
00163         // Client is requesting a message abort
00164         if(writeFCS_Originator == ~writeFCS_Client)
00165                 return CLIENT_ABORT; 
00166 
00167         // No data to read      
00168         if (cmdFlag == DONT_READ_DATA) 
00169                 return PING_OFFSET_RESET_CMD;
00170 
00171         // Data to read
00172         if(cmdFlag == READ_DATA) 
00173         {
00174                 // Read data
00175                 LSB_Received    = SST_ReadByte(SST_LINE);       //get LSB
00176                 MSB_Received    = SST_ReadByte(SST_LINE);       //get MSB
00177                 readFCS_Client  = SST_ReadByte(SST_LINE);       //get FCS
00178 
00179                 // Client FC check
00180                 if(FCS_Step(MSB_Received, FCS_Step(LSB_Received, 0x00)) != readFCS_Client) 
00181                         return FCS_RERROR;               // No match 
00182 
00183                 // Temperature Conversion +/- 512 degC on 16bits
00184                 // if negative, then do two's complement
00185                 if((MSB_Received & 0x80) == 0x80) {
00186                         MSB_Received = ~MSB_Received;
00187                         LSB_Received = ~LSB_Received + 0x01;
00188                 }
00189 
00190                 // In 1/64th degree Celsius
00191                 itemperature    = (MSB_Received << 8) + LSB_Received;   
00192                 *temperature    = ((float) itemperature) / 64;
00193 //              *temperature *= CONVERSION_FACTOR1;     // -PAA- Should be ONE
00194                 *temperature -= CONVERSION_FACTOR2;
00195 
00196                 // Check whether temperature is in range
00197                 if ((*temperature > 100.) || (*temperature < -10.)) 
00198                         return OUT_OF_RANGE;    
00199                 else if (*temperature == -CONVERSION_FACTOR2) 
00200                         return INVALID_TEMP;
00201         }
00202 
00203         // Valid temperature
00204         return SUCCESS;
00205 }


Generated on 10 Jun 2013 for FGDC8051 by  doxygen 1.4.7