Quantcast
Viewing all articles
Browse latest Browse all 4537

General • Pico interrupt handler hangs when displaying Waveshare eink display

Hello,

I have really weird problem with my Pico development. I am building small meteorological sensor using bme280 and displaying the data on eink from waveshare. I have some success with this, mainly the screen and sensor is working correctly. I was also able to use deep sleep mode to preserve energy and this is working fine. My next step is to add some switches to provide some settings. I am building an interrupt handler that will switch pico into different screen but here I hit a wall. I am able to connect switch to pico and fire handler function on press. Returning to main loop after handler is complete also works fine. However when I try to display new data the entire system hangs. Here is a sample of my code

Code:

static UBYTE *Frame;static bool isMainWindowVisible = false;void gpio_callback(uint gpio, uint32_t events) {    // Put the GPIO event(s) that just happened into event_str    // so we can print it    printf("GPIO %d\n", gpio);    if(Frame == NULL) {        printf("init display\n");        UBYTE *Frame = init_display();    }    printf("clear screen\n");    Paint_Clear(WHITE);    printf("prepare text\n");    int len = snprintf(NULL, 0, "IRQ %d", gpio);    char *result = malloc(len + 1);    snprintf(result, len + 1, "IRQ %d", gpio);    printf("draw text\n");    Paint_DrawString_EN(10, 10, result, LARGE_FONT, WHITE, BLACK);    printf("display frame\n");    // EPD_3IN7_4Gray_Display(Frame);    printf("%s\n", result);    isMainWindowVisible = false;}int main() {    // Initialize chosen serial port    stdio_init_all();     struct reading reading = {0, 0, 0, -100, -100, -100};    uint waitTime = 15;    printf("Pico Started...\r\n");    printf("Starting EPD.......\r\n");    Frame = init_display();    if(Frame == NULL) {        printf("Failed to apply for black memory...\r\n");        return -1;    }    const unsigned char* background = get_background();    set_background(Frame, background);    isMainWindowVisible = true;    gpio_set_irq_enabled_with_callback(6, GPIO_IRQ_EDGE_RISE , true, &gpio_callback);    while(true) {        printf("Display sensor values\n");        if (!isMainWindowVisible) {            printf("Reinit background\n");            set_background(Frame, background);            isMainWindowVisible = true;        }        display_values(DATA_FONT, Frame, reading);        EPD_3IN7_4Gray_Display(Frame);        sleep_ms(1000 * waitTime);    }}
when I uncomment EPD_3IN7_4Gray_Display(Frame); call that should send new data to the screen the screen is refreshed with the new data but it does not return from the handler.
With the epd call commented I got all printf in the console
GPIO 6
clear screen
prepare text
draw text
display frame
IRQ 6

with uncommented I see only
GPIO 6

I tried reinitializing screen in the handler and it does not work, this time I do not even see the updated text or even clear screen.
I tried using different EPD, I have 3.7inch and 2.9inch versions and the result in hanging is the same.
Is there something about interrupts that can cause issues with SPI interface? I am connecting the screen spi0 on pins 17-19 and 20-22 are for busy, dc, and reset.

Statistics: Posted by Zefiryn — Sat Feb 15, 2025 11:14 pm — Replies 0 — Views 32



Viewing all articles
Browse latest Browse all 4537

Trending Articles