Reading temperature from Microchip TC74 with AVR ATmega328P via I2C

Hi, I tried stepping a little bit down the stack and use a bare ATmega 328P for a temperature sensor.

I’m using a bare ATmega328P chip clocked at 8MHz to communicate over I2C/TWI with Microchip TC74A2-5.0V on a breadboard with jumper wires. The TWBR is set at 42 which should give 80kHz (tried 32 for 100kHz) as well. Any command I’m trying to send ends ups with TW_STATUS equal 0x20 which I understand is slave address + WR bit sent, but no acknowledge received. I even tried iterating over all addresses available but every time with the same result. The chip has 100nF capacitors, and SDA and SCL are pulled up with 10kOhm resistors.

I read TC74 spec over and over again and I just don’t get what’s wrong.

The code uses i2c_master library from
I’m using this library because I’m writing everything in C and it’s much easier to understand for me than Arduino Wire library and the twi C code used within, which is based on ISR.

uint8_t dataReceivedCfg[1] = {0};
uint8_t dataEnable[1] = {TC74_STBY_NORMAL << TC74_CFGREG_STANDBY};
uint8_t dataReceivedTemp[1] = {0};
uint8_t a = 1;

while(a < 0x80) {
i2c_readReg(a << 1, TC74_CMD_RW_CONFIG, dataReceivedCfg, 1);
i2c_writeReg(a << 1, TC74_CMD_RW_CONFIG, dataEnable, 1);
i2c_readReg(a << 1, TC74_CMD_READ_TEMP, dataReceivedTemp, 1);

I got a reading from TC74 only once with hundreds of attempts.

Any help or suggestions would be welcome. Thanks.

This TC74 library for Ardunio has worked well for me in the past;

Thanks, but the reason I used this library and not Wire from Arduino is the fact that I'm already running low on memory because of all the debug strings I'm printing to myself (I should be using PROGMEM probably). Wire (which is used by the library you linked to) is already a big C++ object constructed on top of C twi library, which further still includes avr/twi.h. That's a lot of stuff to understand, and I don't just want to use libraries not knowing what's going on. And currently I know only some C (I haven't used C++ for years) and I want to manage one language at a time.

Perhaps I will need to drop all libraries and simplify my code. I'm scared how much space sprintf() takes :wink:

Okay, do you have any option to expand the memory? I guess, many issues will be solved once you expand the memory mybpcreditcard