# send hex data by uart

**URL:** <https://forums.freertos.org/t/send-hex-data-by-uart/1388>\
**Category:** Kernel\
**Created:** [March 18, 2014, 5:25am UTC](https://forums.freertos.org/t/send-hex-data-by-uart/1388 "2014-03-18T05:25:25Z")\
**Posts on this page:** 8\
**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:** [March 18, 2014, 5:25am UTC](https://forums.freertos.org/t/send-hex-data-by-uart/1388/1 "2014-03-18T05:25:25Z")

</div>

**[mcgilbarron](https://sourceforge.net/u/mcgilbarron/)** wrote on [Tuesday, March 18, 2014](https://sourceforge.net/p/freertos/discussion/382005/thread/3de06d69/#4b26):

I am using the lpcxxpresso 1769, I need to create a task that runs every 10 seconds automatically and to transmit a series of numbers in hexadecimal format:  
unsigned portCHAR pcCall[36]={0xbf, 0xff, 0x00, 0x1F, 0x43, 0x41, 0x4C, 0x4C, 0x20, 0x30, 0x30, 0x3A, 0x30, 0x37, 0x3A, 0x38, 0x30, 0x3A, 0x39, 0x62, 0x3A, 0x30, 0x38, 0x3A, 0x31, 0x62, 0x20, 0x31, 0x30, 0x30, 0x31, 0x20, 0x48, 0x44, 0x50, 0x0A};  
I try to modify the task vUARTCommandConsoleStart() on the sample FreeRTOS+IO; but only the first two bytes transmitted and aborts program execution, could someone tell me how I can create a task that runs independently and forward numbers in hexadecimal format?

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [March 18, 2014, 8:49am UTC](https://forums.freertos.org/t/send-hex-data-by-uart/1388/2 "2014-03-18T08:49:01Z")

</div>

**[davedoors](https://sourceforge.net/u/davedoors/)** wrote on [Tuesday, March 18, 2014](https://sourceforge.net/p/freertos/discussion/382005/thread/3de06d69/#80a5):

How do you want the numbers to appear? As ascii or binary?

If binary then you should be able to just send the start and length of pcCall to any suitable UART send function.

If as ascii then with the 0x in front of each number of witout and with a comma between each number of without? In all cases you should be able to use sprintf() to format the string in a temporary buffer then send the start and length of the temporary buffer to any suitable UART send function.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [March 19, 2014, 3:43pm UTC](https://forums.freertos.org/t/send-hex-data-by-uart/1388/3 "2014-03-19T15:43:56Z")

</div>

**[mcgilbarron](https://sourceforge.net/u/mcgilbarron/)** wrote on [Wednesday, March 19, 2014](https://sourceforge.net/p/freertos/discussion/382005/thread/3de06d69/#6d4b):

could you five commercial suport? I need help for create a task for send hexadecimal characters, i tried but freertos not allow me to add a task,and tried to do it in different ways but only sends data in response to a command registered by FreeRTOS\_CLIRegisterCommand.

---

<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:** [March 19, 2014, 3:49pm UTC](https://forums.freertos.org/t/send-hex-data-by-uart/1388/4 "2014-03-19T15:49:08Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Wednesday, March 19, 2014](https://sourceforge.net/p/freertos/discussion/382005/thread/3de06d69/#912c):

Commercial support should not be necessary - all that is necessary is to understand what it is you are trying to do. If you went the commercial route they would just ask the same questions because they to would need to understand what you are trying to do.

Is creating the task the problem? Or sending to the UART? Or the format of what you are trying to send to the UART?

Regards.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [March 19, 2014, 4:09pm UTC](https://forums.freertos.org/t/send-hex-data-by-uart/1388/5 "2014-03-19T16:09:43Z")

</div>

**[mcgilbarron](https://sourceforge.net/u/mcgilbarron/)** wrote on [Wednesday, March 19, 2014](https://sourceforge.net/p/freertos/discussion/382005/thread/3de06d69/#b16b):

Ok, I need to create using the next function, the next funcion usually works using a FreeRTOS\_CLIRegisterCommand(&xSample\_Adc) action, but now I need to this begin from any task without using a command reception to start. is it possible?

static portBASE\_TYPE prvSample\_AdcCommand( int8\_t \*pcWriteBuffer, size\_t xWriteBufferLen, const int8\_t \*pcCommandString )  
{  
PRIVILEGED\_DATA static char pcString2[50] ;

```
char cont=0;
Resultado=0;
Resultado=RTC_GetTime(LPC_RTC,RTC_TIMETYPE_SECOND);
*pcWriteBuffer = ( signed char ) 0x00;

char *ptr = "inicio muestra\n";//agregado
strcat( ( char* ) pcWriteBuffer, ( char* ) ptr );//agregado

strcat( ( char * ) pcWriteBuffer, ( const char * ) "\r\n" );
sprintf(pcString2,"%d\n", Resultado);
strcat( ( char * ) pcWriteBuffer, ( char * ) pcString2 );

getADCsample ( );

 for (cont=0;cont<200;cont++)
  {
    sprintf(pcString2,"%02x\n",val[cont] );
    strcat( ( char * ) pcWriteBuffer, ( char * ) pcString2 );
  }
    strcat( ( char * ) pcWriteBuffer, ( const char * ) "\r\n" );
    char *ptr2 = "fin muestra\n";//agregado
 	strcat( ( char* ) pcWriteBuffer, ( char* ) ptr2 );//agregado

```

pdFALSE. \*/  
return pdFALSE;  
}

---

<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:** [March 19, 2014, 4:20pm UTC](https://forums.freertos.org/t/send-hex-data-by-uart/1388/6 "2014-03-19T16:20:48Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Wednesday, March 19, 2014](https://sourceforge.net/p/freertos/discussion/382005/thread/3de06d69/#104f):

So the function you have posted (prvSample\_AdcCommand()) generates a string that contains some data. You say in your post that generating the string works ok when prvSample\_AdcCommnad() is called in response to somebody typing a command into the CLI. Now you want to call the same function from C code, rather than from the CLI?

If so, then you can just make the function non-static and call it directly.

Alternatively paste the same code into a new function and call that.

In the function you posted I don’t see the string being sent to a UART. Do you have a UART send function you can use? If not you can get a suitable function from the [LPCWare.com](http://LPCWare.com) website as NXP provide drivers for this chip.

Regards.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [March 20, 2014, 3:29am UTC](https://forums.freertos.org/t/send-hex-data-by-uart/1388/7 "2014-03-20T03:29:32Z")

</div>

**[mcgilbarron](https://sourceforge.net/u/mcgilbarron/)** wrote on [Thursday, March 20, 2014](https://sourceforge.net/p/freertos/discussion/382005/thread/3de06d69/#7e4a):

Thanks for your help.  
Now I am having problems when using strcat, the program aborts execution when i use it, and I dont now why?

void vSendStringSerial ( void \*pvParameters)  
{  
int8\_t cRxedChar, cInputIndex = 0, \*pcOutputString;  
static int8\_t cInputString[cmdMAX\_INPUT\_SIZE];  
portBASE\_TYPE xReturned;  
int8\_t \*pcWriteBuffer=( signed char ) 0x00;  
char \*pcString[50];  
unsigned portSHORT val=100;

```
( void ) pvParameters;
pcOutputString = FreeRTOS_CLIGetOutputBuffer();
xConsoleUART = FreeRTOS_open( boardCOMMAND_CONSOLE_UART, ( uint32_t ) cmdPARAMTER_NOT_USED );
configASSERT( xConsoleUART );
xReturned = FreeRTOS_ioctl( xConsoleUART, ioctlUSE_ZERO_COPY_TX, cmdPARAMTER_NOT_USED );
configASSERT( xReturned );
xReturned = FreeRTOS_ioctl( xConsoleUART, ioctlUSE_CHARACTER_QUEUE_RX, ( void * ) cmdMAX_INPUT_SIZE );
configASSERT( xReturned );
xReturned = FreeRTOS_ioctl( xConsoleUART, ioctlSET_INTERRUPT_PRIORITY, ( void * ) ( configMIN_LIBRARY_INTERRUPT_PRIORITY - 1 ) );
configASSERT( xReturned );

sprintf( ( char * )pcString,"%x\n", 0x64);
strcat( ( char * ) pcWriteBuffer, ( char * ) pcString );

if( FreeRTOS_ioctl( xConsoleUART, ioctlOBTAIN_WRITE_MUTEX, cmd50ms ) == pdPASS )
	{
		FreeRTOS_write( xConsoleUART, pcWriteBuffer, strlen( ( char * ) pcWriteBuffer ) );
	}

```

}

**attribute** ((section(".after\_vectors")))  
void HardFault\_Handler(void)  
{  
\_\_asm volatile  
(  
" tst lr, #4 \n"  
" ite eq \n"  
" mrseq r0, msp \n"  
" mrsne r0, psp \n"  
" ldr r1, [r0, #24] \n"  
" ldr r2, handler\_address\_const \n"  
" bx r2 \n"  
" handler\_address\_const: .word pop\_registers\_from\_fault\_stack \n"  
);  
}

---

<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:** [March 20, 2014, 9:03am UTC](https://forums.freertos.org/t/send-hex-data-by-uart/1388/8 "2014-03-20T09:03:58Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Thursday, March 20, 2014](https://sourceforge.net/p/freertos/discussion/382005/thread/3de06d69/#7705):

Do you have stack overflow protection turned on?  
[http://www.freertos.org/Stacks-and-stack-overflow-checking.html](http://www.freertos.org/Stacks-and-stack-overflow-checking.html)

Are you running a recent version (7.6.0 or higher) with configASSERT() defined to give you the extra error checking included in those versions?  
[http://www.freertos.org/a00110.html#configASSERT](http://www.freertos.org/a00110.html#configASSERT)

Regards.
