View previous topic :: View next topic |
Author |
Message |
jj9867
Joined: 27 Feb 2008 Posts: 8
|
Devantech Thermal Array |
Posted: Wed Feb 27, 2008 12:54 pm |
|
|
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
|
|
Posted: Wed Feb 27, 2008 1:07 pm |
|
|
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
|
Thanks |
Posted: Wed Feb 27, 2008 4:31 pm |
|
|
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 |
|
|
|