# Sending ADC measurements with UART

I want to measure signal with ADC and send measurements to PC to generate plots.

My code:

ADC_SoftwareStartConv(ADC3);
while(1)
{
USART2_SendText(str);
USART2_SendText(";");
}


The problem is that I want to sample signal as fast as it is possible. Here I'm using baud rate = 256000 (Windows only). What is the possibility to sample signals faster? What is more optimal code for sample and send measurement?

I see that the problem there is UART transmission.

And my additional questions are: Is it real time measurement with this code? How it should be made if I want real time measurement?

• Ad. as fast as possible: Check the datasheet (so add a link to it) on how fast the ADC actually is. Ad. additional question: First define what your requirement is for "real time". – jippie Jun 2 '13 at 19:12
• But there the problem is also with uart sending of data. I know that the limiting is ADC speed, but in the code in question it is slowed by UART sending of data. My question is how to implement it effictient to not limit measurement speed. I do not understand secod part of question, I thought that there is one "real time" definition? – krzych Jun 2 '13 at 19:16
• Interrupts. The ADC can do a conversion while the data is shifted out through UART. During the conversion the CPU is doing nothing and you can use that time for filling the UART buffer with data. – jippie Jun 2 '13 at 19:18
• Or DMA, though you would probably have to set up two DMA streams (DAC to memory, memory to UART). – fm_andreas Jun 2 '13 at 19:20
• If the purpose of the transfer to the PC is to generate real time plots, take a moment to think about how that data can be used and interpreted on the user end. Plotting 8Msample/second data in real time is just useless for visualization. Also, the "as fast as possible" thing is a bit backwards. Start with "as fast as I need it to work", put a number on that, and strive to achieve it. – Scott Seidman Jun 3 '13 at 20:57

It's probably also worth mentioning that the sprintf call is probably fairly slow and (if it's the only time you use it) pulls in a lot of library code. Even if you want to keep human-readable ascii, you could probably serialize the number a lot faster yourself than sprintf. While you're at it, you could include the semicolon in the string and make only one call to USART2_SendText.