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, 10 months ago.
Printf statement appears to be non-func. for outputing data to a UART when located within a for-loop
I am trying to program the mbed to output data parameter values via UART interface to a data logger card. For some reason, that I don't understand, using a printf statement within a for-loop does not output this data to the UART IF. The printf works fine not in a loop and even works in a while-loop. Tried this operation using UART2 or UART3. I found this same operation "abnormality" in trying to transfer data via a printf statement within a for-loop over USB to a terminal in my PC. I can certainly live with this restriction but I would like to understand what might be causing it.
Question relating to:
2 Answers
11 years ago.
You can try using function: writeable()
Serial PC
// Print "Hello World" to the PC #include "mbed.h" Serial pc(USBTX,USBRX); int main() { while(!pc.writeable()); pc.printf("\n\rHello World!!"); while(1) { if(pc.readable()) pc.putc(pc.getc()); } }
11 years ago.
There should not be any problem with printf in a for-loop. You may be sending data too fast and somehow loose characters. There could also be other issues related to interrupts (printf should not be used in interrupt handlers). Please post smallest code example that shows your problem.