cancel
Showing results for 
Search instead for 
Did you mean: 

Transmit Single Byte Using UART

anuj
Associate II
Posted on September 02, 2016 at 20:13

I am working on STM32F0. I am suing Uart HAL API to send a command to transmit data over UART which is  

  char *TxBuffer=''ABCD\n\r'';

  int len = strlen(TxBuffer);

  HAL_UART_Transmit_IT(&huart,(uint8_t*)TxBuffer,len);

However I am unable to send single byte using above Command. If I want to send 'A' , It shows the warning that ''incompatible integer to pointer conversion passing int to parameter type 'uint8_t *'.

How can I pass unsigned char values over UART or integer values? I am able to pass string over uart.

#stm32 #learn-c #learn-c #cubemx #!stm32 #uart #hal
4 REPLIES 4
Posted on September 02, 2016 at 20:48

This is basic C programming, unrelated to STM32, HAL, etc

Understand types and pointers, passing parameters by value or address. The function wants a pointer/address to the thing it is sending not the thing itself.

char c = 'A';
HAL_UART_Transmit_IT(&huart, (uint8_t*)&c, 1);

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
anuj
Associate II
Posted on September 02, 2016 at 22:04

I was little confused with that. Thanks,anyway! I have query, how can I send integer type values over UART using HAL_UART_Transmit_IT?

if

int A =10;

How can I transfer value of A over UART?

Posted on September 02, 2016 at 23:59

int a = 12345;
char str[16];
HAL_UART_Transmit_IT(&huart, (uint8_t*)str, sprintf(str,''%d'',a));
or
itoa(a, str, 10); // Base 10
HAL_UART_Transmit_IT(&huart, (uint8_t*)str, strlen(str));

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
anuj
Associate II
Posted on September 03, 2016 at 00:54

Thanks! It's working fine now.

Can you please have a look at my another discussion topic regarding UART.

Here is the link 

[DEAD LINK /public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/UART%20Receive%20Buffer%20Clear&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B&TopicsView=https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/AllItems.aspx&currentviews=0]UART Receive Buffer