2019-07-08 05:31 AM
Dear Members,
How can I pass float value from RPM to UART buffer
float ==> (uint8_t*)&aTxBuffer8 ?
(uint8_t*)&aTxBuffer8 = snprintf(str_rpm,sizeof(str_rpm),"%f",rpm);
?
Thanks
2019-07-08 05:37 AM
strcpy()?
You could use pointers, or use a function sending the string directly.
2019-07-08 06:51 AM
define a union composed by (float and a vector of uint8_t).
The vector dimension depend on how many bytes is implemented the float in your architecture.
In this way you can use ever the byte.
Bets regards
2019-07-08 09:36 AM
if it's to show a value to users, make it simple:
uint32_t rpm_x100;
rpm_x100 = (uint32_t) (rpm * 100);
Make your own printf with custom markers like %D for decimal X.X, %C for X.XX, %M for X.*** from int value...
2019-07-08 09:46 AM
Or functions like ftoa()
The question from the OP is more one of moving strings around, and the fact you can just write something to the address of the pointer with the kind of assignment used in the question.
I seem to recall sprintf() returning the number of bytes, not a pointer to the string. http://www.cplusplus.com/reference/cstdio/snprintf/
char aTxBuffer8[16];
int TxBuffer8length = snprintf(aTxBuffer8,sizeof(aTxBuffer8),"%f",rpm);
2019-08-19 10:26 PM
How about passing this :
*temperature=((temp_x/65536.0)*165.0)-40.0;
uint8_t Sensor_variable[]=*temperature;
HAL_UART_Transmit_IT(&huart1,(uint8_t*)&Sensor_variable,sizeof(Sensor_variable));
??
Thanks
2019-08-19 10:31 PM
char Sensor_variable[16];
int TxBuffer8length = snprintf(Sensor_variable,sizeof(Sensor_variable),"%2.2lf",*temperature);
HAL_UART_Transmit_IT(&huart1,(uint8_t*)&Sensor_variable,sizeof(Sensor_variable)); //Temp and humidity variable
Am I right ?
2019-08-19 10:33 PM
Sensor_variable will be transmitted on buffer and the content = *temperature ?
2019-08-19 10:57 PM
No
2019-08-19 11:22 PM
What do I miss then? Thanks