This commit is contained in:
小马_666 2024-12-01 14:00:17 +08:00
parent f23691aeea
commit 9fcf973f31
7 changed files with 138 additions and 93 deletions

View File

@ -76,7 +76,7 @@
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.compiler.std.2020844713" name="Language standard" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.compiler.std" useByScannerDiscovery="true" value="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.compiler.std.gnu99" valueType="enumerated"/> <option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.compiler.std.2020844713" name="Language standard" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.compiler.std" useByScannerDiscovery="true" value="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.compiler.std.gnu99" valueType="enumerated"/>
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.compiler.defs.177116515" name="Defined symbols (-D)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.compiler.defs" useByScannerDiscovery="true" valueType="definedSymbols"> <option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.compiler.defs.177116515" name="Defined symbols (-D)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.compiler.defs" useByScannerDiscovery="true" valueType="definedSymbols">
<listOptionValue builtIn="false" value="CLK_OSC32K=0"/> <listOptionValue builtIn="false" value="CLK_OSC32K=0"/>
<listOptionValue builtIn="false" value="DEBUG=1"/> <listOptionValue builtIn="false" value="DEBUG=3"/>
</option> </option>
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="true" id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.compiler.include.files.288896968" name="Include files (-include)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.compiler.include.files" useByScannerDiscovery="true" valueType="includeFiles"/> <option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="true" id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.compiler.include.files.288896968" name="Include files (-include)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.compiler.include.files" useByScannerDiscovery="true" valueType="includeFiles"/>
<option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.compiler.preprocessonly.1594987158" name="Preprocess only (-E)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.compiler.preprocessonly" useByScannerDiscovery="false" value="false" valueType="boolean"/> <option id="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.compiler.preprocessonly.1594987158" name="Preprocess only (-E)" superClass="ilg.gnumcueclipse.managedbuild.cross.riscv.option.c.compiler.preprocessonly" useByScannerDiscovery="false" value="false" valueType="boolean"/>

View File

@ -5,7 +5,7 @@
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/> <provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/> <provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/> <provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="-612898175655791173" id="ilg.gnumcueclipse.managedbuild.cross.riscv.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT RISC-V Cross GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} ${cross_toolchain_flags} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true"> <provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="-534292699691499399" id="ilg.gnumcueclipse.managedbuild.cross.riscv.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT RISC-V Cross GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} ${cross_toolchain_flags} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
<language-scope id="org.eclipse.cdt.core.gcc"/> <language-scope id="org.eclipse.cdt.core.gcc"/>
<language-scope id="org.eclipse.cdt.core.g++"/> <language-scope id="org.eclipse.cdt.core.g++"/>
</provider> </provider>

View File

@ -1,19 +1,25 @@
eclipse.preferences.version=1 eclipse.preferences.version=1
encoding//APP/bsp_wf5803.c=GBK encoding//APP/bsp_wf5803.c=UTF-8
encoding//APP/include/bsp_wf5803.h=GBK encoding//APP/include/bsp_wf5803.h=GBK
encoding//APP/peripheral.c=GBK encoding//APP/peripheral.c=GBK
encoding//APP/peripheral_main.c=GBK encoding//APP/peripheral_main.c=UTF-8
encoding//HAL/MCU.c=GBK encoding//HAL/MCU.c=GBK
encoding//HAL/SLEEP.c=GBK encoding//HAL/SLEEP.c=UTF-8
encoding//HAL/include/CONFIG.h=GBK encoding//HAL/include/CONFIG.h=GBK
encoding//LIB/CH58xBLE_LIB.h=GBK encoding//LIB/CH58xBLE_LIB.h=GBK
encoding//LIB/CH58xBLE_ROM.h=GBK encoding//LIB/CH58xBLE_ROM.h=GBK
encoding//Ld/Link.ld=GBK encoding//Ld/Link.ld=GBK
encoding//RVMSIS/core_riscv.h=GBK encoding//RVMSIS/core_riscv.h=GBK
encoding//Startup/startup_CH585.S=GBK encoding//Startup/startup_CH585.S=GBK
encoding//StdPeriphDriver/CH58x_spi0.c=GBK
encoding//StdPeriphDriver/CH58x_sys.c=GBK encoding//StdPeriphDriver/CH58x_sys.c=GBK
encoding//StdPeriphDriver/CH58x_uart1.c=GBK encoding//StdPeriphDriver/CH58x_uart1.c=GBK
encoding//StdPeriphDriver/CH58x_uart3.c=GBK
encoding//StdPeriphDriver/inc/CH585SFR.h=GBK encoding//StdPeriphDriver/inc/CH585SFR.h=GBK
encoding//StdPeriphDriver/inc/CH58x_common.h=GBK
encoding//StdPeriphDriver/inc/CH58x_gpio.h=GBK
encoding//StdPeriphDriver/inc/CH58x_sys.h=GBK
encoding//StdPeriphDriver/inc/CH58x_uart.h=GBK
encoding//bsp/inc/bsp_ml307r.h=GBK encoding//bsp/inc/bsp_ml307r.h=GBK
encoding//bsp/inc/bsp_uart.h=GBK encoding//bsp/inc/bsp_uart.h=GBK
encoding//bsp/src/bsp_ml307r.c=GBK encoding//bsp/src/bsp_ml307r.c=GBK

