8 years, 10 months ago.

send and receive array type over usb

Hello,

I am searching whether I can send and receive integer array to and from pc from my stm32f401 nucleo. Please help me on how to do it or can I send or receive like that? Thank you for your support.

sincerely,

princekham

1 Answer

8 years, 10 months ago.

Not directly. In c (and c++) an array variable is just a pointer to the first entry in the array, if you try to send that over a serial port all you'll get is the memory address of the first item in the array.

For an array that is always going to be the same length it is simple enough to have a for loop and send each entry in the array in turn.

If you need more flexibility you need to send the size of the array first and then the list of values.

The receiving side is exactly the same in reverse, create an array the required size and then read each value as it comes in and store it in the array.

As always you can play games with data start and end markers, checksums etc... depending on how controlled the system is and how reliable you need it to be.

Thank you for your answer. I found an article about sending the data using string type and parsing it as integers or float. Here.

https://developer.mbed.org/forum/helloworld/topic/1024/?page=1#comment-7867

I just want to send the speed and direction command to my nucleo board from a pc or another nucleo board. so i think the way it described there is alright to me. But I don't know if there is any better alternative solutions.

posted by Sao Kham 24 Jun 2015