Quantcast
Channel: MSP low-power microcontrollers
Viewing all articles
Browse latest Browse all 62309

Forum Post: msp430f5438 experiment board float operation errors

$
0
0
Hi, the function i'm implementing on msp430 experiment board is that convert a float number to char array and transfer each character in the array to computer through UART. the problem is with the float operation. when i convert a float number 5.27 to char array and transfer it through UART, the value i got on the computer is 2f. the codes is attached as well #include #include char transfer_char = '.'; static char str_value[6] = {}; const float value = 5.27; /* * main.c */ int main(void) { sprintf(str_value, "%.2f", value); WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer P11SEL |= BIT0 + BIT1 + BIT2; P11DIR |= BIT0 + BIT1 + BIT2; /*do{ UCSCTL7 &= ~(XT2OFFG + XT1LFOFFG + DCOFFG); SFRIFG1 &= ~OFIFG; }while(SFRIFG1&OFIFG);*/ P5SEL |= BIT6 + BIT7; P5DIR |= BIT6; P5DIR &= ~BIT7; P1DIR |= BIT0; P1OUT &= ~BIT0; UCA1CTL1 |= UCSWRST; UCA1CTL1 |= UCSSEL_2; UCA1BR0 = 18; UCA1BR1 = 0; UCA1MCTL = UCBRS_1 + UCBRF_0; UCA1CTL1 &= ~UCSWRST; UCA1IE |= UCTXIE + UCRXIE; __bis_SR_register(GIE); } #pragma vector=USCI_A1_VECTOR __interrupt void UCA1_ISR(void){ static int counter = 0; switch(UCA1IV){ case 2: transfer_char = UCA1RXBUF; break; case 4: UCA1TXBUF = str_value[counter]; if(++counter==4){ counter = 0; } __delay_cycles(1000000); break; default: break; } } but when i execute float to char array conversion on eclipse c++, it has no problem. that's why i am confused and any suggestion will be appreciated regards Jensen

Viewing all articles
Browse latest Browse all 62309

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>