This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CCS/MSP430FR5969: regarding sending float data over uart

Part Number: MSP430FR5969

Tool/software: Code Composer Studio

please uggest a function which sends data type of float data over uart

#include"driverlib.h"
#include"dht22.h"
uint8_t buff=0;
float Temperature_val=0;
void usartinit();
void usartsenddata(uint8_t );
unsigned char *chptr;
int main(void)
{
WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
PM5CTL0 &= ~LOCKLPM5;
clockinit();
_bis_SR_register(GIE);
while(1)
{
Temperature_val=dht22_temperature_read();
_delay_cycles(320000);
CS_initClockSignal(CS_SMCLK,CS_DCOCLK_SELECT,CS_CLOCK_DIVIDER_1);
GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P2,GPIO_PIN0 + GPIO_PIN1,GPIO_SECONDARY_MODULE_FUNCTION);
usartinit();
chptr = (unsigned char *) &Temperature_val;
usartsenddata(*chptr++);usartsenddata(*chptr++);usartsenddata(*chptr++);usartsenddata(*chptr);
//usartsenddata(buff);
}
}
void usartinit()
{
EUSCI_A_UART_initParam paramm={0};
paramm.clockPrescalar=52;
paramm.firstModReg=1;
paramm.secondModReg=73;
paramm.msborLsbFirst=EUSCI_A_UART_LSB_FIRST;
paramm.numberofStopBits=EUSCI_A_UART_ONE_STOP_BIT;
paramm.overSampling= EUSCI_A_UART_OVERSAMPLING_BAUDRATE_GENERATION;
paramm.parity=EUSCI_A_UART_NO_PARITY;
paramm.selectClockSource=EUSCI_A_UART_CLOCKSOURCE_SMCLK;
paramm.uartMode=EUSCI_A_UART_MODE;
EUSCI_A_UART_init(EUSCI_A0_BASE, &paramm);
EUSCI_A_UART_enable(EUSCI_A0_BASE);

}
void usartsenddata(uint8_t data)
{

EUSCI_A_UART_transmitData(EUSCI_A0_BASE,data);

}

  • Hi Manoj ,

                         In Msp430  Uart Tx buffer and Rx buffer size is 1 byte so you can send only 1 byte at a time.

    In order to send an integer , long or any value whose size is greater than 1 byte you have to break it and send one byte at a time and convert it back to your original value at other end.

    for example : If you have to send a Long value say 0x2FAABBFF (size 4 byte) 

                              1) make an array buffer[4]:

                              2) now  buffer[0]=0xFF

                                            buffer[1]=0xBB

                                            buffer[2]=0xAA

                                            buffer[3]=0x2F

    to send it over you can use this function:

    void pheonix_send_data_to_pc(unsigned char *sps, unsigned char length)  //             use as                   pheonix_send_data_to_pc(buffer,4);
    {
        while (length)
        {
            while (!(UCA1IFG & UCTXIFG));
            UCA1TXBUF = *sps;
            length--;
            sps++;
        }
    
    }

    and at other end  convert back the value using    buffer[3] *2^32   +buffer[2] * 2^16+buffer[1] * 2^8+buffer[0]

  • The best method is sprintf() and send ascii. That way you do not need to worry about control characters, and you can read it easily during debug.

  • hi sasuke uchiha, can u share any code reference regarding sprintf
  • www.cplusplus.com/.../
    You may need to increase the heap.

**Attention** This is a public forum