From 77d80fe2732b311ef3594e65d38250c3ddefca76 Mon Sep 17 00:00:00 2001
From: stark1898y <1658608470@qq.com>
Date: Sun, 15 Dec 2024 16:13:29 +0800
Subject: [PATCH] bsp_i2c ok
---
.cproject | 7 ++++---
.project | 6 +++---
APP/peripheral_main.c | 7 +++++--
BSP/src/bsp_i2c.c | 17 ++++++++++-------
BSP/src/bsp_uart.c | 1 +
5 files changed, 23 insertions(+), 15 deletions(-)
diff --git a/.cproject b/.cproject
index 74bb70a..7420052 100644
--- a/.cproject
+++ b/.cproject
@@ -90,7 +90,7 @@
-
+
@@ -103,9 +103,9 @@
-
+
-
+
@@ -173,4 +173,5 @@
+
diff --git a/.project b/.project
index d7d4c38..b2e792e 100644
--- a/.project
+++ b/.project
@@ -1,7 +1,7 @@
-
+
BLE_TYQ_CH592F
-
+
@@ -26,7 +26,7 @@
1602468250279
-
+
22
org.eclipse.ui.ide.multiFilter
diff --git a/APP/peripheral_main.c b/APP/peripheral_main.c
index 734ec73..440e574 100644
--- a/APP/peripheral_main.c
+++ b/APP/peripheral_main.c
@@ -165,6 +165,8 @@ int main(void)
BSP_KEY_Init();
+
+
BSP_ADC_Init();
CH59x_BLEInit();
@@ -177,11 +179,12 @@ int main(void)
GAPRole_PeripheralInit();
Peripheral_Init();
- DelayMs(100);
- GXHTC3C_Init();
BSP_FLASH_Init();
+ DelayMs(100);
+ GXHTC3C_Init();
+
Main_Circulation();
}
diff --git a/BSP/src/bsp_i2c.c b/BSP/src/bsp_i2c.c
index 926dfce..6ea2fc8 100644
--- a/BSP/src/bsp_i2c.c
+++ b/BSP/src/bsp_i2c.c
@@ -42,7 +42,8 @@ static struct i2c_slave_cb *slave_cb = NULL;
#define MASTER_ADDR 0x42
uint8_t i2c_tx_data[2];
-uint8_t i2c_rx_data[6];
+// __attribute__((aligned(4)))
+uint8_t i2c_rx_data[8];
void BSP_I2C_Init(uint8_t address)
{
@@ -95,7 +96,7 @@ int I2C_Write(uint8_t addr_7bit, const uint8_t *data, uint8_t length,
i2c_master_buffer_index = 0;
i2c_master_buffer_length = length;
- memcpy(i2c_master_buffer, data, length);
+ tmos_memcpy(i2c_master_buffer, data, length);
i2c_slave_addr_rw = I2C_WRITE;
i2c_slave_addr_rw |= addr_7bit << 1;
@@ -201,7 +202,7 @@ int I2C_Read(uint8_t addr_7bit, uint8_t *data, uint8_t length,
length = i2c_master_buffer_index;
// copy i2c buffer to data
- memcpy(data, i2c_master_buffer, length);
+ tmos_memcpy(data, i2c_master_buffer, length);
return length;
}
@@ -279,7 +280,7 @@ void GXHTC3C_SendCmd(uint16_t cmd)
i2c_tx_data[0] = HI_UINT16(cmd);
i2c_tx_data[1] = LO_UINT16(cmd);
ret = I2C_Write(GXHTC3C_ADDR, (const uint8_t *)&i2c_tx_data, 2, true, true);
- logDebug("GXHTC3C_SendCmd %s", ret ? "failed" : "success");
+ // logDebug("GXHTC3C_SendCmd %s", ret ? "failed" : "success");
}
void GXHTC3C_Sleep(void)
@@ -361,8 +362,8 @@ uint8_t GXHTC3C_GetTempHumi(float *humi, float *temp)
if ((crc_humi == i2c_rx_data[2]) && (crc_temp == i2c_rx_data[5]))
{
- logDebug("crc ok");
- logHexDumpAll(i2c_rx_data, 6);
+ // logDebug("crc ok");
+ // logHexDumpAll(i2c_rx_data, 6);
*humi = (100.0 * raw_humi) / 65536.0; // 湿度真实值
*temp = (175.0 * raw_temp) / 65536.0 - 45.0; // 温度真实值
@@ -375,6 +376,7 @@ uint8_t GXHTC3C_GetTempHumi(float *humi, float *temp)
logError("crc error");
return 2;
}
+ // logDebug("0 success");
return 0;
}
@@ -391,6 +393,7 @@ void GXHTC3C_Read(void)
ret = GXHTC3C_GetTempHumi(&humi, &temp);
if (ret == 0)
{
+ // logDebug("ret=0");
logDebug("humi %.2f %, temp %.2f C", humi, temp);
}
@@ -415,7 +418,7 @@ void GXHTC3C_Init(void)
ret = GXHTC3C_GetTempHumi(&humi, &temp);
if (ret == 0)
{
- logDebug("humi %.2f %, temp %.2f C", humi, temp);
+ // logDebug("humi %.2f %, temp %.2f C", humi, temp);
}
GXHTC3C_Sleep();
diff --git a/BSP/src/bsp_uart.c b/BSP/src/bsp_uart.c
index 3181af1..457804c 100644
--- a/BSP/src/bsp_uart.c
+++ b/BSP/src/bsp_uart.c
@@ -22,6 +22,7 @@ unsigned int BSP_Uart1_Send_Data(const void *buf, unsigned int len)
unsigned int ret;
ret = lwrb_write(&Uart1Tx, buf, len);
+ BSP_UART1_TxLoop();
// UART1_INTCfg(ENABLE, RB_IER_THR_EMPTY);
return ret;
}