【MCXA156开发板测评】+P3T1755温度检测与显示
[复制链接]
本帖最后由 jinglixixi 于 2025-1-3 19:13 编辑
在MCXA156开发板上配有温度传感器P3T1755,该传感器以I2C方式工作,其电路如图1所示。
图1 传感器电路
进行传感器测试的主程序为:
int main(void)
{
status_t result = kStatus_Success;
i3c_master_config_t masterConfig;
p3t1755_config_t p3t1755Config;
double temperature;
CLOCK_SetClockDiv(kCLOCK_DivI3C0_FCLK, 4U);
CLOCK_AttachClk(kFRO_HF_DIV_to_I3C0FCLK);
BOARD_InitPins();
BOARD_InitBootClocks();
BOARD_InitDebugConsole();
PRINTF("\r\nI3C master read sensor data example.\r\n");
I3C_MasterGetDefaultConfig(&masterConfig);
masterConfig.baudRate_Hz.i2cBaud = EXAMPLE_I2C_BAUDRATE;
masterConfig.baudRate_Hz.i3cPushPullBaud = EXAMPLE_I3C_PP_BAUDRATE;
masterConfig.baudRate_Hz.i3cOpenDrainBaud = EXAMPLE_I3C_OD_BAUDRATE;
masterConfig.enableOpenDrainStop = false;
masterConfig.disableTimeout = true;
I3C_MasterInit(EXAMPLE_MASTER, &masterConfig, I3C_MASTER_CLOCK_FREQUENCY);
I3C_MasterTransferCreateHandle(EXAMPLE_MASTER, &g_i3c_m_handle, &masterCallback, NULL);
result = p3t1755_set_dynamic_address();
if (result != kStatus_Success)
{
PRINTF("\r\nP3T1755 set dynamic address failed.\r\n");
}
p3t1755Config.writeTransfer = I3C_WriteSensor;
p3t1755Config.readTransfer = I3C_ReadSensor;
p3t1755Config.sensorAddress = SENSOR_ADDR;
P3T1755_Init(&p3t1755Handle, &p3t1755Config);
while (1)
{
result = P3T1755_ReadTemperature(&p3t1755Handle, &temperature);
if (result != kStatus_Success)
{
PRINTF("\r\nP3T1755 read temperature failed.\r\n");
}
else
{
PRINTF("\r\nTemperature:%f \r\n", temperature);
}
SDK_DelayAtLeastUs(1000000, CLOCK_GetCoreSysClkFreq());
}
}
经程序的编译与下载,其测试结果如图2所示。
图2 检测效果
由此可见,P3T1755这款温度传感器的精度还是蛮高的。
|