From 53fadd4c22ac0c8ed7539461e8f30607dc100c29 Mon Sep 17 00:00:00 2001 From: yelvlab Date: Wed, 9 Oct 2024 10:38:39 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=A8gd32e230=E7=9A=84stdlib=E9=87=8D?= =?UTF-8?q?=E5=86=99wbh=E7=9A=84=E5=8F=82=E8=80=83=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=EF=BC=8C=E5=B9=B6=E5=9B=A0=E4=B8=BAstm=E7=9A=84stdlib=E5=92=8C?= =?UTF-8?q?gd32=E7=9A=84stdlib=E6=9C=89=E5=BE=88=E5=A4=A7=E5=B7=AE?= =?UTF-8?q?=E5=BC=82=EF=BC=8C=E8=B6=85=E6=97=B6=E6=9C=BA=E5=88=B6=E4=B8=8E?= =?UTF-8?q?flag=E9=AA=8C=E8=AF=81=E5=B7=AE=E5=BC=82=E8=BE=83=E5=A4=A7?= =?UTF-8?q?=EF=BC=8C=E9=80=9A=E8=BF=87=E5=AF=B9=E6=AF=94=E9=87=8D=E6=96=B0?= =?UTF-8?q?=E7=BC=96=E5=86=99=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 数据计算方式重新书写,两个8位数据的合并方式修改为位移,并且整体放大100倍(标准数据为((Data[1] << 8) | Data[0]) * 0.02 - 273.15) --- src/main.c | 2 +- src/mlx90614.c | 30 +++++++++++++++++------------- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/src/main.c b/src/main.c index 160ad2c..8e94187 100644 --- a/src/main.c +++ b/src/main.c @@ -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()); } } diff --git a/src/mlx90614.c b/src/mlx90614.c index 67b5898..5020641 100644 --- a/src/mlx90614.c +++ b/src/mlx90614.c @@ -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; }