我可以在其他地方初始化并仅在低温环境中
// main_rtos
Board_init();
GPIO_init();
I2C_init();
GPIO_setConfig(CONFIG_GPIO_LED_0, GPIO_CFG_OUT_STD | GPIO_CFG_OUT_LOW);
#ifdef CONFIG_GPIO_TMP_EN
GPIO_setConfig(CONFIG_GPIO_TMP_EN, GPIO_CFG_OUT_STD | GPIO_CFG_OUT_HIGH);
/* Allow the sensor to power on */
sleep(1);
#endif
/* Set priority and stack size attributes */
//...
// tcpecho.c
void static i2c0 (void){
uint16_t sample;
int16_t temperature;
uint8_t txBuffer[1];
uint8_t rxBuffer[2];
int8_t i;
I2C_Handle i2c;
I2C_Params i2cParams;
I2C_Transaction i2cTransaction;
/* Call driver init functions */
//Display_init();
//GPIO_init();
I2C_init();
/* Configure the LED and if applicable, the TMP_EN pin */
// GPIO_setConfig(CONFIG_GPIO_LED_0, GPIO_CFG_OUT_STD | GPIO_CFG_OUT_LOW);
#ifdef CONFIG_GPIO_TMP_EN
GPIO_setConfig(CONFIG_GPIO_TMP_EN, GPIO_CFG_OUT_STD | GPIO_CFG_OUT_HIGH);
/* Allow the sensor to power on */
sleep(1);
#endif
/* Turn on user LED */
GPIO_write(CONFIG_GPIO_LED_0, CONFIG_GPIO_LED_ON);
Display_printf(display, 0, 0, "Starting the i2ctmp example\n");
/* Create I2C for usage */
I2C_Params_init(&i2cParams);
i2cParams.bitRate = I2C_400kHz;
i2c = I2C_open(CONFIG_I2C_TMP, &i2cParams);
if (i2c == NULL)
{
Display_printf(display, 0, 0, "Error Initializing I2C\n");
while (1) {}
}
else
{
Display_printf(display, 0, 0, "I2C Initialized!\n");
}
/* Common I2C transaction setup */
i2cTransaction.writeBuf = txBuffer;
i2cTransaction.writeCount = 1;
i2cTransaction.readBuf = rxBuffer;
i2cTransaction.readCount = 0;
/*
* Determine which I2C sensors are present by querying known I2C
* target addresses.
*/
for (i = TMP_COUNT - 1; i >= 0; i--)
{
i2cTransaction.targetAddress = sensors[i].address;
txBuffer[0] = sensors[i].resultReg;
if (I2C_transfer(i2c, &i2cTransaction))
{
targetAddress = sensors[i].address;
Display_printf(display,
0,
0,
"Detected TMP%s sensor with target"
" address 0x%x",
sensors[i].id,
sensors[i].address);
}
else
{
i2cErrorHandler(&i2cTransaction, display);
}
}
/* If we never assigned a target address */
if (targetAddress == 0)
{
Display_printf(display, 0, 0, "Failed to detect a sensor!");
I2C_close(i2c);
while (1) {}
}
Display_printf(display, 0, 0, "\nUsing last known sensor for samples.");
i2cTransaction.targetAddress = targetAddress;
/* Take 3 samples and print them out onto the console */
i2cTransaction.readCount = 2;
for (sample = 0; sample < 3; sample++)
{
if (I2C_transfer(i2c, &i2cTransaction))
{
/*
* Extract degrees C from the received data;
* see TMP sensor datasheet
*/
temperature = (rxBuffer[0] << 8) | (rxBuffer[1]);
temperature *= 0.0078125;
Display_printf(display, 0, 0, "Sample %u: %d C", sample, temperature);
}
else
{
i2cErrorHandler(&i2cTransaction, display);
}
/* Sleep for 1 second */
sleep(1);
}
I2C_close(i2c);
Display_printf(display, 0, 0, "I2C closed!");
}
许多没有被删除的尝试似乎都失败了。 在如此微小的故障下,我似乎使用 platform.c 中的主机名而不是固定的 IP 地址,从而使路由器和/或本地 AP 受到困扰。 我想这应该是另一个问题。