2019-02-20 07:12 AM
Dear All,
I need to send hexadecimal number over uart using STM32F407VG. How can I do that?
Regards,
Gunit
2019-02-20 08:28 AM
Ideally create a generic printf function.
Otherwise, just hardcode what you need.
If it's a byte, it would like: (unoptimized)
uint8_t data = 0x9D; // example
uint8_t ch,hexdigit;
hexdigit = data>>8; // MSB '9'
ch = hexdigit + (hexdigit<0x0A)? '0' : 'A' ;
Transmit(ch);
hexdigit = data & 0xFF; // LSB 'D'
ch = hexdigit + (hexdigit<0x0A)? '0' : 'A' ;
Transmit(ch);
2019-02-20 09:14 AM
Seems like some pretty basic C programming stuff...
see also sprintf() and itoa() usage
http://www.cplusplus.com/reference/cstdlib/itoa/
2019-02-21 03:31 AM
HAL_UART_TRANSMIT function accepts uint8_t as its second argument.
Hence convert hex to int and then transmit
https://www.includehelp.com/c-programs/convert-hexadecimal-to-integer.aspx
2019-02-21 03:53 AM
I agree with the other posters.
And want to add, you see the problem the wrong way.
You want to send a string, that happens to be interpretable (represent) as hexadecimal number.
2019-02-21 12:30 PM
Maybe this isn't the case, but it should be reminded, that if both sides of connection are custom made, then the most effective format is of course binary data packets.