CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Devantech Thermal Array

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
jj9867



Joined: 27 Feb 2008
Posts: 8

View user's profile Send private message

Devantech Thermal Array
PostPosted: Wed Feb 27, 2008 12:54 pm     Reply with quote

Hi,

I am trying to get a Devantech Thermal Array Sensor TPA81 to work with my Picc 16f690 micro controller I am using the following code:

#include "thermal.h"

BYTE address,data[10];
BYTE readdata;
int count, current, high;
int16 delay;

BYTE readthermal(int address)
{
i2c_start();
delay_ms(10);
i2c_write(0xD0); // Device address
delay_ms(10);
i2c_write(address); // Data to device
delay_ms(10);
i2c_start(); // Restart
delay_ms(10);
i2c_write(0xD1); // to change data direction
delay_ms(10);
readdata = i2c_read(5); // Now read from slave
delay_ms(10);
i2c_stop();

return readdata;

}

void main()
{

//setup_adc_ports(NO_ANALOGS|VSS_VDD);
//setup_adc(ADC_OFF);
//setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
//setup_timer_1(T1_DISABLED);
//setup_timer_2(T2_DISABLED,0,1);

//setup_oscillator(OSC_8MHZ);

// now we must read this sucker
delay_ms(10000);

while(1 == 1)
{

address = 1;

while(address < 10)
{
data[address] = readthermal(address);
address++;
}


//count = 1;
//current = data[0];
//high = 0;
delay =800;

set_tris_c(0);
output_c(data[1]);
delay_ms(delay);
output_c(0b00000101);
delay_ms(delay);
output_c(data[2]);
delay_ms(delay);
output_c(0b00000101);
delay_ms(delay);
output_c(data[3]);
delay_ms(delay);
output_c(0b00000101);
delay_ms(delay);
output_c(data[4]);
delay_ms(delay);
output_c(0b00000101);
delay_ms(delay);
output_c(data[5]);
delay_ms(delay);
output_c(0b00000101);
delay_ms(delay);
output_c(data[6]);
delay_ms(delay);
output_c(0b00000101);
delay_ms(delay);
output_c(data[7]);
delay_ms(delay);
output_c(0b00000101);
delay_ms(delay);
output_c(data[8]);
delay_ms(delay);
output_c(0b00000101);
delay_ms(delay);
output_c(data[9]);
delay_ms(delay);
output_c(0b00000101);
delay_ms(delay);
output_c(0b11111111);
delay_ms(delay);


//while (count < 9)
//{
// if (current < data[count])
// {
// current = data[count];
// high = count;
// }
// count = count + 1;
//}

// set_tris_c(0);
// output_c(high);

}





}


really the important part of the code is the function that is supposed to read the thermal array one register at a time.

I am running this with LED's on each of the C pins. The only output I get from this program is 11111100. I am new to the whole I2C bus, but I have never had this problem when interfacing with a device. Normally the above code works without problems.

Any help would be great,
Thanks
JJ
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Feb 27, 2008 1:07 pm     Reply with quote

Quote:
delay_ms(10);
readdata = i2c_read(5); // Now read from slave
delay_ms(10);
i2c_stop();

This usage of i2c_read() is not in the CCS manual. The parameter is
allowed to be either a stream ID or an ACK/NACK indicator.

Download the CCS manual and look at page 169 in the Acrobat reader.
http://www.ccsinfo.com/downloads/CReferenceManual.pdf

The last i2c read operation must do a NACK (not acknowledge).
Do a search for the keyword Devantech and you will find examples:
http://www.ccsinfo.com/forum/viewtopic.php?t=26969
jj9867



Joined: 27 Feb 2008
Posts: 8

View user's profile Send private message

Thanks
PostPosted: Wed Feb 27, 2008 4:31 pm     Reply with quote

The stream address matched the one in the header file but I did not realize not to send the acknowledge bit....

Without that the sensor works flawlessly

Thanks
JJ
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group