Hello everyone,
this should be a fairly easy question for you guys, just need advice on the best way for I2C thermal sensor read with TM4CAE6PM. The system clock is set to 80MHz, but the main loop is spinning at freq of 1kHz, it is more than enough for this system (Timer 0 is used to regulate this). I want to read this I2C value 8 samples per second that means, if I am correct 8Hz cycle to read this data, I used Timer 2 for this on Timer2_ISR I read thermal sensor value and convert it to degrees. Below is the I2C configuration as well as this interrupt of Timer2 which is used to read the data. Is there some other way to do this that would be more acceptable or less processor consuming?
void I2C_Configuration()
{
SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C0);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
GPIOPinConfigure(GPIO_PB2_I2C0SCL);
GPIOPinConfigure(GPIO_PB3_I2C0SDA);
GPIOPinTypeI2CSCL(GPIO_PORTB_BASE, GPIO_PIN_2);
GPIOPinTypeI2C(GPIO_PORTB_BASE, GPIO_PIN_3);
I2CMasterInitExpClk(I2C0_BASE, SysCtlClockGet(), false);
I2CMasterSlaveAddrSet(I2C0_BASE, TC74_ADDRESS, false);
I2CMasterDataPut(I2C0_BASE, READ_TEMP_CMD);
I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_SINGLE_SEND);
while(I2CMasterBusy(I2C0_BASE))
{
}
}
void Timer2_ISR(void)
{
TimerIntClear(TIMER2_BASE, TIMER_TIMA_TIMEOUT);
I2CMasterSlaveAddrSet(I2C0_BASE, TC74_ADDRESS, true);
I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_SINGLE_RECEIVE);
ui32_I2C_DataRx = I2CMasterDataGet(I2C0_BASE);
ConvertToValidTempValue();
flag_thermal_sens_read=true;
}