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