Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sleep and interrupt in Sduino #147

Open
chirag-uAtech opened this issue Feb 17, 2023 · 2 comments
Open

Sleep and interrupt in Sduino #147

chirag-uAtech opened this issue Feb 17, 2023 · 2 comments

Comments

@chirag-uAtech
Copy link

Hi community,

I am new to Sduino and Stm8s. Have some prior experience working with Arduino, AVRs & STM32. I chose STM8s due to its lower price for a project. After developing the project, I need to reduce the current usage as much as possible to make the system Standby Mode. I have tried and failed while using Interrupt with a button.

For the sake of clear understanding, I want to develop a project that can control LED using a Push Button. I want the system to be in sleep mode for the rest of the time.

The sduino repo contains an example code for interrupt, that is:

#define BUTTON	PA2

volatile uint8_t flag = 0;

void on_button_pressed(void)
{
	flag = 1;
}
void setup()
{
	pinMode(LED_BUILTIN, OUTPUT);
	digitalWrite(LED_BUILTIN, 1);	// turn off the LED

	pinMode(BUTTON, INPUT_PULLUP);

	attachInterrupt(digitalPinToInterrupt(BUTTON), on_button_pressed, FALLING);
}
void loop()
{
	if (flag) {
		digitalWrite(LED_BUILTIN, 0);
		delay(300);
		digitalWrite(LED_BUILTIN, 1);
		flag = 0;
	}
}

The code does not get compiled in Arduino. On searching the internet for a bit, I found changing digitalPinToInterrupt(pin); to digitalPinToPort(pin); may work. The code gets compiled now but the result remains unexpected.

After digging some more into the problem, I found one more possible solution:

GPIO_Init(GPIOA, GPIO_PIN_3, GPIO_MODE_IN_FL_IT);
disableInterrupts();
EXTI_SetExtIntSensitivity( EXTI_PORT_GPIOA, EXTI_SENSITIVITY_RISE_ONLY);  
enableInterrupts();
attachInterrupt(INT_PORTA & 0xFF,ISR,0);

Source: #92

I tried this as well in my code. But still unable to make it work.

My requirement is to attachInterrupt on pin PA2 & use it to wake from sleep. Similar issues have been raised multiple times but not resolved completely.

Kindly provide some input on this problem.

@MR-IC
Copy link

MR-IC commented Dec 5, 2023

You can implement it simply by writing a command "wfi" it halts the microcontroller and waits for the interrupt to occur.

Before entering this command make sure that you have proper interrupt attached.

@chirag-uAtech
Copy link
Author

@MR-IC How do I do that? I am new to development on STM8 and can't find any function in the whole sduino library relating to this. It would help greatly if you can attach a simple code to go to sleep and then wake from button using EXTI.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants