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

Adding support for wakeup from TwoWire #72

Open
mkals opened this issue Jun 14, 2022 · 9 comments
Open

Adding support for wakeup from TwoWire #72

mkals opened this issue Jun 14, 2022 · 9 comments

Comments

@mkals
Copy link

mkals commented Jun 14, 2022

Are there any plans for implementing the enableWakeupFrom(TwoWire ...) function? This would be very useful to have!

@mkals
Copy link
Author

mkals commented Jun 14, 2022

If it is not too hard I could take a look at implementing it myself, but I am assuming there may be a reason for it to have been left out of the library so far.

@fpistm
Copy link
Member

fpistm commented Jun 15, 2022

I @mkals
Main reason is the time. I don't know if it can be added easily across all series.
If you want you can try to implement it and proposed a PR.

@mkals
Copy link
Author

mkals commented Jun 15, 2022

Ok, thanks for your quick reply! I have been looking into this for a few hours now, but I am struggling. The core needs to wake in time for the address specified in the I2C packet to be parsed, but I am not sure how to can be ensured with the delays to wake from the sleep modes. Any suggestions as to where I should start looking for implementing this? There are no options related to I2C wake from sleep in the STM32CubeMX tool for example..

@fpistm
Copy link
Member

fpistm commented Jun 16, 2022

Well, in that case I try to find an example project in the STM32CubeFw.
IIWR you work with L010RB. There is no project but for L011K4 it exists:
https://github.com/STMicroelectronics/STM32CubeL0/tree/master/Projects/NUCLEO-L011K4/Examples/I2C/I2C_WakeUpFromStop

From Reference manual

image

@mkals
Copy link
Author

mkals commented Jun 16, 2022

Thanks a lot @fpistm! I'll see what I can figure out.

@mkals
Copy link
Author

mkals commented Jun 16, 2022

By setting the I2C1->CR1 |= I2C_CR1_WUPEN; bit, the STM32L0 wakes on I2C from LowPower.sleep(), but it does not seem to wake on LowPower.deepSleep() or HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI);.

I make sure I use HSI by calling __HAL_RCC_WAKEUPSTOP_CLK_CONFIG(RCC_STOP_WAKEUPCLOCK_HSI); before going to sleep. I'm using the STM32L051C8, which supports I2C wakeup from stop on I2C1 according to the datasheet.

Screenshot 2022-06-16 at 10 50 19

@mkals
Copy link
Author

mkals commented Jun 16, 2022

I have also tried setting other bits in the I2C_CR1 register manually, but it does not make a difference.

        SET_BIT(I2C1->CR1, I2C_CR1_PE); 
        SET_BIT(I2C1->CR1, I2C_CR1_WUPEN); 
        SET_BIT(I2C1->CR1, I2C_CR1_STOPIE); 
        SET_BIT(I2C1->CR1, I2C_CR1_RXIE); 
        SET_BIT(I2C1->CR1, I2C_CR1_ADDRIE); 
        SET_BIT(I2C1->CR1, I2C_CR1_NACKIE);
        CLEAR_BIT(I2C1->CR1, I2C_CR1_NOSTRETCH);

@fpistm
Copy link
Member

fpistm commented Jun 16, 2022

Hard to tell.
We should try to mimic this:
https://github.com/STMicroelectronics/STM32CubeL0/blob/master/Projects/NUCLEO-L011K4/Examples/I2C/I2C_WakeUpFromStop/Src/main.c#L199-L217

Best thing would be to properly add those mechanism to Wire.

@asukiaaa
Copy link

asukiaaa commented May 2, 2023

Thank you for the infomation.

I'm using stm32l432kc and tried but not succeded in handleing i2c with low poer.
Could you give me some advice?

=== What I tried ===

I called HAL_I2CEx_EnableWakeUp function (with the following code) after i2c_custom_init ( https://github.com/stm32duino/Arduino_Core_STM32/blob/565f3ecc1c2c12f9577cf648c292a5ddc5b7eb6b/libraries/Wire/src/utility/twi.c#L782-L785 ) which is called in Wire.begin().

        // manualy add
        if (HAL_I2CEx_EnableWakeUp(handle)) {
          // SERIAL_DEBUG.println("error on enabling wakeup");
          Error_Handler();
        }

I called LowPower.enableWakeupFrom(&Serial, []() {}); to enable stop 0 or 1 because i2c1 of stm32l4 cannot wakeup from stop 2.

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

No branches or pull requests

3 participants