- 17. January 2012: Atypical Curiosity
- 4. January 2012: PIC32MX7 PIM, RB5 pin conflict (solved)
- 30. December 2011: MikroE Mini-32 Board
- 29. December 2011: Donate to Wikipedia
- 28. December 2011: PIC32 Interrupt Nesting (update)
- 20. December 2011: Graphics Library 3.02
- 2. December 2011: Home Brewed IDE for PIC32 assembly development
- 30. November 2011: Yoda Conditions, Egyptian brackets and more...
- 9. November 2011: AVI Player Project (for the uMMB)
- 21. March 2011: More Multimedia Boards
- January 2012
- December 2011
- November 2011
- March 2011
- February 2011
- January 2011
- March 2010
- January 2010
- December 2009
- November 2009
- September 2009
- August 2009
- July 2009
- June 2009
- May 2009
- April 2009
- March 2009
- January 2009
- December 2008
- November 2008
- October 2008
- July 2008
- June 2008
- May 2008
- April 2008
- March 2008
- February 2008
- January 2008
Good old printf() (continued)
Continuing on the subject of using printf() as the most basic debugging tool, if you are using the MPLAB SIM software simulator to test portions of your code, you might be aware that the PIC simulator offers the possibility to simulate the UART1 module.
Simply open the Debugger menu, select Settings to open the Simulator Settings dialog box and in the UART1 I/O pane check the “Enable UART1 I/O” checkbox. This will give you two options:
· Record anything transmitted by UART1 into a file
· Send the transmitted data directly to the MPLAB Output window but in a separate pane, next to the Build pane, the Find in Files pane and the Debugger Output panes.
Notice that the UART1 simulation timing is not accurate, which is actually an advantage here. Not only the output is displayed immediately, but this means also that you won’t need to worry about the correct baud rate setting/matching (although you still need to remember to enable the module).
Here is the simplest code example I can provide.
Include the standard peripheral libraries (if you have not done so already) at the top of your source file:
#include <plib.h>
Put the following lines in your main() function:
char s[32]; // define a small (string) buffer
OpenUART1(UART_EN, UART_TX_ENABLE, 1); // enable UART1
Whenever needed you can send a simple text message:
putsUART1( “I am here!”);
Or you can use sprintf() to format a more complex output:
sprintf( s, ” data=%03d \n”, mydata); putsUART1( s);
3 Responses to “Good old printf() (continued)”
Leave a Reply
You must be logged in to post a comment.
20. October 2009 at 08:05
If you define and configure a baud rate for UART1 in your code, the printf and UART output are run with delay, as it should to properly simulate. The printf command will take the proper cycles to operate. This can mess with stimulus inputs to the UART. I had a printf statement in a receive ISR when I encountered this. I scratched my head for some time until I figured it out by placing breakpoints and watching it work fine without the printf. It wasn’t exiting the ISR before the next input byte arrived, and it dropped the rest of the data.
30. December 2009 at 17:13
I am glad I stopped by. I just started a new project: porting some code I wrote a few years ago for an AVR Atmega processor to a new PIC32. Having printf available should make my job much easier.