cancel
Showing results for 
Search instead for 
Did you mean: 

How to use the tamper level detection in STM2L0?

Denson Li
Associate
Posted on June 24, 2018 at 15:09

 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 Tamper 

  stamperstructure.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);

 }

 

} 0690X0000060LQgQAM.png

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 .

1 REPLY 1
Denson Li
Associate
Posted on June 28, 2018 at 15:43

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 .