cancel
Showing results for 
Search instead for 
Did you mean: 

Need to send ASCII and then HEX

SScot.3
Associate II

I am trying to send commands to a Netion display which needs ASCII and then termination of 3 hex 0xFFs.

I tried this:

						HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4, GPIO_PIN_SET);
						char Cdata[11] = "bt6.val=[1]";
						HAL_UART_Transmit(&huart1, Cdata, 11);
						uint8_t data[] = {0x20, 0xFF, 0xFF, 0xFF};
						HAL_UART_Transmit(&huart1, data, 4, 100);

But get errors. I thought if I locally define the VARs, I can ship them out.

I need to send "bt6.val=[1]" and then send 0xFF, 0xFF, 0xFF to end the command.

Curious display but really cool to use.

What am I not seeing/ remembering?

10 REPLIES 10
KnarfB
Principal III

Why not sending all in one string: "bt6.val=[1]\xFF\xFF\xFF" ?

SScot.3
Associate II

Have you used that?

So:

char Cdata[11] = "bt6.val=[1]\xFF\xFF\xFF";

HAL_UART_Transmit(&huart1, Cdata, 14);

??

Haven't used that. If you send all in one, the timing is tighter.

SScot.3
Associate II

KnarfB-

I did try after adding the wait char:

char Cdata[14] = "bt6.val=[1]\xFF\xFF\xFF";

HAL_UART_Transmit(&huart1, Cdata, 14, 100);

but get this warning:

../Drivers/STM32F0xx_HAL_Driver/Inc/stm32f0xx_hal_uart.h:1528:73: note: expected 'uint8_t *' {aka 'unsigned char *'} but argument is of type 'char *'

 1528 | HAL_StatusTypeDef HAL_UART_Transmit(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size, uint32_t Timeout);

   |                                 ~~~~~~~~~^~~~~

???

For some reason, STM HAL functions expect unsigned char*. You can safely ignore that warning or cast it away.

TDK
Guru

> But get errors.

It's useful for you to show what errors you're getting so we don't have to guess.

In this case, you need to cast the pointer.

HAL_UART_Transmit(&huart1, (uint8_t *) Cdata, 14, HAL_MAX_DELAY);

You have some errors with the length of the string in the initialization statement being wrong as well, and a missing timeout argument.

If you feel a post has answered your question, please click "Accept as Solution".
SScot.3
Associate II

Thanks TDK, I did post the error in response to KnarfB. Re-printed for you here:

char Cdata[14] = "bt6.val=[1]\xFF\xFF\xFF";

HAL_UART_Transmit(&huart1, Cdata, 14, 100);

but get this warning:

../Drivers/STM32F0xx_HAL_Driver/Inc/stm32f0xx_hal_uart.h:1528:73: note: expected 'uint8_t *' {aka 'unsigned char *'} but argument is of type 'char *'

 1528 | HAL_StatusTypeDef HAL_UART_Transmit(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size, uint32_t Timeout);

   |                               ~~~~~~~~~^~~~~

SScot.3
Associate II

Well, just noticed the pointer did NOT point to the pData.

I will try:

HAL_UART_Transmit(&huart1, (uint8_t *)Cdata, 14, 100);

And, of course it worked without warnings. I am almost getting the philosophy of 'cast'......

Thanks!

FYI your string is real lenght 15 and cleaner for code is leave compiler arange

uint8_t Cdata[] = "bt6.val=[1]\xFF\xFF\xFF";
 
HAL_UART_Transmit(&huart1, Cdata, 14, 100);