# How to send string through queue 

**URL:** <https://forums.freertos.org/t/how-to-send-string-through-queue/3483>\
**Category:** Kernel\
**Created:** [December 27, 2015, 6:02pm UTC](https://forums.freertos.org/t/how-to-send-string-through-queue/3483 "2015-12-27T18:02:23Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [December 27, 2015, 6:02pm UTC](https://forums.freertos.org/t/how-to-send-string-through-queue/3483/1 "2015-12-27T18:02:23Z")

</div>

**[ephobb](https://sourceforge.net/u/ephobb/)** wrote on [Sunday, December 27, 2015](https://sourceforge.net/p/freertos/discussion/382005/thread/9b0e9d02/#99d4):

Hi,  
This is my first FreeRTOS based project.  
I am trying to send string through one task to uart task. but i could see, only 1st letter is being sent.  
here is my code

[code]  
gbl\_queue\_handler = xQueueCreate(6,sizeof(uint8\_t));  
xTaskCreate((TaskFunction\_t)Sd\_uart,“Suart”,256,NULL,1,NULL);  
xTaskCreate((TaskFunction\_t)send\_str1,“string1”,256,NULL,0,NULL);

void send\_str1(void const \* argument)  
{  
uint8\_t dat[5]={‘S’,‘K’,‘N’,‘A’,‘B’};  
for(;😉  
{  
xQueueSend(gbl\_queue\_handler,&dat[0],0);  
vTaskDelay(1000);  
}  
}

void Sd\_uart(void const \* argument)  
{  
uint8\_t data[6]={0};  
uint8\_t da;  
for(;😉  
{  
HAL\_UART\_Transmit(&huart1,“UART Task”,9,1000);  
if(xQueueReceive(gbl\_queue\_handler,data,100))  
{  
HAL\_UART\_Transmit(&huart1,&data[0],1,1000);   
}  
else  
{  
HAL\_UART\_Transmit(&huart1,“No Data”,7,1000);  
}  
}  
}

[\code]

and part of the output where i m receving queued data is “…UART Task **S** UART…”

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [December 27, 2015, 6:30pm UTC](https://forums.freertos.org/t/how-to-send-string-through-queue/3483/2 "2015-12-27T18:30:07Z")

</div>

**[edwards3](https://sourceforge.net/u/edwards3/)** wrote on [Sunday, December 27, 2015](https://sourceforge.net/p/freertos/discussion/382005/thread/9b0e9d02/#1276):

This line

xQueueCreate(6,sizeof(uint8\_t));

creates a queue that holds 6 characters max. Each character is 8bits.  
[http://www.freertos.org/a00116.html](http://www.freertos.org/a00116.html)

This line

xQueueSend(gbl\_queue\_handler,&dat[0],0);

sends ojne character to the queue. Only the ‘S’ is ever sent to the queue (the queue holds 8bit types).

If you want to send a string then the string needs to be null terminated in the normal C way, and then you need to create the queue to hold char pointers.

```auto
/* Create a string that holds pointers, each pointer is 4 bytes. */
xQueueCreate(6,sizeof(char*));

const char *myString="SKNAB";

/* Queue a pointer. */
xQueueSend(gbl_queue_handler,&myString,0);

```

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [December 27, 2015, 7:29pm UTC](https://forums.freertos.org/t/how-to-send-string-through-queue/3483/3 "2015-12-27T19:29:44Z")

</div>

**[ephobb](https://sourceforge.net/u/ephobb/)** wrote on [Sunday, December 27, 2015](https://sourceforge.net/p/freertos/discussion/382005/thread/9b0e9d02/#a65e):

Thanks it works.  
can you please give me some links for queue tutorial. I read basic queue creation, send and receive.  
but i want to know how to protect it with semaphore.  
because more than task may be send data to uart.

---

<div class="post-metadata">

**Author:** ![rtel](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rtel/32/31_2.png) [@rtel](https://forums.freertos.org/u/rtel)\
**Post date:** [December 27, 2015, 7:39pm UTC](https://forums.freertos.org/t/how-to-send-string-through-queue/3483/4 "2015-12-27T19:39:16Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Sunday, December 27, 2015](https://sourceforge.net/p/freertos/discussion/382005/thread/9b0e9d02/#a65e/0008):

Queues (or any other FreeRTOS object) do not need to be protected by the  
application - that is all taken care of by the RTOS itself. Any number  
of tasks and interrupts can write to or read from the same queue. Note  
that when accessing a queue from an interrupt only the API functions  
appended with “FromISR” can be used.

Regards.
