Skip to content
This repository was archived by the owner on Jun 10, 2024. It is now read-only.

Strings not printing properly #20

Open
vincentabraham opened this issue Nov 8, 2021 · 0 comments
Open

Strings not printing properly #20

vincentabraham opened this issue Nov 8, 2021 · 0 comments

Comments

@vincentabraham
Copy link

I've written the following program in main.c:

TaskHandle_t vTask1Handle = NULL;
TaskHandle_t vTask2Handle = NULL;
QueueHandle_t myQueue;

void vTask1(void* p);
void vTask2(void* p);


void vTask1(void* p)
{
    char myTxBuff[30];

    myQueue = xQueueCreate(
        1, // Size of the queue
        sizeof(myTxBuff) // Size of each block
    );
    sprintf(myTxBuff, "Message 1");
    xQueueSend(
        myQueue,
        (void*) myTxBuff,
        (TickType_t) 0
    );

    sprintf(myTxBuff, "Message 2");
    xQueueOverwrite(
        myQueue,
        (void*) myTxBuff
    );

    vTaskDelay(pdMS_TO_TICKS(1000));
    printf("Data Waiting to be read: %d\r\n", uxQueueMessagesWaiting(myQueue));

    //vTaskDelay(pdMS_TO_TICKS(1000));
    printf("Spaces Available: %d\r\n", uxQueueSpacesAvailable(myQueue));

    while(1)
    {
        ;    
    }
}

void vTask2(void* p)
{
    char myRxBuff[30];

    while(1)
    {
        vTaskDelay(pdMS_TO_TICKS(1000));
        if(myQueue != 0){
            if(xQueuePeek(myQueue, (void*)myRxBuff, (TickType_t)0)){
                printf("Data Received: %s\r\n", myRxBuff);
            }
        }
    }
}


int main(void)
{

    xTaskCreate(vTask1,             // Function that the task executes
                "Task 1",            // Name
                1024,                // Stack Size
                (void*)0,                // Parameters
                1,                  // Priority
                &vTask1Handle);      // Task Handler
    
    xTaskCreate(vTask2,             // Function that the task executes
                "Task 2",            // Name
                1024,                // Stack Size
                (void*)0,                // Parameters
                1,                  // Priority
                &vTask2Handle);      // Task Handler

    vTaskStartScheduler();
    while(1)
    {
        ;
    }
    return 0;
}

However, this is the output I get:
image
How could I get the strings to print properly? It seems like if there are more than one lines to print, then this happens.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant