can't get full array in Queue RTOS

hi there
in the code below I am trying to pass a word to Rcv array and then check the word. so first I use ReceiveData() to receive the array and then I use StoreDataandRespond() to check it

#include <Arduino_FreeRTOS.h>
#include <queue.h>

QueueHandle_t queue1;

void ReceiveData(void *prm);
void StoreDataandRespond(void *prm);

void setup(){
Serial.begin(9600);

  // put your setup code here, to run once:
xTaskCreate(ReceiveData,"Task1",128,NULL,2,NULL);
xTaskCreate(StoreDataandRespond,"Task2",128,NULL,1,NULL);
queue1=xQueueCreate(5,sizeof(char));
vTaskStartScheduler();
}

void loop() {
  // put your main code here, to run repeatedly:

}

void ReceiveData(void *prm)
{
    char Rcv[5]; // for incoming serial data  
    int index=0;
    while(1)
    {
        //Serial.println("Task1");
        if (Serial.available() > 0) 
        {
            // read the incoming byte:
            char Buffer = Serial.read();
            if(index<5)
            {
              Rcv[index]=Buffer;
              index++;
            }
            else
            {
            Serial.println(Rcv);
            xQueueSend(queue1,&Rcv,portMAX_DELAY);
            vTaskDelay(1000/portTICK_PERIOD_MS); 
            }   
        }
    }
}

void StoreDataandRespond(void *prm)
{
  char Rcv[5];
  while(1)
  {
      if(xQueueReceive(queue1,&Rcv,portMAX_DELAY)==pdPASS)
      {
            if(Rcv[0]=='A')// && Rcv[1]=='B' && Rcv[2]=='C' && Rcv[3]=='D' && Rcv[4]=='E')
            {
                 Serial.println("Task2");
                 Serial.println(Rcv);
            }
      }
  }
}

but as you can see in the second function when I want to read Rcv, only the first character is right and rest is gibberish..
(I just inserted if(Rcv[0]=='A') and commented the rest to just show you what I get in serial monitor when Serial.println(Rcv) performes)

You are using your Rcv array as a string but it does not have a terminating nul char at the end so the println() function prints more than you expect. Your Rcv array should be ‘A’, ‘B’, ‘C’, ‘D’, ‘E’, ‘\0’
Make it one char longer and terminate it when it reaches 5. You will also have to make your queue1 larger

void ReceiveData(void *prm)
{
  char Rcv[6]; // for incoming serial data
  int index = 0;
  while (1)
  {
    //Serial.println("Task1");
    if (Serial.available() > 0)
    {
      // read the incoming byte:
      char Buffer = Serial.read();
      if (index < 5)
      {
        Rcv[index] = Buffer;
        index++;
      }
      else
      {
        Rcv[index] = '\0';
        Serial.println(Rcv);
        xQueueSend(queue1, &Rcv, portMAX_DELAY);
        vTaskDelay(1000 / portTICK_PERIOD_MS);
      }
    }
  }
}

You defined your queue to be 5 elements deep, but each element is only a single character:

queue1=xQueueCreate(5,sizeof(char));

So this:

xQueueSend(queue1,&Rcv,portMAX_DELAY);

only puts one character (from Rcv[0]) into the queue.

And this:

xQueueReceive(queue1,&Rcv,portMAX_DELAY)

only takes one character out of the queue and puts it into Rcv[0]

Dear gfvalvo

so how should I define it to send and receive the whole array and not character-wise? as you know, I am totally beginner in RTOS...

Try:

queue1 = xQueueCreate(5, 5 * sizeof(char));

But, as already noted by @blh64, your character array is unterminated. So, you can’t treat it like a c-string. You should either terminate it or use a different way to print it.

char Rcv[50} = {NULL}; to make a char array 50 characters long filled with nulls.
queue1 = xQueueCreate( 5, 5 * sizeof(Rcv) ); make 5 queues of character arrays 50 characters long.


freeRTOS on an Uno/Mega is a waste of time.

Idahowalker:
char Rcv[50} = {NULL}; to make a char array 50 characters long filled with nulls.
queue1 = xQueueCreate( 5, 5 * sizeof(Rcv) ); make 5 queues of character arrays 50 characters long.

sizeof(Rcv) is 50. So, I think you only need:

queue1 = xQueueCreate( 5, sizeof(Rcv) );

gfvalvo:
sizeof(Rcv) is 50. So, I think you only need:

queue1 = xQueueCreate( 5, sizeof(Rcv) );

Oi! You got it.

I terminated Rcv and tried

queue1 = xQueueCreate(5, 5 * sizeof(char));

it worked! thank you all!