diff --git a/MCU/WCH-南京沁恒/CH57x.md b/MCU/WCH-南京沁恒/CH57x.md new file mode 100644 index 0000000..4df38fd --- /dev/null +++ b/MCU/WCH-南京沁恒/CH57x.md @@ -0,0 +1,60 @@ +--- +created: 2024-04-23 +tags: + - "#RISC_V" + - "#低功耗" + - "#CH57X" + - 代码块 + - mcu +--- +# 低功耗 +使用官方例子最低功耗仍有约2mA,经察,默认GPIO得配置改为`GPIO_ModeIN_PD`能显著降低功耗,可低至约35uA,代码如下: +```c +/********************************************************************* + * @fn DebugInit + * + * @brief 调试初始化 + * + * @return none + */ +void DebugInit(void) +{ + GPIOA_SetBits(GPIO_Pin_9); + GPIOA_ModeCfg(GPIO_Pin_9, GPIO_ModeOut_PP_5mA); + UART1_DefInit(); +} + +/********************************************************************* + * @fn main + * + * @brief 主函数 + * + * @return none + */ +int main() +{ + SetSysClock(CLK_SOURCE_PLL_60MHz); + + GPIOA_ModeCfg(GPIO_Pin_All, GPIO_ModeIN_PD); + GPIOB_ModeCfg(GPIO_Pin_All, GPIO_ModeIN_PD); + GPIOA_ModeCfg(GPIO_Pin_8, GPIO_ModeIN_PU); + /* 配置串口调试 */ + DebugInit(); + PRINT("Start @ChipID=%02x\n", R8_CHIP_ID); + DelayMs(200); + + PRINT("sleep mode sleep \n"); + DelayMs(2); + LowPower_Sleep(RB_PWR_RAM16K | RB_PWR_RAM2K); //只保留14+2K SRAM 供电 + HSECFG_Current(HSE_RCur_100); // 降为额定电流(低功耗函数中提升了HSE偏置电流) + DelayMs(5); + PRINT("wake.. \n"); + DelayMs(500); + while(1); +} +``` +参考的一些例子: +[基于CH573的BLE温湿度传感器](https://yuanze.wang/posts/ch573-temp-humid-beacon/),源码可编译 +[CH571F无线温湿度计](https://oshwhub.com/thelight/ch571f-wu-xian-wen-shi-du-ji),源码不能正常编译 + +