Skip to main content
hashtala
Associate III
October 9, 2020
Question

how to properly cast ushort to float in Cortex M4 MCU

  • October 9, 2020
  • 2 replies
  • 1017 views

Hello

I have DMA ADC and store data in uint16_t buffer

I need to copy these values to input buffer to arm_rfft_fast_f32 function;

the function should also cast ushort to float

void copy_adc_to_input(uint16_t * int_buff, float32_t * float_buff, uint16_t size)

{

for(int i = 0; i < size; i++)

{

  float_buff[i] = (float32_t)int_buff[i];

}

}

it seems to be working on STM32F7 mcu but goes crazy on STM32F303

any suggestions ???

This topic has been closed for replies.

2 replies

TDK
October 9, 2020

I don't see anything wrong with the code. What does "goes crazy" mean?

"If you feel a post has answered your question, please click ""Accept as Solution""."
hashtala
hashtalaAuthor
Associate III
October 9, 2020

turns out this fft function modifies input buffer as well. That was the reason why I could not recognize what I was seeing.

At this stage I am witnessing rather strange thing. my adc is 12 bits resolution but values are in 16 bit for some reason.

I use uint16_t for buffer. I think I just need to shift down these values