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.

MSP430F6721: I2C Write to TMP007

Part Number: MSP430F6721
Other Parts Discussed in Thread: MSP430WARE

I'm using the MSP430F6721 to communicate with TI's TMP007 temperature sensor using I2C and TI's driverlib.  I can read important data from the TMP007 (thermopile voltage, die temperature, calibrated temperature), but I cannot reliably write data to it.  When I try to write to the TMP007 (to the configuration register, or to one of the coefficient registers) I get a partial write, where the register address is missing.

I previously asked for feedback on my I2C write-then-read function, which works wonderfully.

Here is my I2C write function.

/**************************************************************************//**
 * @brief       Write to  TMP007 Register using I2C.
 * @param[in]   address - I2C device address
 * @param[in]   reg - TMP007 register to act upon
 * @param[in]   data - data to write to the TMP007 chip
 * @retval      true for success; false otherwise
 *****************************************************************************/
static bool tempWriteReg (uint8_t address, uint8_t reg, _q4_t data)
{
    bool result = false;                // pessimistic return value
    uint8_t temp[2] = {0,0};            // data to send over I2C

    // Form the message.
    temp[0] = (uint8_t)(data >> 8);
    temp[1] = (uint8_t)(data & 0x00FF);

    do  // This structure will handle errors nicely.
    {
        // Set the slave address of the sensor we wish to talk to.
        EUSCI_B_I2C_setSlaveAddress(I2C_BASEADDR, address);

        // Set write mode.
        EUSCI_B_I2C_setMode(I2C_BASEADDR, EUSCI_B_I2C_TRANSMIT_MODE);

        // Pat the watchdog before while loops in the following functions.
        watchdog_update();

        // Write the register to the sensor.
        // Send START + address, followed by 3 byte message, followed by STOP.
        result = EUSCI_B_I2C_masterSendMultiByteStartWithTimeout(I2C_BASEADDR, reg, TEMP_TIMEOUT);
        if (result == false)
            break;

        result = EUSCI_B_I2C_masterSendMultiByteNextWithTimeout(I2C_BASEADDR, temp[0], TEMP_TIMEOUT);
        if (result == false)
            break;

        result = EUSCI_B_I2C_masterSendMultiByteFinishWithTimeout(I2C_BASEADDR, temp[1], TEMP_TIMEOUT);
    } while (false);

    return result;
}

Below is a capture of I2C data when executing the following three lines of code, using a Saleae Logic protocol analyzer.

#define TMP007_ADDRESS 0x40    // 7-bit address of sensor

#define TMP007_REG_S0 0x0A    // S0 Coefficient Register
#define TMP007_REG_B0 0x0D    // B0 Coefficient Register
#define TMP007_REG_B1 0x0E    // B1 Coefficient Register

tempWriteReg(TMP007_ADDRESS, S0_COEFF_REG_ADDR, 0x0DC9);
tempWriteReg(TMP007_ADDRESS, B0_COEFF_REG_ADDR, 0xFF32);
tempWriteReg(TMP007_ADDRESS, B1_COEFF_REG_ADDR, 0xFA78);

Green dots indicates a start condition; red dots indicate a stop condition.  The blue waveform is the analog waveform on the bus.  As you can see, while there should be four bytes in each transaction, there are only three bytes in the 2nd and 3rd transaction.

Am I doing something obviously wrong?  Also, is there an I2C example for the MSP430F6721 that uses driverlib?  I was unable to find one in MSP430ware.

  • Hello Adam,

    Have you seen the following application note? It should help you with some debugging effort with I2C in the future. www.ti.com/.../slaa734

    That being said, from looking at your logic analyzer screenshot, particularly the analog signal levels, I would say that you do not have sufficient pull-ups on your I2C lines. It seems you have too much capacitance on the line and a stronger pull-up is needed for proper communication.
  • FYI, for this project, I ended up just resetting the I2C driver after each write of the TMP007. A dirty hack, but in my case it worked well enough.

    I2C pullup resistors used in my circuit were sized correctly...I had a slow sampling rate selected in the oscilloscope, and that was responsible for the poor-looking waveform.

    Adam J.

**Attention** This is a public forum