The msp430 microcontroller sends floating point numbers to the host computer through the serial port[Copy link]
Assembling data First assemble the data through the sprintf function. Tips for assembling data: length = 0; sprintf(Storage+length, "Rr=%4.3f ", g_StrComm.aSBuf[0]); length = strlen(Storage); //strlen =12 sprintf(Storage+length, "Rh=%4.3f ", g_StrComm.aSBuf[2]); length = strlen(Storage); //strlen =24 sprintf(Storage+length, "B1=Rr/Rh=%2.4f", g_StrComm.aSBuf[0]/g_StrComm.aSBuf[2]); length = strlen(Storage); SendStr(Storage,strlen(Storage)); //Assemble and send data 1 2 3 4 5 6 7 8 It is easier to assemble data in this way, which is convenient for obtaining the array length and updating the array content. The sprintf function can easily convert the floating-point number type to the char type. Each number corresponds to a byte. 2. Send data void SendStr(char SBuf[],int len) { int m = 0; for( m = 0; m < len; m++ ) //Loop to send len bytes { while (!(UCA1IFG&UCTXIFG)); // UART1 transmit register is ready UCA1TXBUF = SBuf[m] ; //Send one byte } }