View File

@ -1,6 +1,13 @@
#include "bsp_wf5803.h" #include "bsp_wf5803.h"
#include "CONFIG.h" #include "CONFIG.h"
#include "bsp_uart.h"
#include "log.h"
#undef LOG_ENABLE
#define LOG_ENABLE 1
typedef enum typedef enum
{ {
kPressIn = 0, kPressIn = 0,
@ -11,14 +18,14 @@ typedef enum
static tmosTaskID press_task_id = INVALID_TASK_ID; static tmosTaskID press_task_id = INVALID_TASK_ID;
#define PRESS_IN_CS_HIGH() GPIOB_SetBits(GPIO_Pin_9) #define PRESS_IN_CS_HIGH() GPIOA_SetBits(GPIO_Pin_3)
#define PRESS_IN_CS_LOW() GPIOB_ResetBits(GPIO_Pin_9) #define PRESS_IN_CS_LOW() GPIOA_ResetBits(GPIO_Pin_3)
#define PRESS_OUT_CS_HIGH() GPIOB_SetBits(GPIO_Pin_4) #define PRESS_OUT_CS_HIGH() GPIOA_SetBits(GPIO_Pin_2)
#define PRESS_OUT_CS_LOW() GPIOB_ResetBits(GPIO_Pin_4) #define PRESS_OUT_CS_LOW() GPIOA_ResetBits(GPIO_Pin_2)
#define PRESS_ATOM_CS_HIGH() GPIOB_SetBits(GPIO_Pin_17) #define PRESS_ATOM_CS_HIGH() GPIOA_SetBits(GPIO_Pin_12)
#define PRESS_ATOM_CS_LOW() GPIOB_ResetBits(GPIO_Pin_17) #define PRESS_ATOM_CS_LOW() GPIOA_ResetBits(GPIO_Pin_12)
uint8_t volatile press_done_flag = 0; uint8_t volatile press_done_flag = 0;
@ -98,7 +105,6 @@ uint8_t WF5803_ReadReg(uint8_t addr, TePressSensorIndex index)
void PRESS_IO_SPI_Init(void) void PRESS_IO_SPI_Init(void)
{ {
/** /**
* CSB: PB17
* SCL: PA13 * SCL: PA13
* SDA: PA14 * SDA: PA14
* SDO: PA15 * SDO: PA15
@ -106,27 +112,24 @@ void PRESS_IO_SPI_Init(void)
// SDA: MOSI // SDA: MOSI
// SDO: MISO // SDO: MISO
// CSB1: PA3 // 板载
// GPIOA_SetBits(GPIO_Pin_3); // CSB1: PA12
// GPIOA_ModeCfg(GPIO_Pin_3, GPIO_ModeOut_PP_5mA); GPIOA_SetBits(GPIO_Pin_12);
GPIOA_ModeCfg(GPIO_Pin_12, GPIO_ModeOut_PP_5mA);
// CSB2: PB9 // CSB2: PA3
GPIOB_SetBits(GPIO_Pin_9); GPIOA_SetBits(GPIO_Pin_3);
GPIOB_ModeCfg(GPIO_Pin_9, GPIO_ModeOut_PP_5mA); GPIOA_ModeCfg(GPIO_Pin_3, GPIO_ModeOut_PP_5mA);
// CSB3: PB4 // CSB3: PA2
GPIOB_SetBits(GPIO_Pin_4); GPIOA_SetBits(GPIO_Pin_2);
GPIOB_ModeCfg(GPIO_Pin_4, GPIO_ModeOut_PP_5mA); GPIOA_ModeCfg(GPIO_Pin_2, GPIO_ModeOut_PP_5mA);
// CSB4: PB17
GPIOB_SetBits(GPIO_Pin_17);
GPIOB_ModeCfg(GPIO_Pin_17, GPIO_ModeOut_PP_5mA);
PRESS_SPI_CsStop(kPressIn); PRESS_SPI_CsStop(kPressIn);
PRESS_SPI_CsStop(kPressOut); PRESS_SPI_CsStop(kPressOut);
PRESS_SPI_CsStop(kPressAtom); PRESS_SPI_CsStop(kPressAtom);
// spi初始化模式0
GPIOA_ModeCfg(GPIO_Pin_13 | GPIO_Pin_14, GPIO_ModeOut_PP_5mA); GPIOA_ModeCfg(GPIO_Pin_13 | GPIO_Pin_14, GPIO_ModeOut_PP_5mA);
GPIOA_ModeCfg(GPIO_Pin_15, GPIO_ModeIN_PU); GPIOA_ModeCfg(GPIO_Pin_15, GPIO_ModeIN_PU);
@ -136,63 +139,68 @@ void PRESS_IO_SPI_Init(void)
void WF5803_Init(void) void WF5803_Init(void)
{ {
PRESS_IO_SPI_Init(); PRESS_IO_SPI_Init();
WF5803_WriteReg(0x00, 0x81, kPressIn); // 配置spi为四线模式 WF5803_WriteReg(0x00, 0x81, kPressIn); // 锟斤拷锟斤拷spi为锟斤拷锟斤拷模式
WF5803_WriteReg(0x00, 0x81, kPressOut); // 配置spi为四线模式 WF5803_WriteReg(0x00, 0x81, kPressOut); // 锟斤拷锟斤拷spi为锟斤拷锟斤拷模式
WF5803_WriteReg(0x00, 0x81, kPressAtom); // 配置spi为四线模式 WF5803_WriteReg(0x00, 0x81, kPressAtom); // 锟斤拷锟斤拷spi为锟斤拷锟斤拷模式
} }
void PRESS_LowerIO_Init(void) void PRESS_LowerIO_Init(void)
{ {
// WF5803默认供电时其他IO都是高电 // WF5803默锟较癸拷锟斤拷时锟斤拷锟斤拷锟斤拷IO锟斤拷锟角高碉拷
// SPI // SPI
GPIOA_SetBits(GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15); GPIOA_SetBits(GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15);
GPIOA_ModeCfg(GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15, GPIO_ModeIN_PU); GPIOA_ModeCfg(GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15, GPIO_ModeIN_PU);
// CSB1: PA3 // 板载
// GPIOA_SetBits(GPIO_Pin_3); // CSB1: PA12
// GPIOA_ModeCfg(GPIO_Pin_3, GPIO_ModeIN_PU); GPIOA_SetBits(GPIO_Pin_12);
// CSB1: PA3 GPIOA_ModeCfg(GPIO_Pin_12, GPIO_ModeIN_PU);
// GPIOA_SetBits(GPIO_Pin_3);
// GPIOA_ModeCfg(GPIO_Pin_3, GPIO_ModeOut_PP_5mA);
// CSB2: PB9 // CSB2: PA3
GPIOB_SetBits(GPIO_Pin_9); GPIOA_SetBits(GPIO_Pin_3);
GPIOB_ModeCfg(GPIO_Pin_9, GPIO_ModeIN_PU); GPIOA_ModeCfg(GPIO_Pin_3, GPIO_ModeIN_PU);
// CSB3: PB4 // CSB3: PA2
GPIOB_SetBits(GPIO_Pin_4); GPIOA_SetBits(GPIO_Pin_2);
GPIOB_ModeCfg(GPIO_Pin_4, GPIO_ModeIN_PU); GPIOA_ModeCfg(GPIO_Pin_2, GPIO_ModeIN_PU);
// CSB4: PB17
GPIOB_SetBits(GPIO_Pin_17);
GPIOB_ModeCfg(GPIO_Pin_17, GPIO_ModeIN_PU);
} }
// 鍦ㄨ繖閲岃繘浼戠湢瀵笽O鎿嶄綔浜<E7B694>
void Lower_IO_Deinit(void) void Lower_IO_Deinit(void)
{ {
// LED // LED
GPIOA_ResetBits(GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_12); GPIOB_ResetBits(GPIO_Pin_4 | GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_16 | GPIO_Pin_17);
GPIOA_ModeCfg(GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_12, GPIO_ModeIN_PD); GPIOB_ModeCfg(GPIO_Pin_4 | GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_16 | GPIO_Pin_17, GPIO_ModeIN_PD);
// KEY // KEY
GPIOA_ResetBits(GPIO_Pin_7); GPIOB_ResetBits(GPIO_Pin_0);
GPIOA_ModeCfg(GPIO_Pin_7, GPIO_ModeIN_PU); // 由外部上拉电阻了
GPIOB_ModeCfg(GPIO_Pin_0, GPIO_ModeIN_Floating);
// RESET KEY
GPIOB_ResetBits(GPIO_Pin_7);
GPIOB_ModeCfg(GPIO_Pin_7, GPIO_ModeIN_PU);
// motor // motor
GPIOB_ResetBits(GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2); GPIOA_ResetBits(GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9);
GPIOB_ModeCfg(GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2, GPIO_ModeIN_PD); GPIOA_ModeCfg(GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9, GPIO_ModeOut_PP_5mA);
// COIL_ADC // 3V8_EN
GPIOA_ResetBits(GPIO_Pin_6); GPIOA_ResetBits(GPIO_Pin_7);
GPIOA_ModeCfg(GPIO_Pin_6, GPIO_ModeIN_PD); // 由外部上拉电阻了
GPIOA_ModeCfg(GPIO_Pin_7, GPIO_ModeOut_PP_5mA);
// ADC_CTRL,ADC_VBAT // ADC_VBAT
GPIOA_ResetBits(GPIO_Pin_0 | GPIO_Pin_1); GPIOA_ResetBits(GPIO_Pin_1);
GPIOA_ModeCfg(GPIO_Pin_0 | GPIO_Pin_1, GPIO_ModeIN_PD); GPIOA_ModeCfg(GPIO_Pin_1, GPIO_ModeIN_Floating);
// 4g的串口也得deinit
// 4G
// 3V8_EN不能浮空
// 3V8_EN
GPIOB_ResetBits(GPIO_Pin_3);
// 由外部上拉电阻了
GPIOB_ModeCfg(GPIO_Pin_3, GPIO_ModeOut_PP_5mA);
GPIOB_ResetBits(GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7);
GPIOB_ModeCfg(GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7, GPIO_ModeIN_PD);
} }
void PRESS_LowPower(void) void PRESS_LowPower(void)
@ -214,8 +222,8 @@ uint8_t GetSensorData(TePressSensorIndex index)
return 1; return 1;
} }
// 气压数据 // 锟斤拷压锟斤拷锟斤拷
// 温度数据 // 锟铰讹拷锟斤拷锟斤拷
for (uint8_t i = 0; i < 5; i++) for (uint8_t i = 0; i < 5; i++)
{ {
press_raw_data[index][i] = WF5803_ReadReg(0x06 + i, index); press_raw_data[index][i] = WF5803_ReadReg(0x06 + i, index);
@ -249,7 +257,7 @@ void SensorData_Process(TePressSensorIndex index)
fDat = reading / 8388608.0f; fDat = reading / 8388608.0f;
} }
press = fDat * 125 + 17.5; // WF5803_1BAR 如果是使用10m级别的深传就使用这个 press = fDat * 125 + 17.5; // WF5803_1BAR 锟斤拷锟斤拷锟绞癸拷锟<EFBFBD>10m锟斤拷锟斤拷锟斤拷畲拷锟绞癸拷锟斤拷锟斤拷
press_value[index] = (uint32_t)(press * 1000); // pa press_value[index] = (uint32_t)(press * 1000); // pa
reading = press_raw_data[index][3]; reading = press_raw_data[index][3];
@ -285,6 +293,7 @@ uint16_t WF5803_ProcessEvent(uint8_t task_id, uint16_t events)
WF5803_WriteReg(0x30, 0x0A, kPressAtom); WF5803_WriteReg(0x30, 0x0A, kPressAtom);
tmos_start_task(press_task_id, WF5803_EVT_READ, MS1_TO_SYSTEM_TIME(5)); tmos_start_task(press_task_id, WF5803_EVT_READ, MS1_TO_SYSTEM_TIME(5));
logDebug("WF5803_EVT_START");
return (events ^ WF5803_EVT_START); return (events ^ WF5803_EVT_START);
} }
else if (events & WF5803_EVT_READ) else if (events & WF5803_EVT_READ)
@ -312,6 +321,8 @@ uint16_t WF5803_ProcessEvent(uint8_t task_id, uint16_t events)
tmos_start_task(press_task_id, WF5803_EVT_START, MS1_TO_SYSTEM_TIME(800)); tmos_start_task(press_task_id, WF5803_EVT_START, MS1_TO_SYSTEM_TIME(800));
logDebug("WF5803_EVT_READ");
press_done_flag = 1; press_done_flag = 1;
return (events ^ WF5803_EVT_READ); return (events ^ WF5803_EVT_READ);
} }
@ -322,4 +333,5 @@ void BSP_PRESS_Init(void)
{ {
press_task_id = TMOS_ProcessEventRegister(WF5803_ProcessEvent); press_task_id = TMOS_ProcessEventRegister(WF5803_ProcessEvent);
tmos_set_event(press_task_id, WF5803_EVT_START); tmos_set_event(press_task_id, WF5803_EVT_START);
logDebug("BSP_PRESS_Init");
} }

View File

@ -3,7 +3,7 @@
* Author : WCH * Author : WCH
* Version : V1.1 * Version : V1.1
* Date : 2020/08/06 * Date : 2020/08/06
* Description : * Description : <EFBFBD>
********************************************************************************* *********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd. * Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* Attention: This software (modified or not) and binary are used for * Attention: This software (modified or not) and binary are used for
@ -11,7 +11,7 @@
*******************************************************************************/ *******************************************************************************/
/******************************************************************************/ /******************************************************************************/
/* 头文件包含 */ /* 头锟侥硷拷锟斤拷锟斤拷 */
#include "CONFIG.h" #include "CONFIG.h"
#include "HAL.h" #include "HAL.h"
#include "gattprofile.h" #include "gattprofile.h"
@ -42,7 +42,7 @@ const uint8_t MacAddr[6] = {0x84, 0xC2, 0xE4, 0x03, 0x02, 0x02};
/********************************************************************* /*********************************************************************
* @fn Main_Circulation * @fn Main_Circulation
* *
* @brief * @brief
* *
* @return none * @return none
*/ */
@ -61,7 +61,7 @@ void Main_Circulation()
/********************************************************************* /*********************************************************************
* @fn main * @fn main
* *
* @brief * @brief
* *
* @return none * @return none
*/ */
@ -72,12 +72,19 @@ int main(void)
#endif #endif
HSECFG_Capacitance(HSECap_18p); HSECFG_Capacitance(HSECap_18p);
SetSysClock(CLK_SOURCE_HSE_PLL_62_4MHz); SetSysClock(CLK_SOURCE_HSE_PLL_62_4MHz);
SysTick_Config( GetSysClock() / 1000 * SYSTICK_INTERVAL); //设定嘀嗒时间1ms SysTick_Config( GetSysClock() / 1000 * SYSTICK_INTERVAL); //锟借定锟斤拷锟绞憋拷锟<E68BB7>1ms
#if(defined(HAL_SLEEP)) && (HAL_SLEEP == FALSE) // 3V8_EN
GPIOA_ModeCfg(GPIO_Pin_All, GPIO_ModeIN_PU); GPIOB_ResetBits(GPIO_Pin_3);
GPIOB_ModeCfg(GPIO_Pin_All, GPIO_ModeIN_PU); // 由外部上拉电阻了
GPIOB_ModeCfg(GPIO_Pin_3, GPIO_ModeOut_PP_5mA);
#if(defined(HAL_SLEEP)) && (HAL_SLEEP == TRUE)
GPIOA_ModeCfg(GPIO_Pin_All, GPIO_ModeIN_PD);
GPIOB_ModeCfg(GPIO_Pin_All, GPIO_ModeIN_PD);
#endif #endif
#ifdef DEBUG #ifdef DEBUG
// DEBUG鐢ㄧ殑uart1
BSP_UART3_Init(); BSP_UART3_Init();
logDebug("%s", TxBuff); logDebug("%s", TxBuff);
#endif #endif
@ -91,12 +98,12 @@ int main(void)
Peripheral_Init(); Peripheral_Init();
logDebug("Peripheral init ok\n"); logDebug("Peripheral init ok\n");
// BSP_PRESS_Init(); BSP_PRESS_Init();
// logDebug("BSP init ok\n"); logDebug("BSP init ok\n");
//
BSP_Ml307r_Init(); // BSP_Ml307r_Init();
logDebug("Start @ChipID=%02X\n", R8_CHIP_ID); // logDebug("Start @ChipID=%02X\n", R8_CHIP_ID);
logDebug("%s\n", VER_LIB); // logDebug("%s\n", VER_LIB);
Main_Circulation(); Main_Circulation();

View File

@ -3,7 +3,7 @@
* Author : WCH * Author : WCH
* Version : V1.2 * Version : V1.2
* Date : 2022/01/18 * Date : 2022/01/18
* Description : * Description : <EFBFBD>
********************************************************************************* *********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd. * Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* Attention: This software (modified or not) and binary are used for * Attention: This software (modified or not) and binary are used for
@ -11,7 +11,7 @@
*******************************************************************************/ *******************************************************************************/
/******************************************************************************/ /******************************************************************************/
/* 头文件包含 */ /* 头锟侥硷拷锟斤拷锟斤拷 */
#include "HAL.h" #include "HAL.h"
#include "bsp_wf5803.h" #include "bsp_wf5803.h"
@ -19,21 +19,21 @@
/******************************************************************************* /*******************************************************************************
* @fn CH58x_LowPower * @fn CH58x_LowPower
* *
* @brief * @brief
* *
* @param time - RTC绝对值 * @param time - TC锟斤拷锟斤拷值锟斤拷
* *
* @return state. * @return state.
*/ */
__HIGH_CODE __HIGH_CODE
uint32_t CH58x_LowPower(uint32_t time) uint32_t CH58x_LowPower(uint32_t time)
{ {
#if(defined(HAL_SLEEP)) && (HAL_SLEEP == FALSE) #if(defined(HAL_SLEEP)) && (HAL_SLEEP == TRUE)
volatile uint32_t i; volatile uint32_t i;
uint32_t time_tign, time_sleep, time_curr; uint32_t time_tign, time_sleep, time_curr;
unsigned long irq_status; unsigned long irq_status;
// 提前唤醒 // 锟斤拷前锟斤拷锟斤拷
if (time <= WAKE_UP_RTC_MAX_TIME) { if (time <= WAKE_UP_RTC_MAX_TIME) {
time_tign = time + (RTC_MAX_COUNT - WAKE_UP_RTC_MAX_TIME); time_tign = time + (RTC_MAX_COUNT - WAKE_UP_RTC_MAX_TIME);
} else { } else {
@ -42,14 +42,14 @@ uint32_t CH58x_LowPower(uint32_t time)
SYS_DisableAllIrq(&irq_status); SYS_DisableAllIrq(&irq_status);
time_curr = RTC_GetCycle32k(); time_curr = RTC_GetCycle32k();
// 检测睡眠时间 // 锟斤拷锟剿拷锟绞憋拷锟<EFBFBD>
if (time_tign < time_curr) { if (time_tign < time_curr) {
time_sleep = time_tign + (RTC_MAX_COUNT - time_curr); time_sleep = time_tign + (RTC_MAX_COUNT - time_curr);
} else { } else {
time_sleep = time_tign - time_curr; time_sleep = time_tign - time_curr;
} }
// 若睡眠时间小于最小睡眠时间或大于最大睡眠时间,则不睡眠 // 锟斤拷睡锟斤拷时锟斤拷小锟斤拷锟斤拷小睡锟斤拷时锟斤拷锟斤拷锟斤拷锟斤拷锟剿拷锟绞憋拷洌拷锟剿拷锟<EFBFBD>
if ((time_sleep < SLEEP_RTC_MIN_TIME) || if ((time_sleep < SLEEP_RTC_MIN_TIME) ||
(time_sleep > SLEEP_RTC_MAX_TIME)) { (time_sleep > SLEEP_RTC_MAX_TIME)) {
SYS_RecoverIrq(irq_status); SYS_RecoverIrq(irq_status);
@ -59,19 +59,26 @@ uint32_t CH58x_LowPower(uint32_t time)
RTC_SetTignTime(time_tign); RTC_SetTignTime(time_tign);
SYS_RecoverIrq(irq_status); SYS_RecoverIrq(irq_status);
#if(DEBUG == Debug_UART0) // 使用其他串口输出打印信息需要修改这行代码 // 这里只写了uart0的其他的也要有
#if(DEBUG == Debug_UART0) // 使锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟接★拷锟较拷锟揭拷薷锟斤拷锟斤拷写锟斤拷锟<E68BB7>
while((R8_UART0_LSR & RB_LSR_TX_ALL_EMP) == 0) while((R8_UART0_LSR & RB_LSR_TX_ALL_EMP) == 0)
{ {
__nop(); __nop();
} }
#elif (DEBUG == Debug_UART3)
while((R8_UART3_LSR & RB_LSR_TX_ALL_EMP) == 0)
{
__nop();
}
#endif #endif
// LOW POWER-sleep模式 // LOW POWER-sleep模式
if(!RTCTigFlag) if(!RTCTigFlag)
{ {
// 杩欓噷鑷繁娣诲姞鐨勶紝TMOS浼氳皟鐢<E79A9F>
PRESS_LowPower(); PRESS_LowPower();
LowPower_Sleep(RB_PWR_RAM32K | RB_PWR_RAM96K | RB_PWR_EXTEND |RB_XT_PRE_EN ); LowPower_Sleep(RB_PWR_RAM32K | RB_PWR_RAM96K | RB_PWR_EXTEND |RB_XT_PRE_EN );
HSECFG_Current(HSE_RCur_100); // 降为额定电流(低功耗函数中提升了HSE偏置电流) HSECFG_Current(HSE_RCur_100); // 锟斤拷为锟筋定锟斤拷锟斤拷(锟酵癸拷锟侥猴拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷HSE偏锟矫碉拷锟斤拷)
return 0; return 0;
} }
@ -82,7 +89,7 @@ uint32_t CH58x_LowPower(uint32_t time)
/******************************************************************************* /*******************************************************************************
* @fn HAL_SleepInit * @fn HAL_SleepInit
* *
* @brief - RTC唤醒 * @brief - RTC锟斤拷锟窖拷锟斤拷锟斤拷模
* *
* @param None. * @param None.
* *
@ -92,10 +99,10 @@ void HAL_SleepInit(void)
{ {
#if(defined(HAL_SLEEP)) && (HAL_SLEEP == TRUE) #if(defined(HAL_SLEEP)) && (HAL_SLEEP == TRUE)
sys_safe_access_enable(); sys_safe_access_enable();
R8_SLP_WAKE_CTRL |= RB_SLP_RTC_WAKE; // RTC唤醒 R8_SLP_WAKE_CTRL |= RB_SLP_RTC_WAKE; // RTC锟斤拷锟斤拷
sys_safe_access_disable(); sys_safe_access_disable();
sys_safe_access_enable(); sys_safe_access_enable();
R8_RTC_MODE_CTRL |= RB_RTC_TRIG_EN; // 触发模式 R8_RTC_MODE_CTRL |= RB_RTC_TRIG_EN; // 锟斤拷锟斤拷模式
sys_safe_access_disable(); sys_safe_access_disable();
PFIC_EnableIRQ(RTC_IRQn); PFIC_EnableIRQ(RTC_IRQn);
#endif #endif

View File

@ -14,6 +14,19 @@
#define ML307_UART_TX_PIN GPIO_Pin_13 //PB13 #define ML307_UART_TX_PIN GPIO_Pin_13 //PB13
#define ML307_UART_RX_PIN GPIO_Pin_12 //PB12 #define ML307_UART_RX_PIN GPIO_Pin_12 //PB12
typedef enum
{
kHeartbeatStatus, // 定时心跳状态
kConcentrationHighStatus, // 浓度异常状态
kSelfCheckStatus, // 自检触发状态
kAlarmStatus, // 报警触发状态
kAlarmClearedStatus, // 报警解除状态
kSensorFaultStatus, // 传感器故障触发状态
kSensorRecoveredStatus, // 传感器故障解除状态
kPowerDownStatus, // 掉电状态
} Mb26Status; // 当前所处的上报状态
void BSP_Ml307r_Init(void); void BSP_Ml307r_Init(void);
void Ml307r_Loop(void); void Ml307r_Loop(void);