2018-06-24 06:09 AM
Today i want to implement the tamper level detection ,but it doesn't works. Is there someone has this using experience? Please help me .
Below is my code.
void init_BspTamper()
{RTC_TamperTypeDef stamperstructure; RtcHandle.Instance = RTC; RtcHandle.Init.HourFormat = RTC_HOURFORMAT_24; RtcHandle.Init.AsynchPrediv = RTC_ASYNCH_PREDIV; RtcHandle.Init.SynchPrediv = RTC_SYNCH_PREDIV; RtcHandle.Init.OutPut = RTC_OUTPUT_DISABLE; RtcHandle.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH; RtcHandle.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN; if (HAL_RTC_Init(&RtcHandle) != HAL_OK) { /* Initialization Error */ //Error_Handler(); } //Configure RTC Tamperstamperstructure.Tamper = RTC_TAMPER_1;
stamperstructure.Trigger = RTC_TAMPERTRIGGER_LOWLEVEL; stamperstructure.Filter = RTC_TAMPERFILTER_2SAMPLE;//定义采样次数 stamperstructure.SamplingFrequency = RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV256; stamperstructure.PrechargeDuration = RTC_TAMPERPRECHARGEDURATION_4RTCCLK; stamperstructure.TamperPullUp = RTC_TAMPER_PULLUP_ENABLE; stamperstructure.TimeStampOnTamperDetection = RTC_TIMESTAMPONTAMPERDETECTION_DISABLE; stamperstructure.NoErase = RTC_TAMPER_ERASE_BACKUP_ENABLE; stamperstructure.MaskFlag = RTC_TAMPERMASK_FLAG_DISABLE; //stamperstructure.Interrupt = RTC_TAMPER1_INTERRUPT; if (HAL_RTCEx_SetTamper(&RtcHandle, &stamperstructure) != HAL_OK) { /* Initialization Error */ //Error_Handler(); }} int main () { HAL_Init(); //------------------------------------------------ //configure the systerm clock SystemClock_Config();//init_BspButtonKey();
BspLed_configure(); init_BspTamper(); __HAL_RTC_TAMPER_CLEAR_FLAG(&RtcHandle,RTC_FLAG_TAMP1F);while(__HAL_RTC_TAMPER_GET_FLAG(&RtcHandle, RTC_FLAG_TAMP1F)== RESET)
{ LED1_toggle(); HAL_Delay(1000); } __HAL_RTC_TAMPER_CLEAR_FLAG(&RtcHandle,RTC_FLAG_TAMP1F); while(1) {LED1_toggle();
HAL_Delay(100);
} }The MCU is stm32l052c8, and the PC13 is used as tamper.
when i pressed the button down, now tamper occoured ,the interrupt flag doesn't changed .
2018-06-28 06:43 AM
I have solve it by myself. The configuration just similar to edge detection .enable the interrupt ,and enable the filter, set low level detection, and net to set exti line ,enable the RTC interrupt .so on .