主题中讨论的其他器件: TMP75
你好朋友
我正在处理一个项目、其中我必须读取温度、因此我使用 Tmp75、该项目位于控制器 Tm4c129dncpdt 的 I2C 线路上。
根据 IC 的数据表、我想获取 MSB 和 lsb 值并正确获取温度、但有时我不会经常将 MSB 设置为零、有时会突然设置为0x80。 我不确定这是因为我正在执行的温度 IC 或 I2C 配置。 下面是我在配置中使用的代码
以上是初始化
void Temp_Sensor_init (void)
{
SysCtlPeripheralEnable (SYSCTL_Periph_I2C0);
SysCtlPeripheralEnable (SYSCTL_Periph_GPIOB);
GPIOPinConfigure (GPIO_PB2_I2C0SCL);
GPIOPinConfigure (GPIO_PB3_I2C0SDA);
//配置引脚以用作 I2C 外设的 SCL
GPIOPinTypeI2CSCL (GPIO_PORTB_BASE、GPIO_PIN_2);
//配置 SDA 引脚供 I2C 外设使用。
GPIOPinTypeI2C (GPIO_PORTB_BASE、GPIO_PIN_3);
//将 I2C 时钟设置为100kHz
I2CMasterInitExpClk (I2C0_BASE、g_ui32SysClock、false);
I2CMasterEnable (I2C0_BASE);
ROM_SysCtlDelay (10000);
//针对12位分辨率初始化
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))
{
}
在函数下面、我将以循环方式调用它
void Temp_read_Config (uint8_t 从器件、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));
字节= I2CMasterDataGet (I2C0_BASE);
DATA[0]=字节;
UARTprintf ("Hr:%x\r\n"byte);
I2CMasterControl (I2C0_BASE、I2C_MASTER_CMD_BURST_Receive_finish);
while (I2CMasterBusy (I2C0_BASE));
ROM_SysCtlDelay (10);
字节= 0;
字节= I2CMasterDataGet (I2C0_BASE);
DATA[1]=字节;
DATA[1]= DATA[1]和0xF0;
数据[1]=数据[1]>> 4;
UARTprintf ("较低:%x\r\n"、字节);
MAIN_DATA =(DATA[0]<< 4)|(DATA[1]);
raW_value =(float)(128*MAIN_DATA)/2048;
memset (temp_data、0、sizeof (temp_data));
sprintf (temp_data、"原始:%f data:%x\r\n"、raW_value、main_data);
UARTprintf (temp_data);
}
}
我认为他们在 i2c 配置方面有什么问题