• Not Answered

TSC2003: Problem reading TSC2003 temperature

Part Number: TSC2003

Hello,

I am trying figure out how to read temperature using this chip. It looks like I implemented my I2C drivers correctly because I am able to measure X and Y okay and I am able to implement touch screen feature. But I could not get the right temperature readings. Any suggestions on what I am doing wrong? I am using the TM4C1294NCPDTI

void InitializeTouch(void)
{
 //PENIRQ pin
 SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);
 while(!SysCtlPeripheralReady(SYSCTL_PERIPH_GPIOC))
 {
 }//end while(!SysCtlPeripheralReady(SYSCTL_PERIPH_GPIOC))
 
 GPIOPinTypeGPIOInput(GPIO_PORTC_BASE, GPIO_PIN_4);
 GPIOIntTypeSet(GPIO_PORTC_BASE, GPIO_PIN_4, GPIO_FALLING_EDGE); 
// GPIOPadConfigSet(GPIO_PORTC_BASE, GPIO_PIN_4, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU);
 
 GPIOIntRegister(GPIO_PORTC_BASE, PortCIntHandler);
 GPIOIntEnable(GPIO_PORTC_BASE, GPIO_PIN_4);
 
 //Touch I2C pins
 SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C6);
 while(!SysCtlPeripheralReady(SYSCTL_PERIPH_I2C6))
 {
 }//end while(!SysCtlPeripheralReady(SYSCTL_PERIPH_I2C6))
 
 SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
 while(!SysCtlPeripheralReady(SYSCTL_PERIPH_GPIOA))
 {
 }//end while(!SysCtlPeripheralReady(SYSCTL_PERIPH_GPIOA)) 
 
 GPIOPinConfigure(GPIO_PA6_I2C6SCL);
 GPIOPinConfigure(GPIO_PA7_I2C6SDA);
  GPIOPinTypeI2CSCL(GPIO_PORTA_BASE, GPIO_PIN_6);
  GPIOPinTypeI2C(GPIO_PORTA_BASE, GPIO_PIN_7); 
 
 //I2C1
 I2CMasterInitExpClk(I2C6_BASE, FOSC_HZ, false); 
 
 //chip initialize
 WriteTouchByte(0x90, 0x02);
 PollTimer0Delay(20, 1000);
 ReadTouchByte(0x90);
}//end void InitializeTouch(void)
/***********************************************/
void WriteTouchByte(uint8_t i2cAdd,  uint8_t commandByte)
{
 i2cAdd = i2cAdd >> 1;
 I2CMasterSlaveAddrSet(I2C6_BASE, i2cAdd, false);
 I2CMasterDataPut(I2C6_BASE, commandByte);
 I2CMasterControl(I2C6_BASE, I2C_MASTER_CMD_SINGLE_SEND);
 
 PollTimer0Delay(50, 1000000);
 while(I2CMasterBusy(I2C6_BASE))
 {
 }
}//end void WriteTouchByte(uint8_t i2cAdd,  uint8_t commandByte)
/***********************************************/
uint8_t ReadTouchByte(uint8_t i2cAdd)
{
 uint32_t i2cByte;
 i2cAdd = i2cAdd >> 1;
 
 I2CMasterSlaveAddrSet(I2C6_BASE, i2cAdd, true);
 I2CMasterControl(I2C6_BASE, I2C_MASTER_CMD_SINGLE_RECEIVE);
 PollTimer0Delay(50, 1000000);
 while(I2CMasterBusy(I2C6_BASE));
 i2cByte = I2CMasterDataGet(I2C6_BASE);
 
 return((uint8_t)i2cByte);
}//end uint8_t ReadTouchByte(uint8_t i2cAdd)
/***********************************************/

This is the code in my main

     WriteUART0("\n\rTouch Temp1 = ");
     WriteTouchByte(0x90, 0x0E);
     PollTimer0Delay(20, 1000);
     touchTemp1 = ReadTouchByte(0x90);
     UINT32ToASCII((uint32_t)touchTemp1);
     WriteUART0(decimal_string);

     WriteTouchByte(0x90, 0x02);  
     PollTimer0Delay(20, 1000);
     ReadTouchByte(0x90);

     PollTimer0Delay(5, 1);

     WriteUART0("\n\rTouch Temp2 = ");
     WriteTouchByte(0x90, 0x4E); 
     PollTimer0Delay(20, 1000); 
     touchTemp2 = ReadTouchByte(0x90);
     UINT32ToASCII((uint32_t)touchTemp2);
     WriteUART0(decimal_string); 
     
     WriteTouchByte(0x90, 0x02);  
     PollTimer0Delay(20, 1000);
     ReadTouchByte(0x90);
     
     Temperature = touchTemp1 * 2.5 / 255 * 1000.0 * 25.0 / 600;
     WriteUART0("\n\rTemp0(C) = ");
     DoubleToASCII(Temperature);
     WriteUART0(decimal_string);

     Temperature = (2.573 * (touchTemp2 - touchTemp1) * 2.5 / 255 * 1000) - 273;
     WriteUART0("\n\rTemp1(C) = ");
     DoubleToASCII(Temperature);
     WriteUART0(decimal_string);    

This is what I see on hyperterminal. And no matter what the temperature around is, it's always like this.

Touch Temp1 = 76
Touch Temp2 = 92
Temp0(C) = 31.04
Temp1(C) = 130.60

Thanks.

AJ

1 Reply