View previous topic :: View next topic |
Author |
Message |
diegonet
Joined: 13 Sep 2005 Posts: 4
|
LM75A and i2c |
Posted: Tue Sep 13, 2005 11:21 pm |
|
|
Hi people!
I'm trying to put to work an LM75A and a 16F88.
My problem is that I have realized that i don't know anything about the i2c implementation of CCS.
In the datasheet of LM75A is stated that the default register is the TEMP reg, that contains the 16 bit's to read (11 actually).
So, I hard wired the address pins to 0, then the address must be 72 decimal (1001 is hard wired in the chip).
Back to C code, I wrote:
i2c_start(1);
i2c_write(72);
data1 = i2c_read();
delay_ms(100);
data2 = i2c_read(0);
delay_ms(100);
i2c_stop();
Ok, the delay's are simple especulation...
The values in data are always 255 decimal...
Any help? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
Ttelmah Guest
|
|
Posted: Wed Sep 14, 2005 4:09 am |
|
|
One obvious comment though on the attempt posted. The address byte sent, also contains the data direction flag as the bottom bit. An 'even' address, will imply a data write, not a data read. An address needs to have one added, to enable reading.
It might well work with the address set to 73.
Best Wishes |
|
|
Barney
Joined: 18 Oct 2004 Posts: 41 Location: Newark, CA
|
|
Posted: Thu Sep 15, 2005 2:35 pm |
|
|
I found the CCS I2C routines very easy to use. I used a 16F88 to get temperature info from a AD7614 using the following routine:
Code: |
addr = 0x90 | (snsr_addr << 1);//build 7 bit address
addr |= 0x01; //set read bit
i2c_start();
i2c_write(addr);
high = i2c_read();
low = i2c_read(0);
i2c_stop();
|
All I2C parts have a 7 bit address and for the AD7416 the first 4 bits are 0101 (ie 0x90). The AD7614 has a 3 bit address range so snsr_addr is the address (0 thru 7) of the chip I want. The address LSB is the read/write direction flag. There are two reads because the chip returns two bytes of temperature data.
My biggest problem with I2C is remembering to put in the pull up resistor. |
|
|
|