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.

TMP75 connection with LM4F232H5QD

Other Parts Discussed in Thread: TMP75, TMP175

Hi,

I have connected TMP75 with microcontroller LM4F232H5QD; anyone having sample code?

Following code I have written to read the TMP75 register, please review:

// Connections:

//! - I2C0SCL - PB2
//! - I2C0SDA - PB3

// A0, A1 and A2 is connected to ground

#define SLAVE_ADDRESS   0x90

// -------------------------------------------------------------------------------------------------------------------------------------------

void
I2CMasterReadReg(unsigned long ulBase, unsigned char ucReg, unsigned char *ucData)
{
    //
    // Check the arguments.
    //
//    ASSERT(I2CMasterBaseValid(ulBase));

    // Initiate the START condition by pulling the data line SDA from HIGH to LOW
    // and the SCL is set to high
    // SCL is on PB2 and SDA is on PB3
    GPIO_PORTB_DATA_R &= ~(0x08); // Set SDA (PB3) from HIGH to LOW
    GPIO_PORTB_DATA_R |= (0x04); // Set SCL (PB2) to HIGH

    // Accessing a particular register on the TMP175 and TMP75 is accomplished by writing
    // the appropriate value to the Pointer Register. The value for the Pointer Register is the
    // first byte transferred after the slave address byte with the R/W bit LOW.

    // Send the slave address for write operation
    HWREG(ulBase + I2C_O_MDR) = SLAVE_ADDRESS;  // Since by default last bit is low

    // Set the pointer register
    HWREG(ulBase + I2C_O_MDR) = ucReg;

    // Once all data has been transferred, the master generates a STOP condition indicated by pulling SDA from LOW to
    // HIGH, while SCL is HIGH.
    GPIO_PORTB_DATA_R |= (0x08); // Set SDA (PB3) from LOW to HIGH

    // ***********************************************************
    // Trigger the read operation by send the slave address
    //

    // Initiate the start condition
    GPIO_PORTB_DATA_R &= ~(0x08); // Set SDA (PB3) from HIGH to LOW

    // Send the slave address for read operation
    HWREG(ulBase + I2C_O_MDR) = SLAVE_ADDRESS | 0x01;  // Since by default last bit is low

    // Read the most significant byte from the slave
    *(ucData + 1) = HWREG(ulBase + I2C_O_MDR);
    // Read the least significant byte from the slave
    *ucData = HWREG(ulBase + I2C_O_MDR);

    // Trigger the STOP condition
    GPIO_PORTB_DATA_R |= (0x08); // Set SDA (PB3) from LOW to HIGH
    // ************************************************************
}

// -------------------------------------------------------------------------------------------------------------------------------------------

Thanks in advance.

Best regards,

Praveen

  • You may benefit from search here - past I2C questions/answers.

    Code posted has (pardon) no chance.  Stellaris team did include fully functional I2C implementation - w/numerous examples - may warrant some slight review...

     // Initiate the START condition by pulling the data line SDA from HIGH to LOW
        // and the SCL is set to high
        // SCL is on PB2 and SDA is on PB3
        GPIO_PORTB_DATA_R &= ~(0x08); // Set SDA (PB3) from HIGH to LOW
        GPIO_PORTB_DATA_R |= (0x04); // Set SCL (PB2) to HIGH

    You are (or should be) aware that StellarisWare automatically handles/manages all of this low-level detail.  Any "intermix" is unlikely to "end well..."


    And - from memory - did not Eval board (bearing that exact MCU) have a very similar temp sensor IC "on board" - with full code provided?  Seems obvious & superior path  to this reporter...