1
\$\begingroup\$

I'm working on a graphic interface that uses an ESP32 alongside a Nokia 1616 LCD.
I am editing old code that someone wrote and it works correctly and it is based on FreeRTOS and I am trying to add a scrolling text to the LCD.
The tasks that should work simultaneously are Tasktimerhandle, SendDatahandle and Task1code.
The Nokia 1616 LCD works with SPI and with the function Lcd_string_english I can draw a string on LCD with a specific coordinates.
I draw the string then I wait for 125ms and during this time other tasks can be done and then the LCD is cleared and then a new string is shown on LCD shifted by 1 that makes the illusion of a scrolling text.

I can do the scrolling alone using a for loop but some other tasks should be done, for example a prompt must be shown on above and a scrolling text in below while the user can enter a number which is shown in the middle etc.

When I try to edit the code and add a semaphore and the task for scrolling, the interface works but it seems like the task that I wrote is ignored and it doesn't show the floating text on the LCD.

Here is the main part of my code: what might be the problem?

#ifdef FREERTOS
SemaphoreHandle_t sema_v;
SemaphoreHandle_t sema_v_1;
SemaphoreHandle_t sema_timer;
SemaphoreHandle_t sema_v_2;
void Tasktimerhandle(void *pvParameters);
void SendDatahandle(void *pvParameters);
void Task1code(void *pvParameters);
#endif

void setup()
{        
#ifdef FREERTOS
    .
    .
    .
    xTaskCreatePinnedToCore(Tasktimerhandle, "Tasktimerhandle", 50000, NULL, 1 // priority
      , NULL, 0); /* pin task to core 1 */
    xTaskCreatePinnedToCore(Task1code, "Task1code", 50000, NULL, 0 // priority
      , NULL, 1); /* pin task to core 1 */

    xTaskCreatePinnedToCore(SendDatahandle, "SendDatahandle", 50000, NULL, 1 // priority
      , NULL, 1); /* pin task to core 0 */

    /* create  binary semaphore for send signal to send to server task */
    sema_v = xSemaphoreCreateCounting(3, 0);
    sema_v_1 = xSemaphoreCreateCounting(3, 0);
    sema_timer = xSemaphoreCreateCounting(3, 0);
    sema_v_2 = xSemaphoreCreateCounting(3, 0);
#endif

#ifndef FREERTOS
    .
    .
    .
#endif
}

void loop()
{
#ifndef FREERTOS         
    Keypadtimer_handle();
    Wifi_check();

#else
    vTaskDelete(NULL);
#endif
}        

#ifdef FREERTOS
/*timer task*/
void Tasktimerhandle(void *pvParameters)
{
    (void)pvParameters;
    keypad_init();
    Lcd_init();
    Show_homepage();
    Keypadtimer_init();
    vTaskDelay(2000);
    EE_init();
    for (;;)
    {
        if (xSemaphoreTake(sema_timer, portMAX_DELAY) == pdTRUE)
        {
            .
            .
            .
        }
    }
}
#endif

/*check internet task */
void SendDatahandle(void *pvParameters)
{
    (void)pvParameters;
    .
    .
    .
    bool success;
    SendTo_Server_Status serverstatus;
    for (;;)
    {
        if (xSemaphoreTake(sema_v, 300) == pdPASS)
        {
            xSemaphoreGive(sema_v_1);
            xSemaphoreGive(sema_v_2);

            EEprom_status ee;
            EEprom_status ee_1;
            vTaskDelay(200);

            if (Birthdate[5] != 0)
            {
                serverstatus = SendToServer(Birthdate);
            }
            else
            {
                serverstatus = SendToServer(number);
            }
            birth_flag = 0;
            .
            .
            .
            xSemaphoreGive(sema_v);
        }

        .
        .
        .
    }
}

void Task1code(void *pvParameters)
{
    (void)pvParameters;

    for (;;)
    {
        xSemaphoreTake(sema_v_2,portMAX_DELAY);
        for (int i = 0; i < 160; i += 5)
        {
            Lcd_string_english("TCCO.IR", u8g2_font_timR24_tr, i, 110, WHITE, GRAY);
            vTaskDelay(pdMS_TO_TICKS(125));
            LCD_CLEAR_SCROLLING();          
        }
        xSemaphoreGive(sema_v_2);
    }
}    
#endif
\$\endgroup\$
18
  • 1
    \$\begingroup\$ Please check the serial UART output, there is usually some clue as to the cause of a crash/reboot there. Then read about the Minimal, Reproducible Example. Start removing stuff from your code until it doesn't crash anymore. Most likely you'll solve it yourself this way, and if not, you'll have a small piece of code that'll be much easier for us to look at and check. \$\endgroup\$
    – TypeIA
    Commented Sep 3, 2022 at 5:58
  • 2
    \$\begingroup\$ Spend a lot more time describing, in detail, what functionality has to work, simultaneously. Don't discuss the library code or the old code you also have. Just describe, in detail, what should function together and how it should function together. A design flows out of that. From there you can decide if the existing code or other libraries may be appropriate or inappropriate. I know nothing about the Nokia 1616 LCD. Talk about it. How does it work? How does a user input information? Etc. Just dumping out code like this may get a lucky hit from someone. But not likely. \$\endgroup\$
    – jonk
    Commented Sep 3, 2022 at 6:38
  • 1
    \$\begingroup\$ @salar1991 No, don't tell me what routines should work simultaneously. That's a design you already have and you know is not working. I don't care about it, at all. Just want a clear description of what a user should see and be able to interact with, and how so. For example, you already mentioned scrolling. Does scrolling take place as though the scrolled material is a background while at the same time a prompt must stay firmly fixed in the foreground on the display while user input is also accepted?? Those kinds of details. I don't want any info on your design. It doesn't work. \$\endgroup\$
    – jonk
    Commented Sep 3, 2022 at 7:12
  • 1
    \$\begingroup\$ Your toy is too complicated. (1) Usually I start cutting everything except perhaps the following two tasks: (a) Nokia display task , (b) keyboard input task, (2) I try a big loop for the two tasks, (3) I crate only one semaphore so the key board would (b) first switch on the semaphore before inputting a key, put the key in a buffer and then switch off the semaphore. (4) The display task must first wait to see if semaphore is free, open the same semaphore before checking out the buffer, and if buffer has new data, display the key and then close the semaphore., ... \$\endgroup\$
    – tlfong01
    Commented Sep 3, 2022 at 7:19
  • 1
    \$\begingroup\$ Please edit new information into your question, don't post it in comments. Otherwise, readers have to piece together the full question from fragments. Thanks. \$\endgroup\$
    – TonyM
    Commented Sep 3, 2022 at 10:23

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.