本帖最后由 yyq006 于 2018-2-10 10:05 编辑
用STM32F103C8T6做了个模块,空闲时进入停机模式,有需要时再唤醒。本来程序运行的好好的,停机和唤醒都没有问题。今天改了一个数据计算的参数(与工作模式无关),重新编译了一下后停机命令就变成复位了,停机命令执行完直接跳到程序起点。有谁知道是怎么回事?
编译器用的是keil5,中间升级过pack。
- int main(void)
- {
- /* USER CODE BEGIN 1 */
- uint32_t tempbak;
- /* USER CODE END 1 */
- /* MCU Configuration----------------------------------------------------------*/
- /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
- HAL_Init();
- /* USER CODE BEGIN Init */
- /* USER CODE END Init */
- /* Configure the system clock */
- SystemClock_Config();
- /* USER CODE BEGIN SysInit */
- /* USER CODE END SysInit */
- /* Initialize all configured peripherals */
- MX_GPIO_Init();
- MX_DMA_Init();
- MX_ADC1_Init();
- MX_I2C1_Init();
- MX_USART1_UART_Init();
- MX_USART3_UART_Init();
- MX_TIM3_Init();
- MX_RTC_Init();
- MX_TIM4_Init();
- /* USER CODE BEGIN 2 */
- HAL_GPIO_WritePin(GPIOB,LED_B_Pin, GPIO_PIN_RESET);
- HAL_TIM_Base_Start_IT(&htim4);
- __HAL_RCC_PWR_CLK_ENABLE();
- //HAL_PWR_DisableWakeUpPin(PWR_CSR_EWUP); //½ûÖ¹wakeup PA0,×÷ΪÆÕͨÒý½Å
- __HAL_UART_ENABLE_IT(&huart1, UART_IT_IDLE);
- HAL_UART_Receive_DMA(&huart1, UsartType1.usartDMA_rxBuf, RECEIVELEN);
- __HAL_UART_ENABLE_IT(&huart3, UART_IT_IDLE);
- HAL_UART_Receive_DMA(&huart3, UsartType3.usartDMA_rxBuf, RECEIVELEN);
- HAL_ADC_Start_DMA(&hadc1, (uint32_t*)&ADC_Value, 12);
- HAL_GPIO_WritePin(GPIOA,G_DTR_Pin,GPIO_PIN_RESET);
- // MX680Q_Init();
- FLASH_If_Init();
- Readset();
- while(!adcok){};
- adcok=0;
- COLL_data.SYS_sta=0xff;
- if(BAT_id==4)COLL_data.SYS_sta&=0xf7;
- if(COLL_data.BAT_val==0)COLL_data.SYS_sta&=0xfd;
- if(HAL_GPIO_ReadPin(GPIOA,VIN_Pin)==1) //Ö÷µç¹¤×÷
- {
- Vext=1;
- COLL_data.power=0;
- HAL_TIM_Base_Start_IT(&htim3);
- if(BAT_id==2)
- {
- HAL_GPIO_WritePin(GPIOB,CHG_SEL_Pin,GPIO_PIN_RESET); //ÉèÖÃС³äµçµçÁ÷
- HAL_GPIO_WritePin(GPIOB,CHG_EN_Pin,GPIO_PIN_RESET); //Æô¶¯³äµç
- }
- if(BAT_id==3)
- {
- HAL_GPIO_WritePin(GPIOB,CHG_SEL_Pin,GPIO_PIN_SET); //ÉèÖôó³äµçµçÁ÷
- HAL_GPIO_WritePin(GPIOB,CHG_EN_Pin,GPIO_PIN_RESET); //Æô¶¯³äµç
- }
- }
-
- /* USER CODE END 2 */
- /* Infinite loop */
- /* USER CODE BEGIN WHILE */
- HAL_RTC_GetTime(&hrtc, &rtctime1, RTC_FORMAT_BCD);
- while(1)
- {
-
- HAL_GPIO_TogglePin(GPIOB,LED_R_Pin);
- HAL_Delay(100);
-
- // HAL_GPIO_WritePin(GPIOB,LED_B_Pin,GPIO_PIN_SET);
- rtcalarm1.Alarm=RTC_ALARM_A;
- rtcalarm1.AlarmTime.Hours=rtctime1.Hours;
- rtcalarm1.AlarmTime.Minutes=rtctime1.Minutes;
- rtcalarm1.AlarmTime.Seconds=rtctime1.Seconds+0x10;
- if(rtcalarm1.AlarmTime.Seconds >0x60)
- {rtcalarm1.AlarmTime.Seconds-=0x60;rtcalarm1.AlarmTime.Minutes++;}
- if(HAL_RTC_SetAlarm_IT(&hrtc, &rtcalarm1, RTC_FORMAT_BCD)!=HAL_OK)
- {
-
- Error_Handler();
- }
-
- HAL_GPIO_WritePin(GPIOA,G_DTR_Pin,GPIO_PIN_SET);
- HAL_ADC_Stop(&hadc1);
- stop=0;
- HAL_PWR_EnterSTOPMode(PWR_MAINREGULATOR_ON, PWR_STOPENTRY_WFI); //stop
- SYSCLKConfig_STOP();
- HAL_GPIO_WritePin(GPIOB,LED_R_Pin,GPIO_PIN_RESET);
- HAL_Delay (100);
- HAL_RTC_GetTime(&hrtc, &rtctime1, RTC_FORMAT_BCD);
- HAL_UART_Transmit_IT(&huart1, (uint8_t *)&rtctime1 , 3);
- HAL_GPIO_WritePin(GPIOB,LED_R_Pin,GPIO_PIN_SET);
- if(stop==2)
- {
- HAL_GPIO_WritePin(GPIOA,G_DTR_Pin,GPIO_PIN_RESET);
- HAL_Delay(20);
- //readsms();
- }
- }
复制代码 |
重新设置了,还是一样。改的是这个位置,判断电池类型的,改了比较的阈值。7000改成6500,4000改成4500.
确实是只改了判断电池类型的阈值。因为程序都已经基本调好了,测试中发现电池类型有判断错误的,就改了一下比较的数值。我也很奇怪啊。
if(temp>10000){BAT_id=4;COLL_data.SYS_sta&=0xf7;}
else if(temp>6500){BAT_id=3;COLL_data.SYS_sta|=0x08;}
else if(temp>4500){BAT_id=1;COLL_data.SYS_sta|=0x08;}
else {BAT_id=2;COLL_data.SYS_sta|=0x08;}