Skip to main content
Visitor II
October 17, 2019
Question

long pressing can not wakeup stm8l152

  • October 17, 2019
  • 0 replies
  • 515 views
/**
 ******************************************************************************
 * @file Project/STM8L15x_StdPeriph_Template/main.c
 * @author MCD Application Team
 * @version V1.6.1
 * @date 30-September-2014
 * @brief Main program body
 ******************************************************************************
 * @attention
 *
 * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
 *
 * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
 * You may not use this file except in compliance with the License.
 * You may obtain a copy of the License at:
 *
 * http://www.st.com/software_license_agreement_liberty_v2
 *
 * Unless required by applicable law or agreed to in writing, software 
 * distributed under the License is distributed on an "AS IS" BASIS, 
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 ******************************************************************************
 */
 
/* Includes ------------------------------------------------------------------*/
#include "stm8l15x.h"
 
/** @addtogroup STM8L15x_StdPeriph_Template
 * @{
 */
 
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
 
/* Private functions ---------------------------------------------------------*/
void delay_ms(u16 n_ms)
{
 
 CLK_PeripheralClockConfig(CLK_Peripheral_TIM2, ENABLE);
 
/* Init TIMER 4 prescaler: / (2^6) = /64 */
 //TIM2->PSCR = 6;
 TIM2->PSCR = 3;
 
/* HSI div by 1 --> Auto-Reload value: 16M / 64 = 1/4M, 1/4M / 1k = 250*/
 TIM2->ARRH = 0;
 TIM2->ARRL = 250;
 
/* Counter value: 2, to compensate the initialization of TIMER*/
 
 TIM2->CNTRH = 0;
 TIM2->CNTRL = 2;
 
/* clear update flag */
 TIM2->SR1 &= ~TIM_SR1_UIF;
 
/* Enable Counter */
 TIM2->CR1 |= TIM_CR1_CEN;
 
 while(n_ms--)
 {
 while((TIM2->SR1 & TIM_SR1_UIF) == 0) ;
 TIM2->SR1 &= ~TIM_SR1_UIF;
 }
 
/* Disable Counter */
 TIM2->CR1 &= ~TIM_CR1_CEN;
}
 
 
void EXTI_setup(void)
{
 
 ITC_DeInit();
 ITC_SetSoftwarePriority(EXTI7_IRQn, ITC_PriorityLevel_1);
 
 
 EXTI_DeInit();
 
 EXTI_SetPinSensitivity(GPIO_Pin_7, EXTI_Trigger_Falling);
 //EXTI_SetPinSensitivity(GPIO_Pin_7, EXTI_Trigger_Rising);
 //EXTI_SetTLISensitivity(EXTI_TLISENSITIVITY_FALL_ONLY);
 enableInterrupts();
 
}
 
void usart_setup(void)
{
 GPIO_ExternalPullUpConfig(GPIOC, GPIO_Pin_3, ENABLE);
 GPIO_ExternalPullUpConfig(GPIOC, GPIO_Pin_2, ENABLE);
 
 CLK_PeripheralClockConfig(CLK_Peripheral_USART1, ENABLE);
 USART_DeInit(USART1);
 USART_Init(USART1, (uint32_t)9600, USART_WordLength_8b, USART_StopBits_1,
 USART_Parity_No, (USART_Mode_TypeDef)(USART_Mode_Tx | USART_Mode_Rx));
 
 
 USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);
 USART_Cmd(USART1, ENABLE);
 
}
/**
 * @brief Main program.
 * @param None
 * @retval None
 */
void main(void)
{
 /* Infinite loop */
 
 CLK_SYSCLKDivConfig(CLK_SYSCLKDiv_8);
 
 GPIO_Init(GPIOE, GPIO_Pin_7, GPIO_Mode_In_PU_IT);
 EXTI_setup();
 
 
loop:
 halt(); // first active
 
 usart_setup();
 USART_SendData8(USART1, 'a');
 
 delay_ms(5000);
 
 if(GPIO_ReadInputDataBit(GPIOE, GPIO_Pin_7) == RESET)
 {
 //i++;
 //if(i == 25)
 USART_SendData8(USART1, 'n');
 while (USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET);
 
 //USART_SendData8(USART1, 'G');
 goto loop;
 
 }
 else
 { 
 USART_SendData8(USART1, 'C');
 while (USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET);
 } 
 
 
 USART_SendData8(USART1, 'b');
 
 while (1)
 {
 }
}
 
#ifdef USE_FULL_ASSERT
 
/**
 * @brief Reports the name of the source file and the source line number
 * where the assert_param error has occurred.
 * @param file: pointer to the source file name
 * @param line: assert_param error line source number
 * @retval None
 */
void assert_failed(uint8_t* file, uint32_t line)
{ 
 /* User can add his own implementation to report the file name and line number,
 ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
 
 /* Infinite loop */
 while (1)
 {
 }
}
#endif
 
/**
 * @}
 */
 
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

key pe7 release , connect to nothing,

when press pe7 connect to GND

when in long press, i can not wakeup, until release

INTERRUPT_HANDLER(EXTI7_IRQHandler,15)
{
 /* In order to detect unexpected events during development,
 it is recommended to set a breakpoint on the following instruction.
 */
 EXTI_ClearITPendingBit(EXTI_IT_Pin7);
}

    This topic has been closed for replies.