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