VCC常供电,SPI管脚 不测气压的时候低功耗输入上拉,静态功耗最低了
This commit is contained in:
parent
f4b6ae581c
commit
1eeff59c4a
201
APP/bsp_wf5803.c
201
APP/bsp_wf5803.c
|
@ -1,21 +1,30 @@
|
||||||
#include "bsp_wf5803.h"
|
#include "bsp_wf5803.h"
|
||||||
#include "CONFIG.h"
|
#include "CONFIG.h"
|
||||||
|
|
||||||
static uint8_t Peripheral_TaskID = 0xff;
|
static tmosTaskID wf5803_task_id = INVALID_TASK_ID;
|
||||||
|
|
||||||
|
#define WF5803_CSB4_HIGH() GPIOB_SetBits(GPIO_Pin_17)
|
||||||
|
#define WF5803_CSB4_LOW() GPIOB_ResetBits(GPIO_Pin_17)
|
||||||
|
|
||||||
|
#define WF5803_CSB4_HIGH() GPIOB_SetBits(GPIO_Pin_17)
|
||||||
|
#define WF5803_CSB4_LOW() GPIOB_ResetBits(GPIO_Pin_17)
|
||||||
|
|
||||||
|
#define WF5803_CSB4_HIGH() GPIOB_SetBits(GPIO_Pin_17)
|
||||||
|
#define WF5803_CSB4_LOW() GPIOB_ResetBits(GPIO_Pin_17)
|
||||||
|
|
||||||
|
uint8_t volatile vcc4_state = 0;
|
||||||
|
|
||||||
#define WF5803_CSB1_HIGH() GPIOB_SetBits(GPIO_Pin_17)
|
|
||||||
#define WF5803_CSB1_LOW() GPIOB_ResetBits(GPIO_Pin_17)
|
|
||||||
|
|
||||||
void SPICs_Start(void)
|
void SPICs_Start(void)
|
||||||
{
|
{
|
||||||
// GPIOA_ResetBits(GPIO_Pin_6);
|
// GPIOA_ResetBits(GPIO_Pin_6);
|
||||||
WF5803_CSB1_LOW();
|
WF5803_CSB4_LOW();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SPICs_Stop(void)
|
void SPICs_Stop(void)
|
||||||
{
|
{
|
||||||
// GPIOA_SetBits(GPIO_Pin_6);
|
// GPIOA_SetBits(GPIO_Pin_6);
|
||||||
WF5803_CSB1_HIGH();
|
WF5803_CSB4_HIGH();
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t WF5803_SendByte(uint8_t data)
|
uint8_t WF5803_SendByte(uint8_t data)
|
||||||
|
@ -63,33 +72,50 @@ void WF5803_Init(void)
|
||||||
// SDA: MOSI
|
// SDA: MOSI
|
||||||
// SDO: MISO
|
// SDO: MISO
|
||||||
#if 1
|
#if 1
|
||||||
// CSB1: PA3
|
// VCC1: PA2
|
||||||
|
// GPIOA_SetBits(GPIO_Pin_2);
|
||||||
|
// GPIOA_ModeCfg(GPIO_Pin_2, GPIO_ModeOut_PP_20mA);
|
||||||
|
// GPIOA_SetBits(GPIO_Pin_2);
|
||||||
|
|
||||||
GPIOA_SetBits(GPIO_Pin_3);
|
// // CSB1: PA3
|
||||||
GPIOA_ModeCfg(GPIO_Pin_3, GPIO_ModeOut_PP_5mA);
|
// GPIOA_SetBits(GPIO_Pin_3);
|
||||||
GPIOA_SetBits(GPIO_Pin_3);
|
// GPIOA_ModeCfg(GPIO_Pin_3, GPIO_ModeOut_PP_5mA);
|
||||||
|
// GPIOA_SetBits(GPIO_Pin_3);
|
||||||
|
|
||||||
|
// // VCC2: PB8
|
||||||
|
// GPIOB_SetBits(GPIO_Pin_8);
|
||||||
|
// GPIOB_ModeCfg(GPIO_Pin_8, GPIO_ModeOut_PP_5mA);
|
||||||
|
// GPIOB_SetBits(GPIO_Pin_8);
|
||||||
|
|
||||||
// CSB2: PB9
|
// CSB2: PB9
|
||||||
GPIOB_ResetBits(GPIO_Pin_9);
|
GPIOB_SetBits(GPIO_Pin_9);
|
||||||
GPIOB_ModeCfg(GPIO_Pin_9, GPIO_ModeOut_PP_5mA);
|
GPIOB_ModeCfg(GPIO_Pin_9, GPIO_ModeOut_PP_5mA);
|
||||||
GPIOB_ResetBits(GPIO_Pin_9);
|
GPIOB_SetBits(GPIO_Pin_9);
|
||||||
|
|
||||||
// WF5803_CSB1_HIGH();
|
// // VCC3: PB3
|
||||||
|
// GPIOB_SetBits(GPIO_Pin_3);
|
||||||
|
// GPIOB_ModeCfg(GPIO_Pin_3, GPIO_ModeOut_PP_5mA);
|
||||||
|
// GPIOB_SetBits(GPIO_Pin_3);
|
||||||
|
|
||||||
// CSB3: PB4
|
// CSB3: PB4
|
||||||
GPIOB_ResetBits(GPIO_Pin_4);
|
GPIOB_SetBits(GPIO_Pin_4);
|
||||||
GPIOB_ModeCfg(GPIO_Pin_4, GPIO_ModeOut_PP_5mA);
|
GPIOB_ModeCfg(GPIO_Pin_4, GPIO_ModeOut_PP_5mA);
|
||||||
GPIOB_ResetBits(GPIO_Pin_9);
|
GPIOB_SetBits(GPIO_Pin_4);
|
||||||
|
|
||||||
|
// // VCC4: PB16
|
||||||
|
// GPIOB_ModeCfg(GPIO_Pin_16, GPIO_ModeIN_PU);
|
||||||
|
// // GPIOB_SetBits(GPIO_Pin_17);
|
||||||
|
// mDelayuS(5);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// CSB4: PB17
|
// CSB4: PB17
|
||||||
GPIOB_SetBits(GPIO_Pin_17);
|
GPIOB_SetBits(GPIO_Pin_17);
|
||||||
GPIOB_ModeCfg(GPIO_Pin_17, GPIO_ModeOut_PP_5mA);
|
GPIOB_ModeCfg(GPIO_Pin_17, GPIO_ModeOut_PP_5mA);
|
||||||
// WF5803_CSB1_HIGH();
|
GPIOB_SetBits(GPIO_Pin_17);
|
||||||
|
|
||||||
// PRINT("WF5803_CSB1_HIGH()\r\n");
|
|
||||||
|
|
||||||
// spi³õʼ»¯£¬Ä£Ê½0
|
// spi³õʼ»¯£¬Ä£Ê½0
|
||||||
GPIOA_ModeCfg(GPIO_Pin_12 | 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);
|
||||||
#endif
|
#endif
|
||||||
// PRINT("GPIOA_ModeCfg ok\r\n");
|
// PRINT("GPIOA_ModeCfg ok\r\n");
|
||||||
|
@ -105,16 +131,96 @@ void WF5803_Init(void)
|
||||||
// PRINT("SPI_Init ok\r\n");
|
// PRINT("SPI_Init ok\r\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void WF5803_DeInit(void)
|
void WF5803_DeInit(void)
|
||||||
{
|
{
|
||||||
// GPIOA_ModeCfg(GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_6, GPIO_ModeIN_PD);
|
// SPI
|
||||||
|
// if (vcc4_state == 1)
|
||||||
|
// {
|
||||||
|
// GPIOA_ResetBits(GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15);
|
||||||
|
// GPIOA_ModeCfg(GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15, GPIO_ModeIN_PU);
|
||||||
|
|
||||||
|
// // CSB4: PB11
|
||||||
|
// GPIOB_ResetBits(GPIO_Pin_17);
|
||||||
|
// GPIOB_ModeCfg(GPIO_Pin_17, GPIO_ModeIN_PU);
|
||||||
|
// }
|
||||||
|
// else
|
||||||
|
if (vcc4_state == 0)
|
||||||
|
{
|
||||||
|
GPIOA_ResetBits(GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15);
|
||||||
|
GPIOA_ModeCfg(GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15, GPIO_ModeIN_PU);
|
||||||
|
GPIOB_ResetBits(GPIO_Pin_17);
|
||||||
|
GPIOB_ModeCfg(GPIO_Pin_17, GPIO_ModeIN_PU);
|
||||||
|
}
|
||||||
|
|
||||||
|
// // VCC1: PA2
|
||||||
|
// GPIOA_ResetBits(GPIO_Pin_2);
|
||||||
// GPIOA_ModeCfg(GPIO_Pin_2, GPIO_ModeIN_PD);
|
// GPIOA_ModeCfg(GPIO_Pin_2, GPIO_ModeIN_PD);
|
||||||
|
|
||||||
// GPIOA_ResetBits(GPIO_Pin_4);
|
// CSB1: PA3
|
||||||
// GPIOA_ResetBits(GPIO_Pin_5);
|
// GPIOA_ResetBits(GPIO_Pin_3);
|
||||||
// GPIOA_ResetBits(GPIO_Pin_12);
|
// GPIOA_ModeCfg(GPIO_Pin_3, GPIO_ModeIN_PD);
|
||||||
|
|
||||||
// GPIOA_ModeCfg(GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_12, GPIO_ModeIN_PD);
|
// GPIOA_SetBits(GPIO_Pin_3);
|
||||||
|
// GPIOA_ModeCfg(GPIO_Pin_3, GPIO_ModeIN_PU);
|
||||||
|
|
||||||
|
// // VCC2: PB8
|
||||||
|
// GPIOB_ResetBits(GPIO_Pin_8);
|
||||||
|
// GPIOB_ModeCfg(GPIO_Pin_8, GPIO_ModeIN_PD);
|
||||||
|
|
||||||
|
// // CSB2: PB9
|
||||||
|
GPIOB_ResetBits(GPIO_Pin_9);
|
||||||
|
GPIOB_ModeCfg(GPIO_Pin_9, GPIO_ModeIN_PD);
|
||||||
|
// GPIOB_SetBits(GPIO_Pin_9);
|
||||||
|
// GPIOB_ModeCfg(GPIO_Pin_9, GPIO_ModeIN_PU);
|
||||||
|
|
||||||
|
// // VCC3: PB3
|
||||||
|
// GPIOB_ResetBits(GPIO_Pin_3);
|
||||||
|
// GPIOB_ModeCfg(GPIO_Pin_3, GPIO_ModeIN_PD);
|
||||||
|
|
||||||
|
// CSB3: PB4
|
||||||
|
GPIOB_ResetBits(GPIO_Pin_4);
|
||||||
|
GPIOB_ModeCfg(GPIO_Pin_4, GPIO_ModeIN_PD);
|
||||||
|
// GPIOB_SetBits(GPIO_Pin_4);
|
||||||
|
// GPIOB_ModeCfg(GPIO_Pin_4, GPIO_ModeIN_PU);
|
||||||
|
|
||||||
|
// if (vcc4_state == 1)
|
||||||
|
// {
|
||||||
|
// // VCC4: PB16
|
||||||
|
// // GPIOB_SetBits(GPIO_Pin_16);
|
||||||
|
// // GPIOB_ModeCfg(GPIO_Pin_16, GPIO_ModeOut_PP_5mA);
|
||||||
|
// // GPIOB_SetBits(GPIO_Pin_16);
|
||||||
|
// }
|
||||||
|
// else
|
||||||
|
// {
|
||||||
|
// // VCC4: PB16
|
||||||
|
// GPIOB_ResetBits(GPIO_Pin_16);
|
||||||
|
// GPIOB_ModeCfg(GPIO_Pin_16, GPIO_ModeIN_PD);
|
||||||
|
// PRINT("vcc4_state = 0\r\n");
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// LED
|
||||||
|
GPIOA_ResetBits(GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_12);
|
||||||
|
GPIOA_ModeCfg(GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_12, GPIO_ModeIN_PD);
|
||||||
|
|
||||||
|
// KEY
|
||||||
|
GPIOA_ResetBits(GPIO_Pin_7);
|
||||||
|
GPIOA_ModeCfg(GPIO_Pin_7, GPIO_ModeIN_PU);
|
||||||
|
|
||||||
|
// motor
|
||||||
|
GPIOB_ResetBits(GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2);
|
||||||
|
GPIOB_ModeCfg(GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2, GPIO_ModeIN_PD);
|
||||||
|
|
||||||
|
// COIL_ADC
|
||||||
|
GPIOA_ResetBits(GPIO_Pin_6);
|
||||||
|
GPIOA_ModeCfg(GPIO_Pin_6, GPIO_ModeIN_PD);
|
||||||
|
|
||||||
|
// ADC_CTRL,ADC_VBAT
|
||||||
|
GPIOA_ResetBits(GPIO_Pin_0 | GPIO_Pin_1);
|
||||||
|
GPIOA_ModeCfg(GPIO_Pin_0 | GPIO_Pin_1, GPIO_ModeIN_PD);
|
||||||
}
|
}
|
||||||
|
|
||||||
long reading = 0;
|
long reading = 0;
|
||||||
|
@ -197,16 +303,40 @@ void SensorData_Process(void)
|
||||||
PRINT("T=%d.%d \r\n", (int)temp, ((int)(temp * 100.0f) % 100));
|
PRINT("T=%d.%d \r\n", (int)temp, ((int)(temp * 100.0f) % 100));
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t wf5803_ProcessEvent(uint8_t task_id, uint16_t events)
|
// __HIGH_CODE
|
||||||
|
// __attribute__((noinline))
|
||||||
|
uint16_t WF5803_ProcessEvent(uint8_t task_id, uint16_t events)
|
||||||
{
|
{
|
||||||
if (events & WF5803_EVT_START)
|
if (events & WF5803_EVT_VCC)
|
||||||
|
{
|
||||||
|
if (vcc4_state == 0)
|
||||||
|
{
|
||||||
|
vcc4_state = 1;
|
||||||
|
// GPIOB_ModeCfg(GPIO_Pin_16, GPIO_ModeIN_PU);
|
||||||
|
|
||||||
|
// mDelaymS(20);
|
||||||
|
// GPIOB_SetBits(GPIO_Pin_16);
|
||||||
|
// GPIOB_ModeCfg(GPIO_Pin_16, GPIO_ModeOut_PP_5mA);
|
||||||
|
// GPIOB_SetBits(GPIO_Pin_16);
|
||||||
|
|
||||||
|
PRINT("WF5803_EVT_VCC\r\n");
|
||||||
|
}
|
||||||
|
tmos_start_task(wf5803_task_id, WF5803_EVT_START, MS1_TO_SYSTEM_TIME(20));
|
||||||
|
|
||||||
|
return (events ^ WF5803_EVT_VCC);
|
||||||
|
}
|
||||||
|
else if (events & WF5803_EVT_START)
|
||||||
{
|
{
|
||||||
// SensorData_Process();
|
// SensorData_Process();
|
||||||
// WF5803_WriteReg(0x30, 0x0a);
|
// WF5803_WriteReg(0x30, 0x0a);
|
||||||
|
|
||||||
|
vcc4_state = 1;
|
||||||
|
|
||||||
|
WF5803_Init();
|
||||||
|
|
||||||
WF5803_WriteReg(0x30, 0x0A);
|
WF5803_WriteReg(0x30, 0x0A);
|
||||||
|
|
||||||
tmos_start_task(Peripheral_TaskID, WF5803_EVT_READ, MS1_TO_SYSTEM_TIME(50));
|
tmos_start_task(wf5803_task_id, WF5803_EVT_READ, MS1_TO_SYSTEM_TIME(5));
|
||||||
return (events ^ WF5803_EVT_START);
|
return (events ^ WF5803_EVT_START);
|
||||||
}
|
}
|
||||||
else if (events & WF5803_EVT_READ)
|
else if (events & WF5803_EVT_READ)
|
||||||
|
@ -214,7 +344,13 @@ uint16_t wf5803_ProcessEvent(uint8_t task_id, uint16_t events)
|
||||||
SensorData_Process();
|
SensorData_Process();
|
||||||
// WF5803_WriteReg(0x30, 0x0a);
|
// WF5803_WriteReg(0x30, 0x0a);
|
||||||
|
|
||||||
tmos_start_task(Peripheral_TaskID, WF5803_EVT_START, MS1_TO_SYSTEM_TIME(800));
|
tmos_start_task(wf5803_task_id, WF5803_EVT_START, MS1_TO_SYSTEM_TIME(800));
|
||||||
|
|
||||||
|
// GPIOB_ResetBits(GPIO_Pin_16);
|
||||||
|
// GPIOB_ModeCfg(GPIO_Pin_16, GPIO_ModeIN_PD);
|
||||||
|
// PRINT("vcc4_state = 0\r\n");
|
||||||
|
|
||||||
|
vcc4_state = 0;
|
||||||
return (events ^ WF5803_EVT_READ);
|
return (events ^ WF5803_EVT_READ);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -222,10 +358,9 @@ uint16_t wf5803_ProcessEvent(uint8_t task_id, uint16_t events)
|
||||||
|
|
||||||
void BSPWF5803_Init(void)
|
void BSPWF5803_Init(void)
|
||||||
{
|
{
|
||||||
WF5803_Init();
|
// WF5803_Init();
|
||||||
Peripheral_TaskID = TMOS_ProcessEventRegister(wf5803_ProcessEvent);
|
wf5803_task_id = TMOS_ProcessEventRegister(WF5803_ProcessEvent);
|
||||||
// WF5803_WriteReg(0x30, 0x2B);
|
|
||||||
tmos_set_event(Peripheral_TaskID, WF5803_EVT_START);
|
tmos_set_event(wf5803_task_id, WF5803_EVT_START);
|
||||||
// tmos_start_task(Peripheral_TaskID, WF5803_EVT_READ, MS1_TO_SYSTEM_TIME(50));
|
// tmos_start_task(wf5803_task_id, WF5803_EVT_READ, MS1_TO_SYSTEM_TIME(50));
|
||||||
// PRINT("WF5803_Init\r\n");
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,17 +3,17 @@
|
||||||
|
|
||||||
#include "CH58x_common.h"
|
#include "CH58x_common.h"
|
||||||
|
|
||||||
#define WF5803_EVT_START 0x0010
|
#define WF5803_EVT_START (0x0001 << 0)
|
||||||
#define WF5803_EVT_READ 0x0100
|
#define WF5803_EVT_READ (0x0001 << 1)
|
||||||
|
#define WF5803_EVT_VCC (0x0001 << 2)
|
||||||
|
|
||||||
void WF5803_Init(void);
|
void WF5803_Init(void);
|
||||||
void WF5803_WriteReg(uint8_t Address, uint8_t value);
|
// void WF5803_WriteReg(uint8_t Address, uint8_t value);
|
||||||
uint8_t WF5803_ReadReg(uint8_t addr);
|
// uint8_t WF5803_ReadReg(uint8_t addr);
|
||||||
uint8_t *GetSensorData(void);
|
// uint8_t *GetSensorData(void);
|
||||||
void SensorData_Process(void);
|
// void SensorData_Process(void);
|
||||||
void BSPWF5803_Init(void);
|
void BSPWF5803_Init(void);
|
||||||
|
|
||||||
void WF5803_DeInit(void);
|
void WF5803_DeInit(void);
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
14
HAL/SLEEP.c
14
HAL/SLEEP.c
|
@ -58,6 +58,9 @@ 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) // 使用其他串口输出打印信息需要修改这行代码
|
#if(DEBUG == Debug_UART0) // 使用其他串口输出打印信息需要修改这行代码
|
||||||
while((R8_UART0_LSR & RB_LSR_TX_ALL_EMP) == 0)
|
while((R8_UART0_LSR & RB_LSR_TX_ALL_EMP) == 0)
|
||||||
{
|
{
|
||||||
|
@ -67,12 +70,21 @@ uint32_t CH58x_LowPower(uint32_t time)
|
||||||
// LOW POWER-sleep模式
|
// LOW POWER-sleep模式
|
||||||
if(!RTCTigFlag)
|
if(!RTCTigFlag)
|
||||||
{
|
{
|
||||||
|
// extern uint8_t volatile vcc4_state;
|
||||||
|
// if (vcc4_state == 0)
|
||||||
|
// {
|
||||||
|
// WF5803_DeInit();
|
||||||
|
// }
|
||||||
|
|
||||||
WF5803_DeInit();
|
WF5803_DeInit();
|
||||||
|
|
||||||
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偏置电流)
|
||||||
|
|
||||||
WF5803_Init();
|
// if (vcc4_state)
|
||||||
|
// {
|
||||||
|
// WF5803_Init();
|
||||||
|
// }
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue