cancel
Showing results for 
Search instead for 
Did you mean: 

TMP102 Configuration Register Read/Write fail

rasem
Associate II

I need help to setup TMP102 alarm function. My board is NUCLEO-F439ZI

Reading the temperature is working fine.

uint8_t TMP102_ADDR = 0x48 << 1;

uint8_t REG_TEMP = 0x00;

uint8_t buf[12];

buf[0] = REG_TEMP;

ret = HAL_I2C_Master_Transmit(&hi2c2, 0x90, buf, 1, 10);    // OK

ret = HAL_I2C_Master_Transmit(&hi2c2, 0x90, 0x00, 1, 10);   //OK

ret = HAL_I2C_Master_Receive(&hi2c2, 0x90, buf, 2 , 10);    //OK

reads the temperature correctly. Buf[0] and buf[1]has correct temperature data.

 

I am trying to setup the alarm function. Reading/writing the Limit registers are failing.

Datasheet states that Thigh=80C, and Tlow=70C. After Reset.

I am reading the Thigh registers, with the following code:

uint8_t reghi = 0x03;

ret = HAL_I2C_Master_Transmit(&hi2c2, TMP102_ADDR, reghi, 1, 10); // fail

is sending 0x00 on reghi. I verified by scope.

ret = HAL_I2C_Master_Transmit(&hi2c2, TMP102_ADDR, 0x03, 1, 10);  //fail     

it is sending 0x00 to configuration register.

The only way to send the right value accomplished by:

Unit8_t reghi = 0x03;

buf[0] = reghigh;

ret = HAL_I2C_Master_Transmit(&hi2c2, TMP102_ADDR, buf, 1, 10); OK.

Sending 0x03 to select the Thigh register. Verified by scope.

 

Now I want to read the value of Thigh.

ret = HAL_I2C_Master_Receive(&hi2c2, TMP102_ADDR, buf, 2 , 100);

The value in buf[0] = 0x00;

The value in buf{1] = 0x00;

I verified it in Debug mode.

 

The same problem when I write two bytes to Thigh and read it back

It gives 0x00 for both bytes.

If anybody tried to set the alarm successfully in TMp102, please help.

Thanks,

Rasem

1 ACCEPTED SOLUTION

Accepted Solutions

Hi Rasem

try this:

change 

 

 

temphi[0] = 0x1A;

temphi[1] = 0x00; // set high temp alarm at 26C.
to 
temphi[1] = 0x1A;

temphi[0] = 0x00; // set high temp alarm at 26C.

 

better

 

 

uint8_t temphi[3]= {0};
temphi[0] = 0x03; // register
temphi[1] = 0x00; // HiByte
temphi[2] = 0x1A; // LowByte

ret = HAL_I2C_Master_Transmit(&hi2c2, TMP102_ADDR, temphi,3, 100);

 

 

Hint: An array is always passed as an address.

 

hth

padawan

 

View solution in original post

4 REPLIES 4

Yeah, because it want a POINTER, the address of variable, and not the number/constant itself..

uint8_t reghi = 0x03;

ret = HAL_I2C_Master_Transmit(&hi2c2, TMP102_ADDR, reghi, 1, 10); // fail

is sending 0x00 on reghi. I verified by scope.

ret = HAL_I2C_Master_Transmit(&hi2c2, TMP102_ADDR, 0x03, 1, 10);  //fail     

it is sending 0x00 to configuration register.

The only way to send the right value accomplished by:

 

uint8_t reghi = 0x03;
ret = HAL_I2C_Master_Transmit(&hi2c2, TMP102_ADDR, (void *)&reghi, 1, 10); // pass via pointer
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
rasem
Associate II

Hi Tesla DeLorean,

Thank you very much for your quick reply. It was great. I am able to read the High Temperature setting of

80C correctly.

I still need your help setting my own limits:

The following did not work.

uint8_t reghi = 0x03;

uint8_t  temphi[2];

uint8_t lowlimit [2];

temphi[0] = 0x1A;

temphi[1] = 0x00; // set high temp alarm at 26C.

 

ret = HAL_I2C_Master_Transmit(&hi2c2, TMP102_ADDR, (void *)&reghi, 1, 10); //OK

ret = HAL_I2C_Master_Transmit(&hi2c2, TMP102_ADDR, (void*)&temphi,2, 100);

ret = HAL_I2C_Master_Receive(&hi2c2, TMP102_ADDR, lowlimit, 2 , 100);

// reads lowlimit[0]=0x00, lowlimit[1]=0x00

 

Coffee on it's way.Thanks.

Rasem

 

 

 

 

Hi Rasem

try this:

change 

 

 

temphi[0] = 0x1A;

temphi[1] = 0x00; // set high temp alarm at 26C.
to 
temphi[1] = 0x1A;

temphi[0] = 0x00; // set high temp alarm at 26C.

 

better

 

 

uint8_t temphi[3]= {0};
temphi[0] = 0x03; // register
temphi[1] = 0x00; // HiByte
temphi[2] = 0x1A; // LowByte

ret = HAL_I2C_Master_Transmit(&hi2c2, TMP102_ADDR, temphi,3, 100);

 

 

Hint: An array is always passed as an address.

 

hth

padawan

 

rasem
Associate II

Hi Padawan.

Great solution. It is working now after sending 3 bytes togther.

Thank you very much.

Rasem