Page 1 of 1

About manage I2C from deep sleep wake stub

Posted: Tue Sep 11, 2018 10:53 am
by Dav_FR
Hello!

I have a case where I need to speak with a I2C I/O Multiplexer before to wake up the device (other wise the device will not wake up correctly). To solve this my intention or what I'm trying is to set up a wake stub function to speak with the I/O multiplexer via I2C before the wake up.

Inside of the wake stub I tried to work with soc/rtc_i2c_reg.h and soc/i2c_reg.h registers, reading-writing-reading the registers to check the interaction with them. See code in ANEX1.

Just RTC_I2C registers changed:

RTC_SCLL: 0
SCLL: 0
RTC_SCLL: 40
SCLL: 0

So I guess that I must work with RTC registers (we are in deep sleep so it should be the normal) but I want to be sure and know if there is some restriction to work with this kind of registers such as 'only available for ULP'. Or maybe I'm wrong and I must work with soc/i2c_reg.h registers. So the first question that arises to me is which register set should I use to manage the I2C from deep sleep?

To place the data to be send via I2C I found information about the use of I2C_DATA_APB_REG, I2C_NONFIFO_EN to 0 for soc/i2c_reg.h, but in case of work with RTC_I2C registers I'm trying to understand where the data must be placed, I want to write 2 byte (1 I2C address with write bit + 1 I/O bitmask). According to the description, RTC_I2C_DATA_REG registers seems that is used to receive bytes, but where to place data to write using the RTC_I2C?

From my opinion ULP is not an option since this is not a sensor to be read during the time, is to modify the configuration of a TPS connected to the I/O multiplexer before to wake up the device. I'm open to ideas (but no to carry out hw modifications if there is no other option).

Thanks you in advance and sorry for disturb.


ANNEX1:

Code: Select all

    uint32_t rtc_val = 0;
    uint32_t val = 0;

    rtc_val = READ_PERI_REG(RTC_I2C_SCL_LOW_PERIOD_REG); //low half period in rtc_fast_clk cycles
    val = READ_PERI_REG(I2C_SCL_LOW_PERIOD_REG(0)); //low half period in rtc_fast_clk cycles

	ets_printf(RTC_SCLL,rtc_val);
	ets_printf(SCLL,val);

    // Wait for UART to end transmitting.
    while (REG_GET_FIELD(UART_STATUS_REG(0), UART_ST_UTX_OUT)) {
        ;
    }

	WRITE_PERI_REG(RTC_I2C_SCL_LOW_PERIOD_REG,40); //low half period in rtc_fast_clk cycles
	WRITE_PERI_REG(I2C_SCL_LOW_PERIOD_REG(0),40); //low half period in rtc_fast_clk cycles


	rtc_val = READ_PERI_REG(RTC_I2C_SCL_LOW_PERIOD_REG); //low half period in rtc_fast_clk cycles
    val = READ_PERI_REG(I2C_SCL_LOW_PERIOD_REG(0)); //low half period in rtc_fast_clk cycles

	ets_printf(RTC_SCLL,rtc_val);
	ets_printf(SCLL,val);

    // Wait for UART to end transmitting.
    while (REG_GET_FIELD(UART_STATUS_REG(0), UART_ST_UTX_OUT)) {
        ;
    }
    

Re: About manage I2C from deep sleep wake stub

Posted: Tue Sep 11, 2018 10:58 am
by WiFive
Wake stub is running on main CPU but you have to enable peripheral clock before you can talk to it

Re: About manage I2C from deep sleep wake stub

Posted: Tue Sep 11, 2018 11:06 am
by Dav_FR
Hi WiFive,

Thanks for your fast reply.

Do you mean use esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_ON); before to sleep? I'm doing it. I found this information in other forum thread.

Best regards

Re: About manage I2C from deep sleep wake stub

Posted: Tue Sep 11, 2018 11:34 am
by WiFive
No

Re: About manage I2C from deep sleep wake stub

Posted: Tue Sep 11, 2018 12:15 pm
by Dav_FR
Regarding peripheral clock I found the DPORT_PERIP_CLK_EN_REG register so I tried with (both in 0 and 1):

DPORT_SET_PERI_REG_MASK(DPORT_PERIP_CLK_EN_REG, DPORT_I2C_EXT0_CLK_EN);

But the result is the same. Is that what you're talking about?

Re: About manage I2C from deep sleep wake stub

Posted: Tue Apr 14, 2020 9:27 pm
by eccessivo
Hi all and thank you in advance i am new to this forum.
I have the same needs: send 2 bytes by I2c to control an external device, and i have to do this from the wake up stub to save time.
I wonder if you had some lucky on getting rid of this.
Thank you
Guido

Re: About manage I2C from deep sleep wake stub

Posted: Wed Apr 22, 2020 10:24 pm
by eccessivo
I solved my self writing some function to create a software I2C on gpio0 and gpio2 . I used all ROM function to create the bitbang so it works perfectly in the wakeup stub.