Skip to content

Sleep and interrupt in Sduino #147

Open

Description

@chirag-uAtech

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.

Activity

  1. MR-IC commented on Dec 5, 2023

    @MR-IC

    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.

  2. chirag-uAtech commented on Jan 8, 2024

    @chirag-uAtech
    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.

  3. g1ra commented on Dec 19, 2024

    @g1ra

    Hi . I found wfi at

    #define wfi() _wfi_() /* Wait For Interrupt */

    Please help How can I set pin for interrup wfi and continue running the program ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions