用gd32e230的stdlib重写wbh的参考代码,并因为stm的stdlib和gd32的stdlib有很大差异,超时机制与flag验证差异较大,通过对比重新编写。

数据计算方式重新书写,两个8位数据的合并方式修改为位移,并且整体放大100倍(标准数据为((Data[1] << 8) | Data[0]) * 0.02 - 273.15)
This commit is contained in:
yelvlab 2024-10-09 10:38:39 +08:00
parent 485122c6df
commit 53fadd4c22
2 changed files with 18 additions and 14 deletions

View File

@ -56,7 +56,7 @@ int main(void)
distance_uint16 = calculate_distance(capture_value);
printf(result, distance_uint16);
printf("Temp:%d", read_ir_mlx90614());
printf("Temp:%d\n", read_ir_mlx90614());
}
}

View File

@ -19,8 +19,10 @@ void i2c_config(void) {
i2c_enable(I2C0);
i2c_ack_config(I2C0, I2C_ACK_ENABLE);
nvic_irq_enable(I2C0_EV_IRQn, 2);
nvic_irq_enable(I2C0_ER_IRQn, 2);
i2c_start_on_bus(I2C0);
// nvic_irq_enable(I2C0_EV_IRQn, 2);
// nvic_irq_enable(I2C0_ER_IRQn, 2);
}
int read_ir_mlx90614(void) {
@ -31,7 +33,7 @@ int read_ir_mlx90614(void) {
while (TIMEOUT < 10000 && i2c_flag_get(I2C0, I2C_FLAG_I2CBSY))
TIMEOUT++;
if (TIMEOUT >= 10000) {
//printf("ERROR0\r\n");
printf("ERROR0\r\n");
return -410;
}
TIMEOUT = 0;
@ -51,7 +53,7 @@ int read_ir_mlx90614(void) {
&& !i2c_flag_get(I2C0, I2C_FLAG_SBSEND))
TIMEOUT++;
if (TIMEOUT >= 10000) {
//printf("ERROR1\r\n");
printf("ERROR1\r\n");
return -410;
}
// I2C_AcknowledgeConfig(I2C0,DISABLE);
@ -98,7 +100,7 @@ int read_ir_mlx90614(void) {
&& !i2c_flag_get(I2C0, I2C_FLAG_SBSEND))
TIMEOUT++;
if (TIMEOUT >= 10000) {
//printf("ERROR3\r\n");
printf("ERROR3\r\n");
return -410;
}
TIMEOUT = 0;
@ -117,7 +119,7 @@ int read_ir_mlx90614(void) {
&& !i2c_flag_get(I2C0, I2C_FLAG_RBNE))
TIMEOUT++;
if (TIMEOUT >= 10000) {
//printf("ERROR4\r\n");
printf("ERROR4\r\n");
return -410;
}
//I2C_AcknowledgeConfig(I2C0,DISABLE);
@ -137,7 +139,7 @@ int read_ir_mlx90614(void) {
&& !i2c_flag_get(I2C0, I2C_FLAG_RBNE))
TIMEOUT++;
if (TIMEOUT >= 10000) {
//printf("ERROR5\r\n");
printf("ERROR5\r\n");
return -410;
}
@ -157,7 +159,7 @@ int read_ir_mlx90614(void) {
&& !i2c_flag_get(I2C0, I2C_FLAG_RBNE))
TIMEOUT++;
if (TIMEOUT >= 10000) {
//printf("ERROR6\r\n");
printf("ERROR6\r\n");
return -410;
}
@ -208,16 +210,18 @@ int read_ir_mlx90614(void) {
i2c_stop_on_bus(I2C0);
// I2C_AcknowledgeConfig(I2C0, ENABLE);
i2c_ack_config(I2C0, I2C_ACK_ENABLE);
//printf("data:%x,%x,%x\r\n",Data[0],Data[1],Data[2]);
printf("data:%x,%x,%x\r\n",Data[0],Data[1],Data[2]);
// inttemp_ir = (int) ((Data[0] + Data[1] * 255) * 0.2 - 2731.5);
// Data[0] = 0x41;
// Data[1] = 0x39;
inttemp_ir = (((Data[1] << 8) | Data[0]) * 2 - 27315);
// printf("temp:%d\r\n",inttemp_ir);
if (inttemp_ir < -400)
inttemp_ir = -400;
if (inttemp_ir > 850)
inttemp_ir = 850;
// if (inttemp_ir < -4000)
// inttemp_ir = -4000;
// if (inttemp_ir > 8500)
// inttemp_ir = 8500;
//
return inttemp_ir;
}