Other Parts Discussed in Thread: TMP117
Hi there
I would like to read a register from the TI temperature sensor TMP117 with my microcontroller. The picture below shows the desired behavior:
Here is my init()-function. As I see some behavior on the I2C-Lines, I guess it works.
void I2C_init(void)
{
// Enable the I2C0 peripheral
MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C1);
I2CMasterEnable(I2C1_BASE);
SysCtlPeripheralReset(SYSCTL_PERIPH_I2C1);
SysCtlPeripheralReset(SYSCTL_PERIPH_I2C1);
// Wait for the I2C0 module to be ready.
while(!SysCtlPeripheralReady(SYSCTL_PERIPH_I2C1))
{
}
MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
// Configure the GPIO Pin Mux for PA6 for I2C1SCL
MAP_GPIOPinConfigure(GPIO_PA6_I2C1SCL);
MAP_GPIOPinTypeI2CSCL(GPIO_PORTA_BASE, GPIO_PIN_6);
// Configure the GPIO Pin Mux for PA7 for I2C1SDA
MAP_GPIOPinConfigure(GPIO_PA7_I2C1SDA);
MAP_GPIOPinTypeI2C(GPIO_PORTA_BASE, GPIO_PIN_7);
// Initialize Master and Slave
I2CMasterInitExpClk(I2C1_BASE, SysCtlClockGet(), false);
while(I2CMasterBusBusy(I2C1_BASE))
{
}
}
With the following code i want to:
- Send the slave address
- Send the register pointer
- read two Bytes
uint32_t I2C_readThisRegister()
{
uint8_t slaveAddress = 0b10010010;
uint32_t registerToRead = 0x00001111;
//------WRITE-Section----------------------------------------
I2CMasterSlaveAddrSet(I2C1_BASE, slaveAddress, false);
I2CMasterDataPut(I2C1_BASE, registerToRead);
I2CMasterControl(I2C1_BASE, I2C_MASTER_CMD_BURST_SEND_START);
while(I2CMasterBusBusy(I2C1_BASE))
{
}
//------READ-Section----------------------------------------
I2CMasterSlaveAddrSet(I2C1_BASE, slaveAddress, true); // set slave address
//read first Byte
I2CMasterControl(I2C1_BASE, I2C_MASTER_CMD_BURST_RECEIVE_CONT);
while(I2CMasterBusBusy(I2C1_BASE))
{
}
uint32_t msb=I2CMasterDataGet(I2C1_BASE);
//read second Byte
I2CMasterControl( I2C1_BASE, I2C_MASTER_CMD_BURST_RECEIVE_FINISH);
while(I2CMasterBusBusy(I2C1_BASE))
{
}
uint32_t lsb=I2CMasterDataGet(I2C1_BASE);
return ((msb << 8)| lsb);
}
The oscilloscope shows that only the WRITE part is executed. The clock is not working in the READ part. It looks like the READ part is ignored.
I have already tried different variants, but I can't get the values to be read in.
PS: The addresses in the example are not especially useful. As soon as the I2C interface works properly, I will add the code so that it drives the sensor correctly.
Thank you for your help! It is much appreciated!
Best regards
Patrik