Hi,
I’m using TC72 sensor http://ww1.microchip.com/downloads/en/DeviceDoc/21743a.pdf
to measure the temp. data using Uno.
I have spend more then required time but this simple communication not working at all.
Please help me out here.
I have already check with this one http://forum.arduino.cc/index.php?topic=365351.0 but not getting success
here is the code for the same.
#include <SPI.h>
//Assign the Chip Select signal to pin 10.
const int CS=10;
//TC72 Registers
const char CNTL_R = 0x00;
const char CNTL_W = 0x80;
const char ID = 0x03;
const char TEMP_LSB = 0x01;
const char TEMP_MSB = 0x02;
char values[10];
byte SensorID,tempLSB,tempMSB,tempMSB1,tempMSB2,tempMSB3,tempMSB4;
unsigned int livetemp;
void setup()
{
//SPI Port Setup
SPI.begin();
SPI.setDataMode(SPI_MODE1);
pinMode(CS, OUTPUT);
digitalWrite(CS, LOW);
//Console Setup
Serial.begin(9600);
//Turn on the sensor for continous temp conversion mode
writeRegister(CNTL_W, 0x04);
}
void loop()
{
readRegister(ID, 1, values);
if(values[0] == 0x54)
{
Serial.print(“TC-72 sensor detected with ID - “);
Serial.print(values[0],HEX);
Serial.print(”\n”);
}
else
{
Serial.print(“TC-72 is not found, the ID is - “);
Serial.print(values[0],HEX);
Serial.print(”\n”);
}
//readRegister(TEMP_LSB, 1, values);
//tempLSB = values[0];
readRegister(TEMP_MSB, 5, values);
tempMSB = values[0];
tempMSB1 = values[1];
tempMSB2 = values[2];
tempMSB3 = values[3];
tempMSB4 = values[4];
Serial.print("Live temp is - ");
Serial.print(tempMSB, DEC);
Serial.print(tempMSB1, DEC);
Serial.print(tempMSB2, DEC);
Serial.print(tempMSB3, DEC);
Serial.print(tempMSB4, DEC);
Serial.print("\n");
delay(500);
}
void writeRegister(char registerAddress, char value)
{
digitalWrite(CS, LOW);
digitalWrite(CS, HIGH);
SPI.transfer(registerAddress);
SPI.transfer(value);
digitalWrite(CS, LOW);
}
void readRegister(char registerAddress, int numBytes, char * values)
{
digitalWrite(CS, LOW);
digitalWrite(CS, HIGH);
SPI.transfer(registerAddress);
for(int i=0; i<numBytes; i++)
{
values = SPI.transfer(0x00);
-
}*
-
digitalWrite(CS, LOW);*
}
-------------------------------------------------------------------------------------------------------------