From 6c7b6c910be1dcdc0bb786e02be648b1a56faa5e Mon Sep 17 00:00:00 2001 From: guowenxue <guowenxue@gmail.com> Date: Thu, 09 Oct 2025 00:50:02 +0800 Subject: [PATCH] 添加串口远程控制项目代码 --- Core/Src/board/sht20.c | 15 +++++++++------ 1 files changed, 9 insertions(+), 6 deletions(-) diff --git a/Core/Src/board/sht20.c b/Core/Src/board/sht20.c index 2d279e6..7e618da 100644 --- a/Core/Src/board/sht20.c +++ b/Core/Src/board/sht20.c @@ -11,10 +11,10 @@ ***********************************************************************/ #include <stdio.h> #include <string.h> -#include "i2c.h" +#include "i2c_bitbang.h" #include "sht20.h" -#define CONFIG_DEBUG_SHT2X /* Enable SHT20 debug */ +//#define CONFIG_DEBUG_SHT2X /* Enable SHT20 debug */ #define SHT2X_CHIPADDR 0x40 /* SHT20 7-Bits Chip address */ @@ -61,6 +61,8 @@ float temp, rh; int rv; + i2c_lock(SHT2X_CHIPADDR); + if( sht2x_softreset() < 0 ) { sht2x_print("SHT20 soft reset failed.\r\n"); @@ -94,6 +96,7 @@ *humdity=rh; OUT: + i2c_free(); return rv; } @@ -104,8 +107,8 @@ sht2x_print("Start soft reset sht2x\r\n"); - rv=HAL_I2C_Master_Transmit(&hi2c1, SHT2X_CHIPADDR<<1, &command, 1, 0xFFFFFFFF); - if( rv != HAL_OK ) + rv=i2c_write(&command, 1); + if( rv ) { sht2x_print("SHT2X send soft reset command 0x%0x failure: rv=0x%02x\r\n", command, rv); return -rv; @@ -161,7 +164,7 @@ return -2; } - if( HAL_I2C_Master_Transmit(&hi2c1, SHT2X_CHIPADDR<<1, &command, 1, 0xFFFFFFFF) != HAL_OK ) + if( i2c_write(&command, 1) < 0 ) { sht2x_print("SHT2X send measure command 0x%0x failure\r\n", command); return -3; @@ -176,7 +179,7 @@ { memset(buf, 0, 3); - if( HAL_OK == HAL_I2C_Master_Receive(&hi2c1, SHT2X_CHIPADDR<<1|1, buf, 3, 0xFFFFFFFF) ) + if( !i2c_read(buf, 3) ) { break; } -- Gitblit v1.9.1