AnsweredAssumed Answered

Sending float32 with UART

Question asked by G.Tom on Jan 3, 2017
Latest reply on Oct 26, 2017 by sameena shaikh

Hi there, recently I was making acustic spectrometer using STM32F4-Discover. In my project im making FFT with
"arm_math" libraries and then I need to send data to PC (with which I'll display it) via UART.

After making FFT  I recieve array of float32_t - I need to send it via UART.

And here comes my question - how do I send them via UART. I've read that I can :

  1. use sprintf and send it like it was string
  2. divide float into 4x 8-bit uint and send it.

 

How do I do that on STM? I preffer to use option 2.

 

I'm using stdPeriphLibs - they are more clear to me.

 

@Edit 18:00 7th of Jan 2017

I have made a program like this:

uint32_t speed;
volatile unsigned char str;
int i;
union
{
    float32_t f;
    uint8_t bytes[4];
}float2int;
/* ---------------------------------------------------------------------------*/
int main(void)
{
    speed = 9600;
    _GPIO();
    _LED();
    //_NVIC();
    _USART1(speed);

    float2int.f = 123.456;
    i = 0;
    GPIO_SetBits(GPIOD, LED_Green);

    while(i<4)
    {
        USART_SendData(USART1, float2int.bytes[1]);
        while(USART_GetFlagStatus(USART1, USART_IT_TXE) != RESET);
        GPIO_SetBits(GPIOD, LED_Red);
        i++;
    }  

Sending data works in a way - normally im recieving bytes[3], but when I'm debugging I'm recieving data properly.
Do I need some kind of delay?

Outcomes