2021-11-18 07:32 AM
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?
2021-11-18 07:36 AM
Why not sending all in one string: "bt6.val=[1]\xFF\xFF\xFF" ?
2021-11-18 07:39 AM
Have you used that?
So:
char Cdata[11] = "bt6.val=[1]\xFF\xFF\xFF";
HAL_UART_Transmit(&huart1, Cdata, 14);
??
2021-11-18 07:42 AM
Haven't used that. If you send all in one, the timing is tighter.
2021-11-18 07:43 AM
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);
| ~~~~~~~~~^~~~~
???
2021-11-18 07:48 AM
For some reason, STM HAL functions expect unsigned char*. You can safely ignore that warning or cast it away.
2021-11-18 07:57 AM
> 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.
2021-11-18 07:59 AM
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);
| ~~~~~~~~~^~~~~
2021-11-18 08:03 AM
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!
2021-11-18 09:36 AM
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);