This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Problem reading second byte correctly over I2C between TMP275 and MSP430F6736 using driverlib

Other Parts Discussed in Thread: TMP275, MSP430F6736
Hi,
I am having trouble getting data correctly from a TMP275 sensor using an MSP430F6736 over I2C. I am using driverlibs.
For your reference, here is my initialization code:
GPIO_setAsPeripheralModuleFunctionOutputPin(SENSOR_SCL_PORT, SENSOR_SCL_PIN);
GPIO_setAsPeripheralModuleFunctionOutputPin(SENSOR_SDA_PORT, SENSOR_SDA_PIN);

EUSCI_B_I2C_initMasterParam param = { 0 };
param.selectClockSource = EUSCI_B_I2C_CLOCKSOURCE_SMCLK;
param.i2cClk = UCS_getSMCLK();
param.dataRate = EUSCI_B_I2C_SET_DATA_RATE_100KBPS;
param.byteCounterThreshold = 0;
param.autoSTOPGeneration = EUSCI_B_I2C_NO_AUTO_STOP;

EUSCI_B_I2C_initMaster(EUSCI_B0_BASE, &param);
EUSCI_B_I2C_enable(EUSCI_B0_BASE);

This is how I configure it to give 12-bit data instead of 9-bit default:
EUSCI_B_I2C_setMode(EUSCI_B0_BASE, EUSCI_B_I2C_TRANSMIT_MODE); // Set master in Tx mode
EUSCI_B_I2C_setSlaveAddress(EUSCI_B0_BASE, SENSOR_I2C_ADDR);
__delay_cycles(50);
successOrFailure = EUSCI_B_I2C_masterMultiByteSendStartWithTimeout(EUSCI_B0_BASE, SENSOR_I2C_CONF_REGISTER_PTR, SENSOR_I2C_TIMEOUT);
if (!successOrFailure) return STATUS_FAIL;
successOrFailure = EUSCI_B_I2C_masterMultiByteSendNextWithTimeout(EUSCI_B0_BASE, (SENSOR_CONF_R0_BIT | SENSOR_CONF_R1_BIT | SENSOR_CONF_TM_BIT | SENSOR_CONF_POL_BIT), SENSOR_I2C_TIMEOUT);
if (!successOrFailure) return STATUS_FAIL;
successOrFailure = EUSCI_B_I2C_masterMultiByteSendStopWithTimeout(EUSCI_B0_BASE, SENSOR_I2C_TIMEOUT);
return successOrFailure;

This returns successfully every time.
This is how I get the data (2 bytes to be read, and the 4 LSBs are always zero, and in case of 9-bit reading, 7 LSBs are zero):
RxDataHi = 0;
RxDataLo = 0;
EUSCI_B_I2C_setMode(EUSCI_B0_BASE, EUSCI_B_I2C_TRANSMIT_MODE); // Set master in Tx mode
EUSCI_B_I2C_setSlaveAddress(EUSCI_B0_BASE, SENSOR_I2C_ADDR);
__delay_cycles(50);
successOrFailure = EUSCI_B_I2C_masterMultiByteSendStartWithTimeout(EUSCI_B0_BASE, SENSOR_I2C_TEMP_REGISTER_PTR, SENSOR_I2C_TIMEOUT);
successOrFailure = EUSCI_B_I2C_masterMultiByteSendStopWithTimeout(EUSCI_B0_BASE, SENSOR_I2C_TIMEOUT);
__delay_cycles(50);
EUSCI_B_I2C_setMode(EUSCI_B0_BASE, EUSCI_B_I2C_RECEIVE_MODE); // Set master in Rx mode
__delay_cycles(2000);
EUSCI_B_I2C_masterReceiveStart(EUSCI_B0_BASE);
RxDataHi = EUSCI_B_I2C_masterMultiByteReceiveNext(EUSCI_B0_BASE);
RxDataLo = EUSCI_B_I2C_masterMultiByteReceiveFinish(EUSCI_B0_BASE);
return ((RxDataHi << 8) | (RxDataLo));

Here, RxDataHi is always good. But, RxDataLo is a repetition of RxDataHi. (RxDataLo == RxDataHi).
I can confirm that the RxDataHi corresponds to the temperature on the sensor and changes correctly when we change the temperature the sensor is exposed to!
Can somebody please guide!
Regards,
Anup
  • Got it working with this code in the receive section:

    RxDataHi = 0;
    RxDataLo = 0;
    EUSCI_B_I2C_setMode(EUSCI_B0_BASE, EUSCI_B_I2C_TRANSMIT_MODE); // Set master in Tx mode
    EUSCI_B_I2C_setSlaveAddress(EUSCI_B0_BASE, SENSOR_I2C_ADDR);
    __delay_cycles(50);
    successOrFailure = EUSCI_B_I2C_masterMultiByteSendStartWithTimeout(EUSCI_B0_BASE, SENSOR_I2C_TEMP_REGISTER_PTR, SENSOR_I2C_TIMEOUT);
    __delay_cycles(50);
    EUSCI_B_I2C_masterReceiveStart(EUSCI_B0_BASE);
    RxDataHi = EUSCI_B_I2C_masterSingleReceive(EUSCI_B0_BASE);
    EUSCI_B_I2C_masterMultiByteReceiveStop(EUSCI_B0_BASE);
    RxDataLo = EUSCI_B_I2C_masterSingleReceive(EUSCI_B0_BASE);
    return ((RxDataHi << 8) | (RxDataLo));
    

    Sending "STOP" before receiving the last byte was the key!
  • Just curious, what do you have SENSOR_I2C_TIMEOUT defined as?

  • I was using 10000. But, now I have moved to a complete interrupt based system, with a timeout (selectable) implemented on a hardware timer.

    This works beautifully for my purposes! But, the sequence of I2C commands is the same.

**Attention** This is a public forum