send hex data by uart

mcgilbarron wrote on Tuesday, March 18, 2014:

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?

davedoors wrote on Tuesday, March 18, 2014:

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.

mcgilbarron wrote on Wednesday, March 19, 2014:

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.

rtel wrote on Wednesday, March 19, 2014:

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.

mcgilbarron wrote on Wednesday, March 19, 2014:

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;
}

rtel wrote on Wednesday, March 19, 2014:

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 website as NXP provide drivers for this chip.

Regards.

mcgilbarron wrote on Thursday, March 20, 2014:

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"
);
}

rtel wrote on Thursday, March 20, 2014:

Do you have stack overflow protection turned on?
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

Regards.