/home/daqweb/fgddaq/c8051/Devices/temp36_ADT7486A_tsensor.c File Reference

#include "../mscbemb.h"
#include "../Protocols/temp36_SST_handler.h"
#include "temp36_ADT7486A_tsensor.h"

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, float *fdata, int SST_LINE)
signed char ADT7486A_Read (unsigned char writeFCS_Originator, unsigned char cmdFlag, float *temperature, int SST_LINE)

Function Documentation

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

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, fdata, SST_LINE);
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, fdata,SST_LINE);
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, fdata,SST_LINE);                     
00107                 }
00108                 // GET 
00109                 if((writeLength == GET_CMD_WL) && (readLength == GET_CMD_RL)) {
00110                         if(k) {
00111                                 status = ADT7486A_Read(writeFCS_Org, READ_DATA, fdata,SST_LINE);
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,
float *  temperature,
int  SST_LINE 
)

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


Generated on 10 Jun 2013 for FGDC8051 by  doxygen 1.4.7