From d6f3ea33b1fc5562f40722bb6e76dac3dc3401d4 Mon Sep 17 00:00:00 2001 From: yelvlab Date: Fri, 13 Dec 2024 16:31:51 +0800 Subject: [PATCH] recevice function --- src/LDC1612.c | 18 +++++++++--------- src/main.c | 5 ----- 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/src/LDC1612.c b/src/LDC1612.c index 2620705..d71ddf7 100644 --- a/src/LDC1612.c +++ b/src/LDC1612.c @@ -102,17 +102,17 @@ int LDC1612_IIC_read_16bits(void) { uint16_t raw_temp = 0; uint16_t timeout = 0; - // i2c_ack_config(I2C0, I2C_ACK_ENABLE); + i2c_ack_config(I2C0, I2C_ACK_ENABLE); - // while (i2c_flag_get(I2C0, I2C_FLAG_I2CBSY) && (timeout < I2C_TIME_OUT)) //判断IIC总线是否忙,发送起始信号 - // timeout++; - // if (timeout < I2C_TIME_OUT) { + while (i2c_flag_get(I2C0, I2C_FLAG_I2CBSY) && (timeout < I2C_TIME_OUT)) //判断IIC总线是否忙,发送起始信号 + timeout++; + if (timeout < I2C_TIME_OUT) { i2c_start_on_bus(I2C0); - // timeout = 0; - // } else { - // printf("err\r\n"); - // return -1; // 超时返回错误 - // } + timeout = 0; + } else { + printf("err\r\n"); + return -1; // 超时返回错误 + } while (!i2c_flag_get(I2C0, I2C_FLAG_SBSEND) && (timeout < I2C_TIME_OUT)) //判断起始位是否发送,设置sensor地址并设置为写 timeout++; diff --git a/src/main.c b/src/main.c index 7b03862..7374424 100644 --- a/src/main.c +++ b/src/main.c @@ -133,7 +133,6 @@ int main(void) // i2c_stop_on_bus(I2C0); - // // i2c_ack_config(I2C0, I2C_ACK_ENABLE); // iicSendData(); @@ -143,10 +142,6 @@ int main(void) result = LDC1612_IIC_read_16bits(); printf("result = %d\r\n", result); - - - - while(1){