cancel
Showing results for 
Search instead for 
Did you mean: 

Need help with passing a float array into a function to transmit floats out of USB port.

ESpra.1
Senior

I'm trying to transmit a 4D array of floats from an stm32l552zet6q to a PC using a USB connection. I can collect the array elements and store them, but when I pass the array into the transmission function, I don't see the same elements.

This image is of the array values as they should be, and are when outside the sendData and sendMatrix functions.

0693W00000UnqDjQAJ.pngAnd this image is what arrives inside the sendData/sendMatrix functions:

0693W00000UnqE8QAJ.png0693W00000UnqEIQAZ.pngAdditionally, I cannot get sprintf to format a string with ANY float values, as shown in the below screenshot

0693W00000UnqErQAJ.pngThe test matrix I've declared is a local variable with a defined size (test[4][35][42][3]).

I've tried altering the code to instead use pointers to the test matrix, but I get the exact same results, though it's entirely possible I was using them incorrectly. Any assistance is appreciated.

1 ACCEPTED SOLUTION

Accepted Solutions

Found the final problem. At some point, I'd accidentally changed configuration from debug to release, and did so before enabling the sprintf float option. So, whenever I fired up debug, I couldn't send any float information. I switched back to debug, re-enabled the float sprintf option, and everything is working

View solution in original post

4 REPLIES 4

Make sure floating point (s)printf() functionality has been enabled and the correct libraries selected. By default I think it's disabled to keep the code foot-print low. There's been 1000's of such posts, you should be able to find some suggestions or tutorials.

Some of the debug screens seem to should addresses of pointers

Check that the sizeof() for the array matches expectations of size vs dimensions.

It should be possible to pass the data as a block, and be able to memcpy() it

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

I do have that functionality enabled (CubeIDE pestered me about it when it wasn't). I'll recheck the posts as well while I'm trying your suggestions. Thanks for the quick response!

That said, I am confused why the debug screens would be showing the addresses of pointers, since they don't do anything like that in other functions where I pass the same array in to set the values; It's all zeroes there. The main difference is that I'm setting the values in the one function, and putting those values into a string in the other, but I'm lost on why that would change the appearance of the array when I enter the other function.

Okay, I tried the memcpy thing, and it the array I tried to copy the code into just came out as all zeroes, even though the array I'm copying from shows the proper contents.

I'll try to get more information while I'm perusing more pages for solutions

Update: Figured out the problem I was having with memcpy. I was passing the maximum sizes of the array (which also read as the very end of the array), rather than the specific slots I wanted copied into the temporary array. It was always going to be zero, since that was constantly checking the last three slots that wouldn't be updated until the very end

Unfortunately, that doesn't solve the problem of the floats not showing up when I use sprintf to format a string that includes them. I even replaced the array with three separate floats to see if that changed things and it didn't. I've read that there's a known bug with ST linkers that can prevent floats from working, but I can't find it in my linker.

Found the final problem. At some point, I'd accidentally changed configuration from debug to release, and did so before enabling the sprintf float option. So, whenever I fired up debug, I couldn't send any float information. I switched back to debug, re-enabled the float sprintf option, and everything is working