Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
11 years, 5 months ago.
Problems with Serial speed
Hello, I been working with mbed platform and I am having some trouble with Serial speed. I am developing an EEG acquisition system with 32 channels. For that i am using 4 ADCs (ADS1299) with the SPI interface communication. The problem is when I send the data to the pc. For a sampling rate of 1KSps I need to send 512bits (4 ADCs x 16bits per channel) per msec. To maintain a reasonable timeframe I need to send data at a baudrate of 921600 using the printf("%s",uint8_t array). The problem is that the data comes corrupted. I have already try the putc() function, but no improvement. I am using ubunto in the pc side, and the serial is correctly configured (stty -F /dev/ttyACM0 ispeed 921600). In some of my experiments the max speed that I was capable to send data with no corruption was at 230400 and using the printf("%d",variable) with less data (only 8 channels x 16 bits = 128bits per msec). Can someone please help me on this one? By using the USB on the mbed instead of Serial, could it be the solution for my problem? Can it handle the speed requirements for my application?
Thanks in advance.
1 Answer
11 years, 5 months ago.
Are you flushing the stdout buffer after calling printf? If not the mbed won't send them immediately (at least when using Serial over USB).
There are two options. Either always use a '\n' character at the end of printf e.g. printf("Hello World\n") or use the function fflush(stdout) after each call of printf.
Yes, I am flushing the data with the \n (printf("%s\r\n",uint8_t array)). The fflush(stdout) I still didn't use. I will give it a try. Thanks.
posted by 28 May 2013Hello again, So I tryed the fflush(stdout) but nothing improved. I still have a lot of data corrupted. Please help. Thanks in advance.
posted by 28 May 2013I'm using a interrupt given from the ADCs. After each interrupt I read make the SPI tranfer and send the data trough Serial. Could this be the problem? Instead of the interrupt, should I pool that signal? Could it be better for the purpose?
Thanks in advance.
posted by 28 May 2013Yes, using both \n and fflush(stdout) shouldn't improve it any further. You hadn't wrote it in the first post that you are using one of them so just what come to my mind ...
Are there only corrupted data? Maybe the source could could help out.
And yes, I think interrupting an communication is a bad idea. You may try to send the same amount of constant data without the interrupts. If this is okay, you need to pull the AD data or schedule your interrupts with an enable variable or so.
posted by 28 May 2013Ok, pooling didn't work either. Using the USB can be the solution? The speed is much higher right?
Thanks in advance.
posted by 28 May 2013I'm using the Serial over USB not 'standard' USB itself. It's working great at a baud of 921600. But I don't have that amount of data. I'm using this high baud rate, because it should not block my program code too long.
Other idea: Any chance to compress or preprocess your data on the mbed? Maybe using other communications, I know there is a wifi adapter board.
posted by 28 May 2013