Other Parts Discussed in Thread: TMP75
Hello Friends
I am working on a project in which I have to read temperature so I am using Tmp75 for that which is on my I2c line of controller Tm4c129dncpdt.
I am doing according to the data sheet of the Ic So do I think and taking the msb and lsb value and getting the temperature correctly but some times it is not that frequent I am getting msb as zero suddenly and some times 0x80 suddenly. I am not sure this because of the temp Ic or the I2c configuration which I am doing. Below is the code which I have used in my confguration
The above is Initialisation
void Temp_Sensor_init(void)
{
SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C0);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
GPIOPinConfigure(GPIO_PB2_I2C0SCL);
GPIOPinConfigure(GPIO_PB3_I2C0SDA);
//Configure pin for use as SCL by the I2C peripheral
GPIOPinTypeI2CSCL(GPIO_PORTB_BASE,GPIO_PIN_2);
//Configure SDA pin for use by the I2C peripheral.
GPIOPinTypeI2C(GPIO_PORTB_BASE,GPIO_PIN_3);
// Set I2C Clock to 100Khz
I2CMasterInitExpClk(I2C0_BASE,g_ui32SysClock, false);
I2CMasterEnable(I2C0_BASE);
ROM_SysCtlDelay(10000);
//Initialinsing for 12bit resolution
I2CMasterSlaveAddrSet(I2C0_BASE, 0x4F, false);
I2CMasterDataPut(I2C0_BASE, 0x01);
I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_SEND_START);
while(I2CMasterBusy(I2C0_BASE))
{
}
I2CMasterDataPut(I2C0_BASE, 0x60);
I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_SEND_FINISH);
while(I2CMasterBusy(I2C0_BASE))
{
}
I2CMasterSlaveAddrSet(I2C0_BASE, 0x4F, false);
I2CMasterDataPut(I2C0_BASE, 0);
I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_SINGLE_SEND);
while(I2CMasterBusy(I2C0_BASE))
{
}
And below function I am calling it in cyclic
void Temp_Read_Config(uint8_t slave,uint8_t reg)
{
uint8_t data[4] = {0};
uint32_t main_data = 0;
uint8_t byte = 0;
float raw_value = 0;
I2CMasterSlaveAddrSet(I2C0_BASE, slave, true);
while(I2CMasterBusy(I2C0_BASE));
I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_RECEIVE_START);
while(I2CMasterBusy(I2C0_BASE));
byte = I2CMasterDataGet(I2C0_BASE);
data[0] = byte;
UARTprintf("Higr : %x\r\n",byte);
I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_RECEIVE_FINISH);
while(I2CMasterBusy(I2C0_BASE));
ROM_SysCtlDelay(10);
byte = 0;
byte = I2CMasterDataGet(I2C0_BASE);
data[1] = byte;
data[1] = data[1] & 0xF0;
data[1] = data[1] >> 4;
UARTprintf("lower : %x\r\n",byte);
main_data = (data[0] << 4) | (data[1]);
raw_value = (float)(128*main_data) / 2048;
memset(temp_data,0,sizeof(temp_data));
sprintf(temp_data,"raw : %f data : %x\r\n",raw_value,main_data);
UARTprintf(temp_data);
}
}
Is their any problem regarding my i2c configuration suggest me