SparkFun Forums 

Where electronics enthusiasts find answers.

Your source for all things Atmel.
By maxr
#88219
I tried to put some code here but it got blocked for bad words or something.

Anyway, here is the link to the device on Sparkfun

http://www.sparkfun.com/commerce/produc ... ts_id=9570

I tried the code in the comments from Ben121 and it doesn't work (for me). Does anyone have any idea about what might be wrong. Does anyone have more detailed setup instruction and some code that may test whether one can communicate with it over the SMBus.

I wish Sparkfun had better documentation.

Thanks,
Max
By maxr
#88676
I bought a Devantech TPA81 from a different supplier and it works.
By maxr
#90644
Just in case you're here, here is Dave Eaton's code from the product comments page.

See CalculusAE's thread at http://www.arduino.cc/cgi-bin/yabb2/YaB ... 1214872633 for a link to a i2cmaster library

I am using a Duemilanove, so I changed the twimaster.c to reflect the 16MHz clock, and changed the bus frequency to 50Khz:

#ifndef F_CPU
#define F_CPU 16000000UL
#endif

/* I2C clock in Hz */
#define SCL_CLOCK 50000L

You make a folder in /{arduino root}/hardware/libraries and copy the
i2cmaster.h and twimaster.c, renaming the .c file to .cpp

Then the Arduio code in subsequent posts works for me:

#include

void setup()
{
Serial.begin(9600);
Serial.println("Hello!");
i2c_init(); //Initialise the i2c bus
Serial.println("Return from i2c_init");
PORTC = (1 << PORTC4) | (1 << PORTC5);//enable pullups
}
void loop()
{
int dev = 0x5A<<1;
int data_low = 0;
int data_high = 0;
int pec = 0;
i2c_start_wait(dev+I2C_WRITE);
i2c_write(0x07);


i2c_rep_start(dev+I2C_READ);
data_low = i2c_readAck(); //Read 1 byte and then send ack
data_high = i2c_readAck(); //Read 1 byte and then send ack
pec = i2c_readNak();
i2c_stop();


//This converts high and low bytes together and processes temperature, MSB is a error bit and is ignored for temps
double tempFactor = 0.02; // 0.02 degrees per LSB
double tempData = 0x0000;
int frac;
// This masks off the error bit of the high byte, then moves it left 8 bits and adds the low byte.
tempData = (double)(((data_high & 0x007F) << 8) + data_low);
tempData = (tempData * tempFactor)-0.01;
tempData = tempData - 273.15;
Serial.print((int)tempData); //Print temp in degrees C to serial
Serial.print(".");
tempData=tempData-(int)tempData;
frac=tempData*100;
Serial.println(frac);
delay(100);
}

The above is CalculusAE's code, with a line added to enable the pullups in the Arduino. It spits out a temperature

to the nearest C degree every second. It was a bit of a tooth-pull to get this device to talk, and this code is not

taking advantage of the capabilities of the device, but it does work, which I wanted to prove to myself before

goofing with getting more accuracy. I stripped most of the comments out to get it to post. You really should look

at the code with comments. I think there is a type conversion error that limits the output to integers. I'll let

y'all know if I figure it out.
By lee810
#127945
Like others who tried the Wire.h library, I found that this device doesn't work at all, it just delivers 0xFF whenever you try to read from it.

When I tried using the i2cmaster.h library instead of Wire.h, my Arduino would hang. Nothing would even come out on the Serial.print unless I commented out the #include <i2cmaster.h> line.

The zip file from Peter Fleury's website includes several other files in the i2cmaster folder. After I removed all the files EXCEPT the i2cmaster.h and the modified twimaster.cpp (which had been renamed from twimaster.c) from the i2cmaster folder in the library, then it began to work.