MCP9804 Software issues

Thread Starter

d333b

Joined Nov 1, 2010
2
Hi all,

So I have been working a project for the home for a while. It is going to be a snake cage controller (for my red tail). In this project I was hoping to utilize I2C and the MCP9804 (for its accuracy). I have successfully used my 18f4550 to talk to EEPROMs via the I2C, but I seem to be having a large issue with this temp sensor. I have verified that all the pins are where they are supposed to be (no shorts or opens).

The situation:

Using the C18 provided CDC COM port emulator and my/microchips 18f4550 software I have been polling this chip with read commands (thru a LabVIEW interface). The results are bizarre. My read (i2c) code is below:

Rich (BB code):
unsigned char gettemp(unsigned char chip)
{
char arr[2];
unsigned char a;
IdleI2C(); 
StartI2C(); 
while ( SSPCON2bits.SEN ); 
WriteI2C( chip ); // write 1 byte 
IdleI2C(); 
WriteI2C(USB_Out_Buffer[2]); // WRITE word address to EEPROM
IdleI2C(); // ensure module is idle
 
StartI2C(); // initiate START condition
while ( SSPCON2bits.SEN ); 
// RestartI2C(); // generate I2C bus restart condition
// while ( SSPCON2bits.RSEN ); // wait until re-start condition is over 
 
WriteI2C( chip | 0x01 ); // WRITE 1 byte - R/W bit should be 1 for read
IdleI2C();
getsI2C(arr, 2);
USB_In_Buffer[0] = (arr[0] & 0x1F); //this is supposed to eliminate the register flags
USB_In_Buffer[1] = arr[1];
NotAckI2C();
while ( SSPCON2bits.ACKEN ); // wait until ACK sequence is over 
StopI2C(); // send STOP condition
while ( SSPCON2bits.PEN );//*/
a = 1;
return a;
}
The result usually winds up being 0x00FF or 0x0FFF and sometimes 0x001D and other times 0x0000. With my trusty work Oscope I can see that these results are right however sometimes the device is sending NACK(it pulls the SDA line low if that’s right). I'm really lost, I can't even get it to work using simple code to light up LEDS, it looks like the MCP9804 is NAKing after each command byte and with the 18f2221 it's just spitting back 0xFFFF (without the flag bits removed).

If anyone has worked with this aggravating chip before please let me know, or if you have a better solution for me (as a temp sensor accurate to .5dF). I would be willing to work with an ADC instead if necessary but I was going to be implementing the I2C line anyways so this looked like a perfect option for me. I would love to hear what you guys think.

p.s. the code that I spaced out and italics i was curious if a restart is the same a start? it didn't seem to make any difference, but i am curious.

TIA
 
Last edited by a moderator:

Thread Starter

d333b

Joined Nov 1, 2010
2
Hello all again,

So with some experimenting and a new serf board I have discovered that my chip does work but the length (~1ft) of ribbon cable I was using to connect to it must be introducing too much noise. When I connect the MCP9804 directly to my breadboard the program (on my 18f2221) functions perfectly, however when I separate the MCP9804 with the cable the program returns incorrect values (telling me my desk is 224dC), and then will quickly freeze (I have a second pin strobing an LED to verify proper function). I've also tried with some cat5 cable and same thing occurs. So maybe I will stick to my current set up with LM335's, and run an external ADC that is I2C. If anyone has any suggestions please share.

Thanks again.
 
Top