Use SPI from deep_sleep_wake_stub
Posted: Tue Jul 16, 2024 7:02 pm
Hi, I am looking for help on a very niche topic,
use the SPI in deep_sleep_wake_stub.
I have a low power application, where I want to access a display via SPI and send a quick "2 Byte" transfer, then go back to sleep.
If I can do this from the deep_sleep_wake_stub, then I measured a save of 33% of power.
I have tried manually driving the GPIOs to send the command:
But this does not seem to work ok.
I canĀ“t use the SPI.h commands since this is outside the RTC_IRAM.
Any way to drive the SPI registers manually without the SPI.h?
Any idea or solutions?
Thanks.
use the SPI in deep_sleep_wake_stub.
I have a low power application, where I want to access a display via SPI and send a quick "2 Byte" transfer, then go back to sleep.
If I can do this from the deep_sleep_wake_stub, then I measured a save of 33% of power.
I have tried manually driving the GPIOs to send the command:
Code: Select all
void RTC_IRAM_ATTR delayMicroseconds(uint32_t us) {
const auto ticks = esp_rom_get_cpu_ticks_per_us();
auto m = esp_cpu_get_cycle_count();
auto e = (m + us * ticks);
while (esp_cpu_get_cycle_count() < e) {
asm volatile("nop");
}
}
void RTC_IRAM_ATTR delayNanoseconds(uint32_t ns) {
const auto ticks = esp_rom_get_cpu_ticks_per_us();
auto m = esp_cpu_get_cycle_count();
auto e = (m + ns * ticks / 1000);
while (esp_cpu_get_cycle_count() < e) {
asm volatile("nop");
}
}
void RTC_IRAM_ATTR _transfer(uint8_t value)
{
for (auto i=0; i<8; i++)
{
// Set value
GPIO_OUTPUT_SET(13, (value >> (7-i)) & 0b1);
// Cycle Clock
GPIO_OUTPUT_SET(14, 1);
delayNanoseconds(1000/20);
GPIO_OUTPUT_SET(14, 0);
delayNanoseconds(1000/20);
}
}
void RTC_IRAM_ATTR _transferCommand(uint8_t value)
{
GPIO_OUTPUT_SET(HW::DisplayPin::Dc, 0);
_transfer(value);
GPIO_OUTPUT_SET(HW::DisplayPin::Dc, 1);
}
I canĀ“t use the SPI.h commands since this is outside the RTC_IRAM.
Any way to drive the SPI registers manually without the SPI.h?
Any idea or solutions?
Thanks.