Where best to write to a sensor register in the sensor template

Dear xtca-support,

We (ATLAS L1Calo) have Texas Instruments LM82 temperature sensors on some of our modules. These feature a T_CRIT register which allows to prevent the full payload voltage being applied to the module if the temperature is exceeded. The datasheet gives the read/write addresses as 0x42/0x5Ah and the power up default is 127 degrees. We would like to set a lower temperature and, indeed, our former colleague implemented it using version 1.2 and a self build but we don’t have the access to his work, unfortunately.

So, as a first re-implementation, using v1.31 and the remote compile.py method I put the following in the initialize sensor function.

unsigned char initialize_sensor_lm82(unsigned short i2c_addr, unsigned short reg){
// set the critical temperature - register is 0x42/0x5A for read/write
if (reg==0x42) {
unsigned char data[1]={0x5F}; // set critical temp to 95 degrees
unsigned short tcritwreg=0x5A;
return i2c_dev_write_reg(i2c_addr, tcritwreg, &data[0], 1);
return 0x00;

So this does display 95 degrees on the read but it is still somehow triggering the interrupt and payload power is disabled even when the board is activated. My only idea is that this is the wrong function to be using (writing too often?) and such operations should be done elsewhere. If you have some advice, indeed, even the previous recommendation that would be great? Apologies for re-asking for this information.