cancel
Showing results for 
Search instead for 
Did you mean: 

Stm8s003 crashing or resetting occasionally when using halt() + GPIO ISR wakeup

vinodstanur
Associate II
#include "stm8s.h"
 
//My delay for testing. Calibrated for milli seconds.
 
void delay2(uint16_t ms)
{
	volatile uint16_t a = 100;
	while(ms--) {
		a = 1800;
		while(a--);
	}
}
 
void main(void)
{ 
  //CLK_DeInit();
	CLK_HSIPrescalerConfig(CLK_PRESCALER_HSIDIV1);
 
  /* Clock divider to HSI/1 */
  //CLK_SYSCLKConfig(CLK_PRESCALER_CPUDIV128);
 
  //CLK_ClockSwitchConfig(CLK_SWITCHMODE_MANUAL, CLK_SOURCE_LSI, DISABLE, CLK_CURRENTCLOCKSTATE_DISABLE);
  
 	/* Initialize LEDs in Output Push-Pull Mode */
  GPIO_Init(LED_PORT, (LED_PIN), GPIO_MODE_OUT_PP_LOW_FAST);
  
  /* Initialize PB0 (BUTTON) in Input Pullup Mode with Interrupt */
  GPIO_Init(BUTTON_PORT, BUTTON_PIN, GPIO_MODE_IN_PU_IT);
 
  /* Initialize the Interrupt sensitivity */
	EXTI_DeInit();
 
  EXTI_SetExtIntSensitivity(EXTI_PORT_GPIOC, EXTI_SENSITIVITY_FALL_ONLY);
  EXTI_SetTLISensitivity(EXTI_TLISENSITIVITY_FALL_ONLY);
  enableInterrupts();    //GPIO ISR is not populated because I am using it to just wakeup CPU.
	 
 
	int i;
	for( i = 0; i < 10; i++)  {       //RESET DETECTION CODE 
	  GPIO_WriteLow(LED_PORT,LED_PIN);
          delay2(100);		
	  GPIO_WriteHigh(LED_PORT,LED_PIN);
          delay2(100);		
	}
 
       //APPLICATION TEST CODE TO FIND RESET BUG. It is toggling the LED on button click, but occasionally chip is getting reset. 
      while(1) {         //CHIP IS RESETTING OCCASIONALLY WHILE I am continuously triggering the button !!!! I don't know why... 
         halt(); //Push button press will wake it up.
         GPIO_WriteLow(LED_PORT,LED_PIN);  //Ignoring debounce while testing...
         halt(); //Push button press will wake it up.
         GPIO_WriteHigh(LED_PORT,LED_PIN); //Ignoring debounce while testing...
      }
 
}
 

I haven't changed any option bytes and what ever is there by default is still there.

Also I haven't configured any watchdog and I am not finding any watchdog reset issue because if I am not pressing the button, the LED state is not changed that means the chip is not resetting. But while I am pressing the button, one out of 10 time or one out of 20 times it resets the chip. I haven't configured anything before using halt() feature, I just measured the current at default halt mode and I am okay with it, so I just continued using it. But now I am facing occasional chip reset or very rare chip hanging.

0 REPLIES 0